Introducing new features. support xxl-job and auto set appname

This commit is contained in:
lbwNB 2020-09-16 14:07:40 +08:00
parent f527555f82
commit 8413ca6278
13 changed files with 28 additions and 171 deletions

View File

@ -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

View File

@ -69,7 +69,6 @@ pig
└── pig-monitor -- 服务监控 [5001]
├── pig-codegen -- 图形化代码生成 [5002]
└── pig-sentinel-dashboard -- 流量高可用 [5003]
└── pig-xxl-job -- 分布式任务调度 [5004]
```
#### 开源共建

View File

@ -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

View File

@ -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 {
}

View File

@ -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";
}

View File

@ -14,7 +14,7 @@ public class XxlExecutorProperties {
/**
* 执行器AppName [选填]执行器心跳注册分组依据为空则关闭自动注册
*/
private String appname = "xxl-job-executor";
private String appname;
/**
* 服务注册地址,优先使用该配置作为注册地址 为空时使用内嵌服务 IP:PORT 作为注册地址 从而更灵活的支持容器类型执行器动态IP和动态映射端口问题

View File

@ -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;
}
}

View File

@ -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

View File

@ -1,62 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>com.pig4cloud</groupId>
<artifactId>pig-visual</artifactId>
<version>2.9.0</version>
</parent>
<artifactId>pig-xxl-job</artifactId>
<description>pig 定时任务示例工程基于xxl-job</description>
<dependencies>
<!--注册中心客户端-->
<dependency>
<groupId>com.alibaba.cloud</groupId>
<artifactId>spring-cloud-starter-alibaba-nacos-discovery</artifactId>
</dependency>
<!--配置中心客户端-->
<dependency>
<groupId>com.alibaba.cloud</groupId>
<artifactId>spring-cloud-starter-alibaba-nacos-config</artifactId>
</dependency>
<!--定时任务-->
<dependency>
<groupId>com.pig4cloud</groupId>
<artifactId>pig-common-job</artifactId>
<version>2.9.0</version>
</dependency>
<!--断路器依赖-->
<dependency>
<groupId>com.pig4cloud</groupId>
<artifactId>pig-common-sentinel</artifactId>
<version>2.9.0</version>
</dependency>
<!--web 模块-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<!--undertow容器-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-undertow</artifactId>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
<plugin>
<groupId>io.fabric8</groupId>
<artifactId>docker-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>

View File

@ -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);
}
}

View File

@ -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<String> demoJobHandler(String s) {
ShardingUtil.ShardingVO shardingVO = ShardingUtil.getShardingVo();
XxlJobLogger.log("This is a demo job." + shardingVO);
return SUCCESS;
}
}

View File

@ -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@

View File

@ -33,6 +33,5 @@
<module>pig-codegen</module>
<module>pig-monitor</module>
<module>pig-sentinel-dashboard</module>
<module>pig-xxl-job</module>
</modules>
</project>