Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
int
Pig
提交
916740e4
P
Pig
项目概览
int
/
Pig
上一次同步 大约 1 年
通知
8
Star
1
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
P
Pig
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
916740e4
编写于
11月 15, 2020
作者:
L
lbw
提交者:
Gitee
11月 15, 2020
浏览文件
操作
浏览文件
下载
差异文件
!86 xxl-job 客户端支持基于服务注册发现的自动化配置 xxl-job-admin
Merge pull request !86 from lbw/dev
上级
c387461f
612ffd4a
变更
9
隐藏空白更改
内联
并排
Showing
9 changed file
with
87 addition
and
12 deletion
+87
-12
README.md
README.md
+1
-1
pig-common/pig-common-core/src/main/java/com/pig4cloud/pig/common/core/config/JacksonConfiguration.java
...ig4cloud/pig/common/core/config/JacksonConfiguration.java
+2
-0
pig-common/pig-common-job/pom.xml
pig-common/pig-common-job/pom.xml
+5
-0
pig-common/pig-common-job/src/main/java/com/pig4cloud/pig/common/job/XxlJobAutoConfiguration.java
...com/pig4cloud/pig/common/job/XxlJobAutoConfiguration.java
+30
-2
pig-common/pig-common-job/src/main/java/com/pig4cloud/pig/common/job/properties/XxlAdminProperties.java
...g4cloud/pig/common/job/properties/XxlAdminProperties.java
+1
-1
pig-visual/pig-xxl-job-admin/pom.xml
pig-visual/pig-xxl-job-admin/pom.xml
+12
-0
pig-visual/pig-xxl-job-admin/src/main/java/com/xxl/job/admin/controller/interceptor/PermissionInterceptor.java
...b/admin/controller/interceptor/PermissionInterceptor.java
+10
-0
pig-visual/pig-xxl-job-admin/src/main/resources/application.yml
...sual/pig-xxl-job-admin/src/main/resources/application.yml
+9
-8
pig-visual/pig-xxl-job-admin/src/main/resources/bootstrap.yml
...visual/pig-xxl-job-admin/src/main/resources/bootstrap.yml
+17
-0
未找到文件。
README.md
浏览文件 @
916740e4
...
...
@@ -18,7 +18,7 @@
| 依赖 | 版本 |
| ---------------------- | ------------- |
| Spring Boot | 2.3.6.RELEASE |
| Spring Cloud | Hoxton.SR
8
|
| Spring Cloud | Hoxton.SR
9
|
| Spring Cloud Alibaba | 2.2.3.RELEASE |
| Spring Security OAuth2 | 2.3.6 |
| Mybatis Plus | 3.4.1 |
...
...
pig-common/pig-common-core/src/main/java/com/pig4cloud/pig/common/core/config/JacksonConfiguration.java
浏览文件 @
916740e4
...
...
@@ -18,6 +18,7 @@ package com.pig4cloud.pig.common.core.config;
import
cn.hutool.core.date.DatePattern
;
import
com.fasterxml.jackson.databind.ObjectMapper
;
import
com.fasterxml.jackson.databind.ser.std.ToStringSerializer
;
import
com.pig4cloud.pig.common.core.jackson.PigJavaTimeModule
;
import
org.springframework.boot.autoconfigure.AutoConfigureBefore
;
import
org.springframework.boot.autoconfigure.condition.ConditionalOnClass
;
...
...
@@ -51,6 +52,7 @@ public class JacksonConfiguration {
builder
.
locale
(
Locale
.
CHINA
);
builder
.
timeZone
(
TimeZone
.
getTimeZone
(
ZoneId
.
systemDefault
()));
builder
.
simpleDateFormat
(
DatePattern
.
NORM_DATETIME_PATTERN
);
builder
.
serializerByType
(
Long
.
class
,
ToStringSerializer
.
instance
);
builder
.
modules
(
new
PigJavaTimeModule
());
};
}
...
...
pig-common/pig-common-job/pom.xml
浏览文件 @
916740e4
...
...
@@ -39,5 +39,10 @@
<artifactId>
xxl-job-core
</artifactId>
<version>
${xxl-job.version}
</version>
</dependency>
<!--提供服务发现能力-->
<dependency>
<groupId>
org.springframework.cloud
</groupId>
<artifactId>
spring-cloud-commons
</artifactId>
</dependency>
</dependencies>
</project>
pig-common/pig-common-job/src/main/java/com/pig4cloud/pig/common/job/XxlJobAutoConfiguration.java
浏览文件 @
916740e4
...
...
@@ -3,9 +3,13 @@ package com.pig4cloud.pig.common.job;
import
com.pig4cloud.pig.common.job.properties.XxlJobProperties
;
import
com.xxl.job.core.executor.impl.XxlJobSpringExecutor
;
import
org.springframework.boot.autoconfigure.EnableAutoConfiguration
;
import
org.springframework.cloud.client.discovery.DiscoveryClient
;
import
org.springframework.context.annotation.Bean
;
import
org.springframework.context.annotation.ComponentScan
;
import
org.springframework.context.annotation.Configuration
;
import
org.springframework.util.StringUtils
;
import
java.util.stream.Collectors
;
/**
* xxl-job自动装配
...
...
@@ -18,10 +22,21 @@ import org.springframework.context.annotation.Configuration;
@ComponentScan
(
"com.pig4cloud.pig.common.job.properties"
)
public
class
XxlJobAutoConfiguration
{
/**
* 服务名称 包含 XXL_JOB_ADMIN 则说明是 Admin
*/
private
static
final
String
XXL_JOB_ADMIN
=
"xxl-job-admin"
;
/**
* 配置xxl-job 执行器,提供自动发现 xxl-job-admin 能力
* @param xxlJobProperties xxl 配置
* @param discoveryClient 注册发现客户端
* @return
*/
@Bean
public
XxlJobSpringExecutor
xxlJobSpringExecutor
(
XxlJobProperties
xxlJobProperties
)
{
public
XxlJobSpringExecutor
xxlJobSpringExecutor
(
XxlJobProperties
xxlJobProperties
,
DiscoveryClient
discoveryClient
)
{
XxlJobSpringExecutor
xxlJobSpringExecutor
=
new
XxlJobSpringExecutor
();
xxlJobSpringExecutor
.
setAdminAddresses
(
xxlJobProperties
.
getAdmin
().
getAddresses
());
xxlJobSpringExecutor
.
setAppname
(
xxlJobProperties
.
getExecutor
().
getAppname
());
xxlJobSpringExecutor
.
setAddress
(
xxlJobProperties
.
getExecutor
().
getAddress
());
xxlJobSpringExecutor
.
setIp
(
xxlJobProperties
.
getExecutor
().
getIp
());
...
...
@@ -29,6 +44,19 @@ public class XxlJobAutoConfiguration {
xxlJobSpringExecutor
.
setAccessToken
(
xxlJobProperties
.
getExecutor
().
getAccessToken
());
xxlJobSpringExecutor
.
setLogPath
(
xxlJobProperties
.
getExecutor
().
getLogPath
());
xxlJobSpringExecutor
.
setLogRetentionDays
(
xxlJobProperties
.
getExecutor
().
getLogRetentionDays
());
// 如果配置为空则获取注册中心的服务列表 "http://pigx-xxl:9080/xxl-job-admin"
if
(
StringUtils
.
isEmpty
(
xxlJobProperties
.
getAdmin
().
getAddresses
()))
{
String
serverList
=
discoveryClient
.
getServices
().
stream
().
filter
(
s
->
s
.
contains
(
XXL_JOB_ADMIN
))
.
flatMap
(
s
->
discoveryClient
.
getInstances
(
s
).
stream
()).
map
(
instance
->
String
.
format
(
"http://%s:%s/%s"
,
instance
.
getHost
(),
instance
.
getPort
(),
XXL_JOB_ADMIN
))
.
collect
(
Collectors
.
joining
(
","
));
xxlJobSpringExecutor
.
setAddress
(
serverList
);
}
else
{
xxlJobSpringExecutor
.
setAddress
(
xxlJobProperties
.
getAdmin
().
getAddresses
());
}
return
xxlJobSpringExecutor
;
}
...
...
pig-common/pig-common-job/src/main/java/com/pig4cloud/pig/common/job/properties/XxlAdminProperties.java
浏览文件 @
916740e4
...
...
@@ -14,6 +14,6 @@ public class XxlAdminProperties {
/**
* 调度中心部署跟地址 [选填]:如调度中心集群部署存在多个地址则用逗号分隔。 执行器将会使用该地址进行"执行器心跳注册"和"任务结果回调";为空则关闭自动注册;
*/
private
String
addresses
=
"http://pig-job:5004/xxl-job-admin"
;
private
String
addresses
;
}
pig-visual/pig-xxl-job-admin/pom.xml
浏览文件 @
916740e4
...
...
@@ -13,6 +13,18 @@
<dependencies>
<!--注册中心客户端-->
<dependency>
<groupId>
com.alibaba.cloud
</groupId>
<artifactId>
spring-cloud-starter-alibaba-nacos-discovery
</artifactId>
</dependency>
<!--hibernate-validator 兼容JAVA11-->
<dependency>
<groupId>
org.springframework.boot
</groupId>
<artifactId>
spring-boot-starter-validation
</artifactId>
</dependency>
<!-- starter-web:spring-webmvc + autoconfigure + logback + yaml + tomcat -->
<dependency>
<groupId>
org.springframework.boot
</groupId>
...
...
pig-visual/pig-xxl-job-admin/src/main/java/com/xxl/job/admin/controller/interceptor/PermissionInterceptor.java
浏览文件 @
916740e4
...
...
@@ -11,6 +11,7 @@ import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;
import
javax.annotation.Resource
;
import
javax.servlet.http.HttpServletRequest
;
import
javax.servlet.http.HttpServletResponse
;
import
java.util.Arrays
;
/**
* 权限拦截
...
...
@@ -20,6 +21,11 @@ import javax.servlet.http.HttpServletResponse;
@Component
public
class
PermissionInterceptor
extends
HandlerInterceptorAdapter
{
/**
* 针对 spring boot admin 对外暴露的接口
*/
private
static
final
String
[]
ACTUATOR_IGNORE
=
{
"/actuator"
,
"/details"
,
"/health"
};
@Resource
private
LoginService
loginService
;
...
...
@@ -31,6 +37,10 @@ public class PermissionInterceptor extends HandlerInterceptorAdapter {
return
super
.
preHandle
(
request
,
response
,
handler
);
}
if
(
Arrays
.
stream
(
ACTUATOR_IGNORE
).
anyMatch
(
s
->
request
.
getRequestURI
().
contains
(
s
)))
{
return
super
.
preHandle
(
request
,
response
,
handler
);
}
// if need login
boolean
needLogin
=
true
;
boolean
needAdminuser
=
false
;
...
...
pig-visual/pig-xxl-job-admin/src/main/resources/application.yml
浏览文件 @
916740e4
# 此配置只适合开发测试环境,详细配置参考: http://t.cn/A64RaHJm
server
:
port
:
5004
servlet
:
context-path
:
/xxl-job-admin
# xxl
xxl
:
job
:
...
...
@@ -20,7 +14,7 @@ mybatis:
# spring
spring
:
datasource
:
url
:
jdbc:mysql://${MYSQL_HOST:pig
-mysql}:${MYSQL_PORT:3306}/${MYSQL_DB:pig
_job}?characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=false&useJDBCCompliantTimezoneShift=true&useLegacyDatetimeCode=false&serverTimezone=GMT%2B8&nullCatalogMeansCurrent=true&allowPublicKeyRetrieval=true
url
:
jdbc:mysql://${MYSQL_HOST:pig
x-mysql}:${MYSQL_PORT:3306}/${MYSQL_DB:pigxx
_job}?characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=false&useJDBCCompliantTimezoneShift=true&useLegacyDatetimeCode=false&serverTimezone=GMT%2B8&nullCatalogMeansCurrent=true&allowPublicKeyRetrieval=true
driver-class-name
:
com.mysql.cj.jdbc.Driver
username
:
${MYSQL-PWD:root}
password
:
${MYSQL-PWD:root}
...
...
@@ -46,9 +40,16 @@ spring:
ssl.enable
:
true
starttls.enable
:
false
required
:
false
# spring boot admin 配置
# close mail health check
management
:
health
:
mail
:
enabled
:
false
endpoints
:
web
:
exposure
:
include
:
'
*'
endpoint
:
health
:
show-details
:
ALWAYS
\ No newline at end of file
pig-visual/pig-xxl-job-admin/src/main/resources/bootstrap.yml
0 → 100644
浏览文件 @
916740e4
# 此配置只适合开发测试环境,详细配置参考: http://t.cn/A64RaHJm
server
:
port
:
5004
servlet
:
context-path
:
/xxl-job-admin
spring
:
application
:
name
:
@
artifactId@
cloud
:
nacos
:
discovery
:
server-addr
:
${NACOS_HOST:pigx-register}:${NACOS_PORT:8848}
metadata
:
management.context-path
:
${server.servlet.context-path}/actuator
profiles
:
active
:
@
profiles.active@
\ No newline at end of file
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录