diff --git a/README.md b/README.md index 7d810790..c62381f2 100644 --- a/README.md +++ b/README.md @@ -70,8 +70,7 @@ pig └── pig-visual └── pig-monitor -- spring boot admin[5001] ├── pig-codegen -- graphical code generation[5002] - └── pig-sentinel-dashboard -- sentinel dashboard [5003] - └── pig-xxl-job -- distributed task scheduling [5004] + └── pig-sentinel-dashboard -- sentinel dashboard [5003] ``` #### Open source co-construction diff --git a/README.zh.md b/README.zh.md index 9068943f..eb7166d8 100644 --- a/README.zh.md +++ b/README.zh.md @@ -69,7 +69,6 @@ pig └── pig-monitor -- 服务监控 [5001] ├── pig-codegen -- 图形化代码生成 [5002] └── pig-sentinel-dashboard -- 流量高可用 [5003] - └── pig-xxl-job -- 分布式任务调度 [5004] ``` #### 开源共建 diff --git a/docker-compose.yml b/docker-compose.yml index 93b86ae4..428486ea 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -81,19 +81,3 @@ services: container_name: pig-codegen hostname: pig-codegen image: pig-codegen - - pig-xxl-job: - build: - context: ./pig-visual/pig-xxl-job - restart: always - image: pig-xxl-job - container_name: pig-xxl-job - - pig-xxl-job-admin: - container_name: pig-xxl-job-admin - image: xuxueli/xxl-job-admin:2.2.0 - restart: always - environment: - PARAMS: "--server.port=8080 --spring.datasource.url=jdbc:mysql://pig-mysql:3306/pig_job?Unicode=true&characterEncoding=UTF-8 --spring.datasource.username=root --spring.datasource.password=root" - ports: - - 8080:8080 diff --git a/pig-common/pig-common-job/src/main/java/com/pig4cloud/pig/common/job/annotation/EnablePigXxlJob.java b/pig-common/pig-common-job/src/main/java/com/pig4cloud/pig/common/job/annotation/EnablePigXxlJob.java index 86e64f2b..803bf7ce 100644 --- a/pig-common/pig-common-job/src/main/java/com/pig4cloud/pig/common/job/annotation/EnablePigXxlJob.java +++ b/pig-common/pig-common-job/src/main/java/com/pig4cloud/pig/common/job/annotation/EnablePigXxlJob.java @@ -1,6 +1,6 @@ package com.pig4cloud.pig.common.job.annotation; -import com.pig4cloud.pig.common.job.properties.XxlJobProperties; +import com.pig4cloud.pig.common.job.XxlJobAutoConfiguration; import org.springframework.context.annotation.Import; import java.lang.annotation.*; @@ -15,7 +15,7 @@ import java.lang.annotation.*; @Retention(RetentionPolicy.RUNTIME) @Documented @Inherited -@Import({ XxlJobProperties.class }) +@Import({ XxlJobAutoConfiguration.class }) public @interface EnablePigXxlJob { } diff --git a/pig-common/pig-common-job/src/main/java/com/pig4cloud/pig/common/job/properties/XxlAdminProperties.java b/pig-common/pig-common-job/src/main/java/com/pig4cloud/pig/common/job/properties/XxlAdminProperties.java index 2efb2cfa..cdb103d4 100644 --- a/pig-common/pig-common-job/src/main/java/com/pig4cloud/pig/common/job/properties/XxlAdminProperties.java +++ b/pig-common/pig-common-job/src/main/java/com/pig4cloud/pig/common/job/properties/XxlAdminProperties.java @@ -14,6 +14,6 @@ public class XxlAdminProperties { /** * 调度中心部署跟地址 [选填]:如调度中心集群部署存在多个地址则用逗号分隔。 执行器将会使用该地址进行"执行器心跳注册"和"任务结果回调";为空则关闭自动注册; */ - private String addresses = "http://127.0.0.1:8080/xxl-job-admin"; + private String addresses = "http://pig-job:8080/xxl-job-admin"; } diff --git a/pig-common/pig-common-job/src/main/java/com/pig4cloud/pig/common/job/properties/XxlExecutorProperties.java b/pig-common/pig-common-job/src/main/java/com/pig4cloud/pig/common/job/properties/XxlExecutorProperties.java index 8b3d8d25..02677bb6 100644 --- a/pig-common/pig-common-job/src/main/java/com/pig4cloud/pig/common/job/properties/XxlExecutorProperties.java +++ b/pig-common/pig-common-job/src/main/java/com/pig4cloud/pig/common/job/properties/XxlExecutorProperties.java @@ -14,7 +14,7 @@ public class XxlExecutorProperties { /** * 执行器AppName [选填]:执行器心跳注册分组依据;为空则关闭自动注册 */ - private String appname = "xxl-job-executor"; + private String appname; /** * 服务注册地址,优先使用该配置作为注册地址 为空时使用内嵌服务 ”IP:PORT“ 作为注册地址 从而更灵活的支持容器类型执行器动态IP和动态映射端口问题 diff --git a/pig-common/pig-common-job/src/main/java/com/pig4cloud/pig/common/job/properties/XxlJobProperties.java b/pig-common/pig-common-job/src/main/java/com/pig4cloud/pig/common/job/properties/XxlJobProperties.java index bdee2970..0ec2d233 100644 --- a/pig-common/pig-common-job/src/main/java/com/pig4cloud/pig/common/job/properties/XxlJobProperties.java +++ b/pig-common/pig-common-job/src/main/java/com/pig4cloud/pig/common/job/properties/XxlJobProperties.java @@ -1,8 +1,12 @@ package com.pig4cloud.pig.common.job.properties; import lombok.Data; +import org.springframework.beans.factory.InitializingBean; import org.springframework.boot.context.properties.ConfigurationProperties; +import org.springframework.context.EnvironmentAware; +import org.springframework.core.env.Environment; import org.springframework.stereotype.Component; +import org.springframework.util.StringUtils; /** * xxl-job配置 @@ -13,10 +17,28 @@ import org.springframework.stereotype.Component; @Data @Component @ConfigurationProperties(prefix = "xxl.job") -public class XxlJobProperties { +public class XxlJobProperties implements InitializingBean, EnvironmentAware { + + private Environment environment; private XxlAdminProperties admin = new XxlAdminProperties(); private XxlExecutorProperties executor = new XxlExecutorProperties(); + @Override + public void afterPropertiesSet() { + // 若是没有设置appname 则取 application Name + if (StringUtils.isEmpty(executor.getAppname())) { + executor.setAppname(environment.getProperty("spring.application.name")); + } + } + + /** + * Set the {@code Environment} that this component runs in. + */ + @Override + public void setEnvironment(Environment environment) { + this.environment = environment; + } + } diff --git a/pig-visual/pig-xxl-job/Dockerfile b/pig-visual/pig-xxl-job/Dockerfile deleted file mode 100755 index b7b417d3..00000000 --- a/pig-visual/pig-xxl-job/Dockerfile +++ /dev/null @@ -1,17 +0,0 @@ -FROM anapsix/alpine-java:8_server-jre_unlimited - -MAINTAINER wangiegie@gmail.com - -ENV TZ=Asia/Shanghai - -RUN ln -sf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone - -RUN mkdir -p /pig-xxl-job - -WORKDIR /pig-xxl-job - -EXPOSE 5004 - -ADD ./target/pig-xxl-job.jar ./ - -CMD sleep 60;java -Djava.security.egd=file:/dev/./urandom -jar pig-xxl-job.jar diff --git a/pig-visual/pig-xxl-job/pom.xml b/pig-visual/pig-xxl-job/pom.xml deleted file mode 100755 index 7f0747cd..00000000 --- a/pig-visual/pig-xxl-job/pom.xml +++ /dev/null @@ -1,62 +0,0 @@ - - - 4.0.0 - - - com.pig4cloud - pig-visual - 2.9.0 - - - pig-xxl-job - pig 定时任务示例工程,基于xxl-job - - - - - com.alibaba.cloud - spring-cloud-starter-alibaba-nacos-discovery - - - - com.alibaba.cloud - spring-cloud-starter-alibaba-nacos-config - - - - com.pig4cloud - pig-common-job - 2.9.0 - - - - com.pig4cloud - pig-common-sentinel - 2.9.0 - - - - org.springframework.boot - spring-boot-starter-web - - - - org.springframework.boot - spring-boot-starter-undertow - - - - - - - org.springframework.boot - spring-boot-maven-plugin - - - io.fabric8 - docker-maven-plugin - - - - diff --git a/pig-visual/pig-xxl-job/src/main/java/com/pig4cloud/pig/job/PigXxlJobApplication.java b/pig-visual/pig-xxl-job/src/main/java/com/pig4cloud/pig/job/PigXxlJobApplication.java deleted file mode 100644 index 6bd3bff8..00000000 --- a/pig-visual/pig-xxl-job/src/main/java/com/pig4cloud/pig/job/PigXxlJobApplication.java +++ /dev/null @@ -1,21 +0,0 @@ -package com.pig4cloud.pig.job; - -import com.pig4cloud.pig.common.job.annotation.EnablePigXxlJob; -import org.springframework.boot.SpringApplication; -import org.springframework.cloud.client.SpringCloudApplication; - -/** - * pig分布式任务调度,基于xxl-job - * - * @author lishangbu - * @date 2020/9/14 - */ -@EnablePigXxlJob -@SpringCloudApplication -public class PigXxlJobApplication { - - public static void main(String[] args) { - SpringApplication.run(PigXxlJobApplication.class, args); - } - -} diff --git a/pig-visual/pig-xxl-job/src/main/java/com/pig4cloud/pig/job/handler/DemoJobHandler.java b/pig-visual/pig-xxl-job/src/main/java/com/pig4cloud/pig/job/handler/DemoJobHandler.java deleted file mode 100644 index ae8b623e..00000000 --- a/pig-visual/pig-xxl-job/src/main/java/com/pig4cloud/pig/job/handler/DemoJobHandler.java +++ /dev/null @@ -1,29 +0,0 @@ -package com.pig4cloud.pig.job.handler; - -import com.xxl.job.core.biz.model.ReturnT; -import com.xxl.job.core.handler.annotation.XxlJob; -import com.xxl.job.core.log.XxlJobLogger; -import com.xxl.job.core.util.ShardingUtil; -import lombok.extern.slf4j.Slf4j; -import org.springframework.stereotype.Component; - -import static com.xxl.job.core.biz.model.ReturnT.SUCCESS; - -/** - * 示例任务处理器 - * - * @author lishangbu - * @date 2020/9/14 - */ -@Slf4j -@Component -public class DemoJobHandler { - - @XxlJob("demoJobHandler") - public ReturnT demoJobHandler(String s) { - ShardingUtil.ShardingVO shardingVO = ShardingUtil.getShardingVo(); - XxlJobLogger.log("This is a demo job." + shardingVO); - return SUCCESS; - } - -} diff --git a/pig-visual/pig-xxl-job/src/main/resources/bootstrap.yml b/pig-visual/pig-xxl-job/src/main/resources/bootstrap.yml deleted file mode 100755 index 7f16cacf..00000000 --- a/pig-visual/pig-xxl-job/src/main/resources/bootstrap.yml +++ /dev/null @@ -1,17 +0,0 @@ -server: - port: 5004 - -spring: - application: - name: @artifactId@ - cloud: - nacos: - discovery: - server-addr: ${NACOS_HOST:pig-register}:${NACOS_PORT:8848} - config: - server-addr: ${spring.cloud.nacos.discovery.server-addr} - file-extension: yml - shared-configs: - - application-${spring.profiles.active}.${spring.cloud.nacos.config.file-extension} - profiles: - active: @profiles.active@ diff --git a/pig-visual/pom.xml b/pig-visual/pom.xml index 53161fcb..2b4628f3 100755 --- a/pig-visual/pom.xml +++ b/pig-visual/pom.xml @@ -33,6 +33,5 @@ pig-codegen pig-monitor pig-sentinel-dashboard - pig-xxl-job