Commit 1b16eaa3611d02957ae5234aaf545a2d0de255bd
1 parent
7f2848c8
拆分jeecg-boot-starter出来,使用独立项目维护
Showing
59 changed files
with
0 additions
and
3389 deletions
jeecg-boot/jeecg-boot-starter/jeecg-boot-starter-cloud/nacos/jeecg-dev.yaml deleted
1 | -spring: | |
2 | - datasource: | |
3 | - druid: | |
4 | - stat-view-servlet: | |
5 | - enabled: true | |
6 | - loginUsername: admin | |
7 | - loginPassword: 123456 | |
8 | - allow: | |
9 | - web-stat-filter: | |
10 | - enabled: true | |
11 | - dynamic: | |
12 | - druid: # 全局druid参数,绝大部分值和默认保持一致。(现已支持的参数如下,不清楚含义不要乱设置) | |
13 | - # 连接池的配置信息 | |
14 | - # 初始化大小,最小,最大 | |
15 | - initial-size: 5 | |
16 | - min-idle: 5 | |
17 | - maxActive: 20 | |
18 | - # 配置获取连接等待超时的时间 | |
19 | - maxWait: 60000 | |
20 | - # 配置间隔多久才进行一次检测,检测需要关闭的空闲连接,单位是毫秒 | |
21 | - timeBetweenEvictionRunsMillis: 60000 | |
22 | - # 配置一个连接在池中最小生存的时间,单位是毫秒 | |
23 | - minEvictableIdleTimeMillis: 300000 | |
24 | - validationQuery: SELECT 1 FROM DUAL | |
25 | - testWhileIdle: true | |
26 | - testOnBorrow: false | |
27 | - testOnReturn: false | |
28 | - # 打开PSCache,并且指定每个连接上PSCache的大小 | |
29 | - poolPreparedStatements: true | |
30 | - maxPoolPreparedStatementPerConnectionSize: 20 | |
31 | - # 配置监控统计拦截的filters,去掉后监控界面sql无法统计,'wall'用于防火墙 | |
32 | - filters: stat,wall,slf4j | |
33 | - # 通过connectProperties属性来打开mergeSql功能;慢SQL记录 | |
34 | - connectionProperties: druid.stat.mergeSql\=true;druid.stat.slowSqlMillis\=5000 | |
35 | - | |
36 | - datasource: | |
37 | - master: | |
38 | - url: jdbc:mysql://${MYSQL-HOST:jeecg-boot-mysql}:${MYSQL-PORT:3306}/${MYSQL-DB:jeecg-boot}?characterEncoding=UTF-8&useUnicode=true&useSSL=false&tinyInt1isBit=false&allowPublicKeyRetrieval=true&serverTimezone=Asia/Shanghai | |
39 | - username: ${MYSQL-USER:root} | |
40 | - password: ${MYSQL-PWD:root} | |
41 | - driver-class-name: com.mysql.cj.jdbc.Driver | |
42 | - # 多数据源配置 | |
43 | - #multi-datasource1: | |
44 | - #url: jdbc:mysql://localhost:3306/jeecg-boot2?useUnicode=true&characterEncoding=utf8&autoReconnect=true&zeroDateTimeBehavior=convertToNull&transformedBitIsBoolean=true&allowPublicKeyRetrieval=true&serverTimezone=Asia/Shanghai | |
45 | - #username: root | |
46 | - #password: root | |
47 | - #driver-class-name: com.mysql.cj.jdbc.Driver | |
48 | - #redis 配置 | |
49 | - redis: | |
50 | - database: 0 | |
51 | - host: jeecg-boot-redis | |
52 | - lettuce: | |
53 | - pool: | |
54 | - max-active: 8 #最大连接数据库连接数,设 0 为没有限制 | |
55 | - max-idle: 8 #最大等待连接中的数量,设 0 为没有限制 | |
56 | - max-wait: -1ms #最大建立连接等待时间。如果超过此时间将接到异常。设为-1表示无限制。 | |
57 | - min-idle: 0 #最小等待连接中的数量,设 0 为没有限制 | |
58 | - shutdown-timeout: 100ms | |
59 | - password: | |
60 | - port: 6379 | |
61 | - #rabbitmq配置 | |
62 | - rabbitmq: | |
63 | - host: jeecg-boot-rabbitmq | |
64 | - username: guest | |
65 | - password: guest | |
66 | - port: 5672 | |
67 | - publisher-confirms: true | |
68 | - publisher-returns: true | |
69 | - virtual-host: / | |
70 | - listener: | |
71 | - simple: | |
72 | - acknowledge-mode: manual | |
73 | - #消费者的最小数量 | |
74 | - concurrency: 1 | |
75 | - #消费者的最大数量 | |
76 | - max-concurrency: 1 | |
77 | - #是否支持重试 | |
78 | - retry: | |
79 | - enabled: true | |
80 | -#minidao | |
81 | -minidao : | |
82 | - base-package: org.jeecg.modules.jmreport.* | |
83 | -#jeecg专用配置 | |
84 | -jeecg : | |
85 | - # 本地:local\Minio:minio\阿里云:alioss | |
86 | - uploadType: local | |
87 | - path : | |
88 | - #文件上传根目录 设置 | |
89 | - upload: D://opt//upFiles | |
90 | - #webapp文件路径 | |
91 | - webapp: D://opt//webapp | |
92 | - shiro: | |
93 | - excludeUrls: /test/jeecgDemo/demo3,/test/jeecgDemo/redisDemo/**,/category/**,/map/**,/jmreport/bigscreen2/** | |
94 | - #阿里云oss存储配置 | |
95 | - oss: | |
96 | - endpoint: oss-cn-beijing.aliyuncs.com | |
97 | - accessKey: ?? | |
98 | - secretKey: ?? | |
99 | - bucketName: jeecgdev | |
100 | - staticDomain: ?? | |
101 | - # ElasticSearch 6设置 | |
102 | - elasticsearch: | |
103 | - cluster-name: jeecg-ES | |
104 | - cluster-nodes: 127.0.0.1:9200 | |
105 | - check-enabled: false | |
106 | - # 表单设计器配置 | |
107 | - desform: | |
108 | - # 主题颜色(仅支持 16进制颜色代码) | |
109 | - theme-color: "#1890ff" | |
110 | - # 文件、图片上传方式,可选项:qiniu(七牛云)、system(跟随系统配置) | |
111 | - upload-type: system | |
112 | - map: | |
113 | - # 配置百度地图的AK,申请地址:https://lbs.baidu.com/apiconsole/key?application=key#/home | |
114 | - baidu: ?? | |
115 | - # 在线预览文件服务器地址配置 | |
116 | - file-view-domain: 127.0.0.1:8012 | |
117 | - # minio文件上传 | |
118 | - minio: | |
119 | - minio_url: http://minio.jeecg.com | |
120 | - minio_name: ?? | |
121 | - minio_pass: ?? | |
122 | - bucketName: otatest | |
123 | - #大屏报表参数设置 | |
124 | - jmreport: | |
125 | - mode: dev | |
126 | - #是否需要校验token | |
127 | - is_verify_token: false | |
128 | - #必须校验方法 | |
129 | - verify_methods: remove,delete,save,add,update | |
130 | - #Wps在线文档 | |
131 | - wps: | |
132 | - domain: https://wwo.wps.cn/office/ | |
133 | - appid: ?? | |
134 | - appsecret: ?? | |
135 | - #xxl-job配置 | |
136 | - xxljob: | |
137 | - enabled: false | |
138 | - adminAddresses: http://jeecg-boot-xxljob:9080/xxl-job-admin | |
139 | - appname: ${spring.application.name} | |
140 | - accessToken: '' | |
141 | - logPath: logs/jeecg/job/jobhandler/ | |
142 | - logRetentionDays: 30 | |
143 | - #自定义路由配置 yml nacos database | |
144 | - route: | |
145 | - config: | |
146 | - data-id: jeecg-gateway-router | |
147 | - group: DEFAULT_GROUP | |
148 | - data-type: yml | |
149 | - #分布式锁配置 | |
150 | - redisson: | |
151 | - address: jeecg-boot-redis:6379 | |
152 | - password: | |
153 | - type: STANDALONE | |
154 | - enabled: true | |
155 | -#Mybatis输出sql日志 | |
156 | -logging: | |
157 | - level: | |
158 | - org.jeecg.modules.system.mapper : info | |
159 | -#cas单点登录 | |
160 | -cas: | |
161 | - prefixUrl: http://localhost:8888/cas | |
162 | -#swagger | |
163 | -knife4j: | |
164 | - production: false | |
165 | - basic: | |
166 | - enable: true | |
167 | - username: jeecg | |
168 | - password: jeecg1314 | |
169 | - | |
170 | -#第三方登录 | |
171 | -justauth: | |
172 | - enabled: true | |
173 | - type: | |
174 | - GITHUB: | |
175 | - client-id: ?? | |
176 | - client-secret: ?? | |
177 | - redirect-uri: http://sso.test.com:8080/jeecg-boot/thirdLogin/github/callback | |
178 | - WECHAT_ENTERPRISE: | |
179 | - client-id: ?? | |
180 | - client-secret: ?? | |
181 | - redirect-uri: http://sso.test.com:8080/jeecg-boot/thirdLogin/wechat_enterprise/callback | |
182 | - agent-id: 1000002 | |
183 | - DINGTALK: | |
184 | - client-id: ?? | |
185 | - client-secret: ?? | |
186 | - redirect-uri: http://sso.test.com:8080/jeecg-boot/thirdLogin/dingtalk/callback | |
187 | - cache: | |
188 | - type: default | |
189 | - prefix: 'demo::' | |
190 | - timeout: 1h | |
191 | -#第三方APP对接 | |
192 | -third-app: | |
193 | - enabled: false | |
194 | - type: | |
195 | - #企业微信 | |
196 | - WECHAT_ENTERPRISE: | |
197 | - enabled: false | |
198 | - #CORP_ID | |
199 | - client-id: ?? | |
200 | - #SECRET | |
201 | - client-secret: ?? | |
202 | - agent-id: ?? | |
203 | - #自建应用秘钥(新版企微需要配置) | |
204 | - # agent-app-secret: ?? | |
205 | - #钉钉 | |
206 | - DINGTALK: | |
207 | - enabled: false | |
208 | - # appKey | |
209 | - client-id: ?? | |
210 | - # appSecret | |
211 | - client-secret: ?? | |
212 | - agent-id: ?? |
jeecg-boot/jeecg-boot-starter/jeecg-boot-starter-cloud/nacos/jeecg-gateway-router.json deleted
1 | -[{ | |
2 | - "id": "jeecg-system", | |
3 | - "order": 0, | |
4 | - "predicates": [{ | |
5 | - "name": "Path", | |
6 | - "args": { | |
7 | - "_genkey_0": "/sys/**", | |
8 | - "_genkey_1": "/eoa/**", | |
9 | - "_genkey_2": "/joa/**", | |
10 | - "_genkey_3": "/jmreport/**", | |
11 | - "_genkey_4": "/bigscreen/**", | |
12 | - "_genkey_5": "/desform/**", | |
13 | - "_genkey_6": "/online/**", | |
14 | - "_genkey_8": "/act/**", | |
15 | - "_genkey_9": "/plug-in/**", | |
16 | - "_genkey_10": "/generic/**", | |
17 | - "_genkey_11": "/v1/**" | |
18 | - } | |
19 | - }], | |
20 | - "filters": [], | |
21 | - "uri": "lb://jeecg-system" | |
22 | -}, { | |
23 | - "id": "jeecg-demo", | |
24 | - "order": 1, | |
25 | - "predicates": [{ | |
26 | - "name": "Path", | |
27 | - "args": { | |
28 | - "_genkey_0": "/mock/**", | |
29 | - "_genkey_1": "/test/**", | |
30 | - "_genkey_2": "/bigscreen/template1/**", | |
31 | - "_genkey_3": "/bigscreen/template2/**" | |
32 | - } | |
33 | - }], | |
34 | - "filters": [], | |
35 | - "uri": "lb://jeecg-demo" | |
36 | -}, { | |
37 | - "id": "jeecg-system-websocket", | |
38 | - "order": 2, | |
39 | - "predicates": [{ | |
40 | - "name": "Path", | |
41 | - "args": { | |
42 | - "_genkey_0": "/websocket/**", | |
43 | - "_genkey_1": "/eoaSocket/**", | |
44 | - "_genkey_2": "/newsWebsocket/**" | |
45 | - } | |
46 | - }], | |
47 | - "filters": [], | |
48 | - "uri": "lb:ws://jeecg-system" | |
49 | -}, { | |
50 | - "id": "jeecg-demo-websocket", | |
51 | - "order": 3, | |
52 | - "predicates": [{ | |
53 | - "name": "Path", | |
54 | - "args": { | |
55 | - "_genkey_0": "/vxeSocket/**" | |
56 | - } | |
57 | - }], | |
58 | - "filters": [], | |
59 | - "uri": "lb:ws://jeecg-demo" | |
60 | -}] | |
61 | 0 | \ No newline at end of file |
jeecg-boot/jeecg-boot-starter/jeecg-boot-starter-cloud/nacos/jeecg.yaml deleted
1 | -server: | |
2 | - tomcat: | |
3 | - max-swallow-size: -1 | |
4 | - error: | |
5 | - include-exception: true | |
6 | - include-stacktrace: ALWAYS | |
7 | - include-message: ALWAYS | |
8 | - compression: | |
9 | - enabled: true | |
10 | - min-response-size: 1024 | |
11 | - mime-types: application/javascript,application/json,application/xml,text/html,text/xml,text/plain,text/css,image/* | |
12 | -management: | |
13 | - health: | |
14 | - mail: | |
15 | - enabled: false | |
16 | - endpoints: | |
17 | - web: | |
18 | - exposure: | |
19 | - include: "*" #暴露所有节点 | |
20 | - health: | |
21 | - sensitive: true #关闭过滤敏感信息 | |
22 | - endpoint: | |
23 | - health: | |
24 | - show-details: ALWAYS #显示详细信息 | |
25 | -spring: | |
26 | - servlet: | |
27 | - multipart: | |
28 | - max-file-size: 10MB | |
29 | - max-request-size: 10MB | |
30 | - mail: | |
31 | - host: smtp.163.com | |
32 | - username: jeecgos@163.com | |
33 | - password: ?? | |
34 | - properties: | |
35 | - mail: | |
36 | - smtp: | |
37 | - auth: true | |
38 | - starttls: | |
39 | - enable: true | |
40 | - required: true | |
41 | - ## quartz定时任务,采用数据库方式 | |
42 | - quartz: | |
43 | - job-store-type: jdbc | |
44 | - initialize-schema: embedded | |
45 | - #设置自动启动,默认为 true | |
46 | - auto-startup: true | |
47 | - #延迟1秒启动定时任务 | |
48 | - startup-delay: 1s | |
49 | - #启动时更新己存在的Job | |
50 | - overwrite-existing-jobs: true | |
51 | - properties: | |
52 | - org: | |
53 | - quartz: | |
54 | - scheduler: | |
55 | - instanceName: MyScheduler | |
56 | - instanceId: AUTO | |
57 | - jobStore: | |
58 | - class: org.quartz.impl.jdbcjobstore.JobStoreTX | |
59 | - driverDelegateClass: org.quartz.impl.jdbcjobstore.StdJDBCDelegate | |
60 | - tablePrefix: QRTZ_ | |
61 | - isClustered: true | |
62 | - misfireThreshold: 60000 | |
63 | - clusterCheckinInterval: 10000 | |
64 | - threadPool: | |
65 | - class: org.quartz.simpl.SimpleThreadPool | |
66 | - threadCount: 10 | |
67 | - threadPriority: 5 | |
68 | - threadsInheritContextClassLoaderOfInitializingThread: true | |
69 | - #json 时间戳统一转换 | |
70 | - jackson: | |
71 | - date-format: yyyy-MM-dd HH:mm:ss | |
72 | - time-zone: GMT+8 | |
73 | - aop: | |
74 | - proxy-target-class: true | |
75 | - activiti: | |
76 | - check-process-definitions: false | |
77 | - #启用作业执行器 | |
78 | - async-executor-activate: false | |
79 | - #启用异步执行器 | |
80 | - job-executor-activate: false | |
81 | - jpa: | |
82 | - open-in-view: false | |
83 | - #配置freemarker | |
84 | - freemarker: | |
85 | - # 设置模板后缀名 | |
86 | - suffix: .ftl | |
87 | - # 设置文档类型 | |
88 | - content-type: text/html | |
89 | - # 设置页面编码格式 | |
90 | - charset: UTF-8 | |
91 | - # 设置页面缓存 | |
92 | - cache: false | |
93 | - prefer-file-system-access: false | |
94 | - # 设置ftl文件路径 | |
95 | - template-loader-path: | |
96 | - - classpath:/templates | |
97 | - # 设置静态文件路径,js,css等 | |
98 | - mvc: | |
99 | - static-path-pattern: /** | |
100 | - resource: | |
101 | - static-locations: classpath:/static/,classpath:/public/ | |
102 | - autoconfigure: | |
103 | - exclude: com.alibaba.druid.spring.boot.autoconfigure.DruidDataSourceAutoConfigure | |
104 | -#mybatis plus 设置 | |
105 | -mybatis-plus: | |
106 | - mapper-locations: classpath*:org/jeecg/modules/**/xml/*Mapper.xml | |
107 | - global-config: | |
108 | - # 关闭MP3.0自带的banner | |
109 | - banner: false | |
110 | - db-config: | |
111 | - #主键类型 0:"数据库ID自增",1:"该类型为未设置主键类型", 2:"用户输入ID",3:"全局唯一ID (数字类型唯一ID)", 4:"全局唯一ID UUID",5:"字符串全局唯一ID (idWorker 的字符串表示)"; | |
112 | - id-type: ASSIGN_ID | |
113 | - # 默认数据库表下划线命名 | |
114 | - table-underline: true | |
115 | - configuration: | |
116 | - # 这个配置会将执行的sql打印出来,在开发或测试的时候可以用 | |
117 | - #log-impl: org.apache.ibatis.logging.stdout.StdOutImpl | |
118 | - # 返回类型为Map,显示null对应的字段 | |
119 | - call-setters-on-nulls: true | |
120 | 0 | \ No newline at end of file |
jeecg-boot/jeecg-boot-starter/jeecg-boot-starter-cloud/pom.xml deleted
1 | -<?xml version="1.0" encoding="UTF-8"?> | |
2 | -<project xmlns="http://maven.apache.org/POM/4.0.0" | |
3 | - xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | |
4 | - xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | |
5 | - <parent> | |
6 | - <artifactId>jeecg-boot-starter</artifactId> | |
7 | - <groupId>org.jeecgframework.boot</groupId> | |
8 | - <version>3.3.0</version> | |
9 | - </parent> | |
10 | - <modelVersion>4.0.0</modelVersion> | |
11 | - <artifactId>jeecg-boot-starter-cloud</artifactId> | |
12 | - | |
13 | - <dependencies> | |
14 | - <dependency> | |
15 | - <groupId>org.jeecgframework.boot</groupId> | |
16 | - <artifactId>jeecg-system-cloud-api</artifactId> | |
17 | - </dependency> | |
18 | - <!-- Nacos注册中心 --> | |
19 | - <dependency> | |
20 | - <groupId>com.alibaba.cloud</groupId> | |
21 | - <artifactId>spring-cloud-starter-alibaba-nacos-discovery</artifactId> | |
22 | - </dependency> | |
23 | - <!-- Nacos配置中心 --> | |
24 | - <dependency> | |
25 | - <groupId>com.alibaba.cloud</groupId> | |
26 | - <artifactId>spring-cloud-starter-alibaba-nacos-config</artifactId> | |
27 | - </dependency> | |
28 | - <!-- feign --> | |
29 | - <dependency> | |
30 | - <groupId>org.springframework.cloud</groupId> | |
31 | - <artifactId>spring-cloud-starter-openfeign</artifactId> | |
32 | - </dependency> | |
33 | - <!-- sentinel限流熔断降级 --> | |
34 | - <dependency> | |
35 | - <groupId>com.alibaba.cloud</groupId> | |
36 | - <artifactId>spring-cloud-starter-alibaba-sentinel</artifactId> | |
37 | - </dependency> | |
38 | - <!--sentinel持久化 --> | |
39 | - <dependency> | |
40 | - <groupId>com.alibaba.csp</groupId> | |
41 | - <artifactId>sentinel-datasource-nacos</artifactId> | |
42 | - </dependency> | |
43 | - | |
44 | - <!-- springboot up 2.6.6 --> | |
45 | - <!-- Alibaba Nacos 配置 --> | |
46 | - <dependency> | |
47 | - <groupId>org.springframework.cloud</groupId> | |
48 | - <artifactId>spring-cloud-starter-bootstrap</artifactId> | |
49 | - </dependency> | |
50 | - <!-- SpringCloud 负载均衡 --> | |
51 | - <dependency> | |
52 | - <groupId>org.springframework.cloud</groupId> | |
53 | - <artifactId>spring-cloud-starter-loadbalancer</artifactId> | |
54 | - </dependency> | |
55 | - <!-- springboot up 2.6.6 --> | |
56 | - | |
57 | - </dependencies> | |
58 | - | |
59 | -</project> | |
60 | 0 | \ No newline at end of file |
jeecg-boot/jeecg-boot-starter/jeecg-boot-starter-cloud/src/main/java/org/jeecg/config/FeignConfig.java deleted
1 | -package org.jeecg.config; | |
2 | - | |
3 | -import java.io.IOException; | |
4 | -import java.util.ArrayList; | |
5 | -import java.util.Arrays; | |
6 | -import java.util.List; | |
7 | -import java.util.SortedMap; | |
8 | - | |
9 | -import javax.servlet.http.HttpServletRequest; | |
10 | - | |
11 | -import org.jeecg.common.constant.CommonConstant; | |
12 | -import org.jeecg.common.util.DateUtils; | |
13 | -import org.jeecg.common.util.PathMatcherUtil; | |
14 | -import org.jeecg.common.config.mqtoken.UserTokenContext; | |
15 | -import org.jeecg.config.mybatis.TenantContext; | |
16 | -import org.jeecg.config.sign.interceptor.SignAuthConfiguration; | |
17 | -import org.jeecg.config.sign.util.HttpUtils; | |
18 | -import org.jeecg.config.sign.util.SignUtil; | |
19 | -import org.springframework.beans.factory.ObjectFactory; | |
20 | -import org.springframework.boot.autoconfigure.AutoConfigureBefore; | |
21 | -import org.springframework.boot.autoconfigure.condition.ConditionalOnClass; | |
22 | -import org.springframework.boot.autoconfigure.http.HttpMessageConverters; | |
23 | -import org.springframework.cloud.openfeign.FeignAutoConfiguration; | |
24 | -import org.springframework.cloud.openfeign.support.SpringDecoder; | |
25 | -import org.springframework.cloud.openfeign.support.SpringEncoder; | |
26 | -import org.springframework.context.annotation.Bean; | |
27 | -import org.springframework.context.annotation.Configuration; | |
28 | -import org.springframework.context.annotation.Primary; | |
29 | -import org.springframework.context.annotation.Scope; | |
30 | -import org.springframework.http.MediaType; | |
31 | -import org.springframework.web.context.request.RequestContextHolder; | |
32 | -import org.springframework.web.context.request.ServletRequestAttributes; | |
33 | - | |
34 | -import com.alibaba.fastjson.JSON; | |
35 | -import com.alibaba.fastjson.serializer.SerializerFeature; | |
36 | -import com.alibaba.fastjson.support.config.FastJsonConfig; | |
37 | -import com.alibaba.fastjson.support.spring.FastJsonHttpMessageConverter; | |
38 | -import com.alibaba.fastjson.support.springfox.SwaggerJsonSerializer; | |
39 | - | |
40 | -import feign.Feign; | |
41 | -import feign.Logger; | |
42 | -import feign.RequestInterceptor; | |
43 | -import feign.codec.Decoder; | |
44 | -import feign.codec.Encoder; | |
45 | -import feign.form.spring.SpringFormEncoder; | |
46 | -import lombok.extern.slf4j.Slf4j; | |
47 | - | |
48 | -/** | |
49 | - * @Description: FeignConfig | |
50 | - * @author: JeecgBoot | |
51 | - */ | |
52 | -@ConditionalOnClass(Feign.class) | |
53 | -@AutoConfigureBefore(FeignAutoConfiguration.class) | |
54 | -@Slf4j | |
55 | -@Configuration | |
56 | -public class FeignConfig { | |
57 | - | |
58 | - /** | |
59 | - * 设置feign header参数 | |
60 | - * 【X_ACCESS_TOKEN】【X_SIGN】【X_TIMESTAMP】 | |
61 | - * @return | |
62 | - */ | |
63 | - @Bean | |
64 | - public RequestInterceptor requestInterceptor() { | |
65 | - return requestTemplate -> { | |
66 | - ServletRequestAttributes attributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes(); | |
67 | - if (null != attributes) { | |
68 | - HttpServletRequest request = attributes.getRequest(); | |
69 | - log.debug("Feign request: {}", request.getRequestURI()); | |
70 | - // 将token信息放入header中 | |
71 | - String token = request.getHeader(CommonConstant.X_ACCESS_TOKEN); | |
72 | - if(token==null || "".equals(token)){ | |
73 | - token = request.getParameter("token"); | |
74 | - } | |
75 | - log.info("Feign Login Request token: {}", token); | |
76 | - requestTemplate.header(CommonConstant.X_ACCESS_TOKEN, token); | |
77 | - | |
78 | - //update-begin-author:taoyan date:2022-6-23 for: issues/I5AO20 多租户微服务之间调用找不到tenant-id(自定义页面) | |
79 | - // 将tenantId信息放入header中 | |
80 | - String tenantId = request.getHeader(CommonConstant.TENANT_ID); | |
81 | - if(tenantId==null || "".equals(tenantId)){ | |
82 | - tenantId = request.getParameter(CommonConstant.TENANT_ID); | |
83 | - } | |
84 | - log.info("Feign Login Request tenantId: {}", tenantId); | |
85 | - requestTemplate.header(CommonConstant.TENANT_ID, tenantId); | |
86 | - //update-end-author:taoyan date:2022-6-23 for: issues/I5AO20 多租户微服务之间调用找不到tenant-id(自定义页面) | |
87 | - | |
88 | - }else{ | |
89 | - String token = UserTokenContext.getToken(); | |
90 | - log.info("Feign no Login token: {}", token); | |
91 | - requestTemplate.header(CommonConstant.X_ACCESS_TOKEN, token); | |
92 | - | |
93 | - //update-begin-author:taoyan date:2022-6-23 for: issues/I5AO20 多租户微服务之间调用找不到tenant-id(自定义页面) | |
94 | - String tenantId = TenantContext.getTenant(); | |
95 | - log.info("Feign no Login tenantId: {}", tenantId); | |
96 | - requestTemplate.header(CommonConstant.TENANT_ID, tenantId); | |
97 | - //update-end-author:taoyan date:2022-6-23 for: issues/I5AO20 多租户微服务之间调用找不到tenant-id(自定义页面) | |
98 | - } | |
99 | - | |
100 | - //================================================================================================================ | |
101 | - //针对特殊接口,进行加签验证 ——根据URL地址过滤请求 【字典表参数签名验证】 | |
102 | - if (PathMatcherUtil.matches(Arrays.asList(SignAuthConfiguration.SIGN_URL_LIST),requestTemplate.path())) { | |
103 | - try { | |
104 | - log.info("============================ [begin] fegin starter url ============================"); | |
105 | - log.info(requestTemplate.path()); | |
106 | - log.info(requestTemplate.method()); | |
107 | - String queryLine = requestTemplate.queryLine(); | |
108 | - if(queryLine!=null && queryLine.startsWith("?")){ | |
109 | - queryLine = queryLine.substring(1); | |
110 | - } | |
111 | - log.info(queryLine); | |
112 | - if(requestTemplate.body()!=null){ | |
113 | - log.info(new String(requestTemplate.body())); | |
114 | - } | |
115 | - SortedMap<String, String> allParams = HttpUtils.getAllParams(requestTemplate.path(),queryLine,requestTemplate.body(),requestTemplate.method()); | |
116 | - String sign = SignUtil.getParamsSign(allParams); | |
117 | - log.info(" Feign request params sign: {}",sign); | |
118 | - log.info("============================ [end] fegin starter url ============================"); | |
119 | - requestTemplate.header(CommonConstant.X_SIGN, sign); | |
120 | - //update-begin--author:taoyan---date:20220421--for: VUEN-410【签名改造】 X-TIMESTAMP牵扯 | |
121 | - requestTemplate.header(CommonConstant.X_TIMESTAMP, String.valueOf(System.currentTimeMillis())); | |
122 | - //update-end--author:taoyan---date:20220421--for: VUEN-410【签名改造】 X-TIMESTAMP牵扯 | |
123 | - } catch (IOException e) { | |
124 | - e.printStackTrace(); | |
125 | - } | |
126 | - } | |
127 | - //================================================================================================================ | |
128 | - }; | |
129 | - } | |
130 | - | |
131 | - | |
132 | - | |
133 | - /** | |
134 | - * Feign 客户端的日志记录,默认级别为NONE | |
135 | - * Logger.Level 的具体级别如下: | |
136 | - * NONE:不记录任何信息 | |
137 | - * BASIC:仅记录请求方法、URL以及响应状态码和执行时间 | |
138 | - * HEADERS:除了记录 BASIC级别的信息外,还会记录请求和响应的头信息 | |
139 | - * FULL:记录所有请求与响应的明细,包括头信息、请求体、元数据 | |
140 | - */ | |
141 | - @Bean | |
142 | - Logger.Level feignLoggerLevel() { | |
143 | - return Logger.Level.FULL; | |
144 | - } | |
145 | - | |
146 | - /** | |
147 | - * Feign支持文件上传 | |
148 | - * @param messageConverters | |
149 | - * @return | |
150 | - */ | |
151 | - @Bean | |
152 | - @Primary | |
153 | - @Scope("prototype") | |
154 | - public Encoder multipartFormEncoder(ObjectFactory<HttpMessageConverters> messageConverters) { | |
155 | - return new SpringFormEncoder(new SpringEncoder(messageConverters)); | |
156 | - } | |
157 | - | |
158 | - // update-begin--Author:sunjianlei Date:20210604 for: 给 Feign 添加 FastJson 的解析支持 ---------- | |
159 | - @Bean | |
160 | - public Encoder feignEncoder() { | |
161 | - return new SpringEncoder(feignHttpMessageConverter()); | |
162 | - } | |
163 | - | |
164 | - @Bean | |
165 | - public Decoder feignDecoder() { | |
166 | - return new SpringDecoder(feignHttpMessageConverter()); | |
167 | - } | |
168 | - | |
169 | - /** | |
170 | - * 设置解码器为fastjson | |
171 | - * | |
172 | - * @return | |
173 | - */ | |
174 | - private ObjectFactory<HttpMessageConverters> feignHttpMessageConverter() { | |
175 | - final HttpMessageConverters httpMessageConverters = new HttpMessageConverters(this.getFastJsonConverter()); | |
176 | - return () -> httpMessageConverters; | |
177 | - } | |
178 | - | |
179 | - private FastJsonHttpMessageConverter getFastJsonConverter() { | |
180 | - FastJsonHttpMessageConverter converter = new FastJsonHttpMessageConverter(); | |
181 | - | |
182 | - List<MediaType> supportedMediaTypes = new ArrayList<>(); | |
183 | - MediaType mediaTypeJson = MediaType.valueOf(MediaType.APPLICATION_JSON_VALUE); | |
184 | - supportedMediaTypes.add(mediaTypeJson); | |
185 | - converter.setSupportedMediaTypes(supportedMediaTypes); | |
186 | - FastJsonConfig config = new FastJsonConfig(); | |
187 | - config.getSerializeConfig().put(JSON.class, new SwaggerJsonSerializer()); | |
188 | - config.setSerializerFeatures(SerializerFeature.DisableCircularReferenceDetect); | |
189 | - converter.setFastJsonConfig(config); | |
190 | - | |
191 | - return converter; | |
192 | - } | |
193 | - // update-end--Author:sunjianlei Date:20210604 for: 给 Feign 添加 FastJson 的解析支持 ---------- | |
194 | - | |
195 | -} |
jeecg-boot/jeecg-boot-starter/jeecg-boot-starter-cloud/src/main/java/org/jeecg/starter/cloud/config/GwCorsFilter.java deleted
1 | -package org.jeecg.starter.cloud.config; | |
2 | - | |
3 | -/** | |
4 | - * @Description: 跨域设置 (升级SpringBoot2.6.6) | |
5 | - * @author: zyf | |
6 | - * @date: 2022/02/21 | |
7 | - * @version: V1.0 | |
8 | - */ | |
9 | -import org.springframework.context.annotation.Bean; | |
10 | -import org.springframework.context.annotation.Configuration; | |
11 | -import org.springframework.web.cors.CorsConfiguration; | |
12 | -import org.springframework.web.cors.reactive.CorsWebFilter; | |
13 | -import org.springframework.web.util.pattern.PathPatternParser; | |
14 | - | |
15 | -@Configuration | |
16 | -public class GwCorsFilter { | |
17 | - | |
18 | - @Bean | |
19 | - public CorsWebFilter corsFilter() { | |
20 | - CorsConfiguration config = new CorsConfiguration(); | |
21 | - config.setAllowCredentials(true); | |
22 | - config.addAllowedOriginPattern("*"); | |
23 | - config.addAllowedHeader("*"); | |
24 | - config.addAllowedMethod("*"); | |
25 | - config.setMaxAge(18000L); | |
26 | - org.springframework.web.cors.reactive.UrlBasedCorsConfigurationSource source = | |
27 | - new org.springframework.web.cors.reactive.UrlBasedCorsConfigurationSource(new PathPatternParser()); | |
28 | - source.registerCorsConfiguration("/**", config); | |
29 | - return new CorsWebFilter(source); | |
30 | - } | |
31 | -} | |
32 | 0 | \ No newline at end of file |
jeecg-boot/jeecg-boot-starter/jeecg-boot-starter-cloud/src/main/java/org/jeecg/starter/cloud/config/PersonBeanConfiguration.java deleted
1 | -//package org.jeecg.starter.cloud.config; | |
2 | -// | |
3 | -//import feign.Client; | |
4 | -//import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; | |
5 | -//import org.springframework.cloud.netflix.ribbon.SpringClientFactory; | |
6 | -//import org.springframework.cloud.openfeign.ribbon.CachingSpringLoadBalancerFactory; | |
7 | -//import org.springframework.cloud.openfeign.ribbon.LoadBalancerFeignClient; | |
8 | -//import org.springframework.context.annotation.Bean; | |
9 | -//import org.springframework.context.annotation.Configuration; | |
10 | -// | |
11 | -//@Configuration | |
12 | -//public class PersonBeanConfiguration { | |
13 | -// | |
14 | -// /** | |
15 | -// * 创建FeignClient | |
16 | -// */ | |
17 | -// @Bean | |
18 | -// @ConditionalOnMissingBean | |
19 | -// public Client feignClient(CachingSpringLoadBalancerFactory cachingFactory, | |
20 | -// SpringClientFactory clientFactory) { | |
21 | -// return new LoadBalancerFeignClient(new Client.Default(null, null), | |
22 | -// cachingFactory, clientFactory); | |
23 | -// } | |
24 | -//} |
jeecg-boot/jeecg-boot-starter/jeecg-boot-starter-cloud/src/main/java/org/jeecg/starter/cloud/feign/IJeecgFeignService.java deleted
jeecg-boot/jeecg-boot-starter/jeecg-boot-starter-cloud/src/main/java/org/jeecg/starter/cloud/feign/impl/JeecgFeignService.java deleted
1 | -//package org.jeecg.starter.cloud.feign.impl; | |
2 | -// | |
3 | -//import feign.*; | |
4 | -//import feign.codec.Decoder; | |
5 | -//import feign.codec.Encoder; | |
6 | -//import lombok.extern.slf4j.Slf4j; | |
7 | -//import org.jeecg.common.constant.CommonConstant; | |
8 | -//import org.jeecg.starter.cloud.feign.IJeecgFeignService; | |
9 | -//import org.springframework.boot.autoconfigure.AutoConfigureBefore; | |
10 | -//import org.springframework.boot.autoconfigure.condition.ConditionalOnClass; | |
11 | -//import org.springframework.cloud.openfeign.FeignAutoConfiguration; | |
12 | -//import org.springframework.cloud.openfeign.FeignClientsConfiguration; | |
13 | -//import org.springframework.context.annotation.Import; | |
14 | -//import org.springframework.stereotype.Service; | |
15 | -//import org.springframework.web.context.request.RequestContextHolder; | |
16 | -//import org.springframework.web.context.request.ServletRequestAttributes; | |
17 | -// | |
18 | -//import javax.servlet.http.HttpServletRequest; | |
19 | -// | |
20 | -//@Service | |
21 | -//@Slf4j | |
22 | -//@ConditionalOnClass(Feign.class) | |
23 | -//@AutoConfigureBefore(FeignAutoConfiguration.class) | |
24 | -//@Import(FeignClientsConfiguration.class) | |
25 | -//public class JeecgFeignService implements IJeecgFeignService { | |
26 | -// | |
27 | -// | |
28 | -// //Feign 原生构造器 | |
29 | -// Feign.Builder builder; | |
30 | -// | |
31 | -// //创建构造器 | |
32 | -// public JeecgFeignService(Decoder decoder, Encoder encoder, Client client, Contract contract) { | |
33 | -// this.builder = Feign.builder() | |
34 | -// .client(client) | |
35 | -// .encoder(encoder) | |
36 | -// .decoder(decoder) | |
37 | -// .contract(contract); | |
38 | -// | |
39 | -// builder.requestInterceptor(requestTemplate -> { | |
40 | -// ServletRequestAttributes attributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes(); | |
41 | -// if (null != attributes) { | |
42 | -// HttpServletRequest request = attributes.getRequest(); | |
43 | -// log.info("Feign request: {}", request.getRequestURI()); | |
44 | -// // 将token信息放入header中 | |
45 | -// String token = request.getHeader(CommonConstant.X_ACCESS_TOKEN); | |
46 | -// if(token==null){ | |
47 | -// token = request.getParameter("token"); | |
48 | -// } | |
49 | -// log.info("Feign request token: {}", token); | |
50 | -// requestTemplate.header(CommonConstant.X_ACCESS_TOKEN, token); | |
51 | -// } | |
52 | -// }); | |
53 | -// } | |
54 | -// | |
55 | -// | |
56 | -// @Override | |
57 | -// public <T> T newInstance(Class<T> clientClass, String serviceName) { | |
58 | -// return builder.target(clientClass, String.format("http://%s/", serviceName)); | |
59 | -// } | |
60 | -//} | |
61 | 0 | \ No newline at end of file |
jeecg-boot/jeecg-boot-starter/jeecg-boot-starter-cloud/src/main/java/org/jeecg/starter/cloud/handler/CustomSentinelExceptionHandler.java deleted
1 | -package org.jeecg.starter.cloud.handler; | |
2 | - | |
3 | -import com.alibaba.csp.sentinel.adapter.spring.webmvc.callback.BlockExceptionHandler; | |
4 | -import com.alibaba.csp.sentinel.slots.block.BlockException; | |
5 | -import com.alibaba.csp.sentinel.slots.block.authority.AuthorityException; | |
6 | -import com.alibaba.csp.sentinel.slots.block.degrade.DegradeException; | |
7 | -import com.alibaba.csp.sentinel.slots.block.flow.FlowException; | |
8 | -import com.alibaba.csp.sentinel.slots.block.flow.param.ParamFlowException; | |
9 | -import com.alibaba.csp.sentinel.slots.system.SystemBlockException; | |
10 | -import org.springframework.context.annotation.Configuration; | |
11 | - | |
12 | -import javax.servlet.http.HttpServletRequest; | |
13 | -import javax.servlet.http.HttpServletResponse; | |
14 | - | |
15 | -/** | |
16 | - * @Description: 全局Sentinel自定义信息处理(需要启动Sentinel客户端) | |
17 | - * @author: zyf | |
18 | - * @date: 2022/02/18 | |
19 | - * @version: V1.0 | |
20 | - */ | |
21 | -@Configuration | |
22 | -public class CustomSentinelExceptionHandler implements BlockExceptionHandler { | |
23 | - | |
24 | - @Override | |
25 | - public void handle(HttpServletRequest request, HttpServletResponse response, BlockException ex) throws Exception { | |
26 | - | |
27 | - String msg = null; | |
28 | - | |
29 | - if (ex instanceof FlowException) { | |
30 | - msg = "访问频繁,请稍候再试"; | |
31 | - | |
32 | - } else if (ex instanceof DegradeException) { | |
33 | - msg = "系统降级"; | |
34 | - | |
35 | - } else if (ex instanceof ParamFlowException) { | |
36 | - msg = "热点参数限流"; | |
37 | - | |
38 | - } else if (ex instanceof SystemBlockException) { | |
39 | - msg = "系统规则限流或降级"; | |
40 | - | |
41 | - } else if (ex instanceof AuthorityException) { | |
42 | - msg = "授权规则不通过"; | |
43 | - | |
44 | - } else { | |
45 | - msg = "未知限流降级"; | |
46 | - } | |
47 | - // http状态码 | |
48 | - response.setStatus(200); | |
49 | - response.setCharacterEncoding("utf-8"); | |
50 | - response.setHeader("Content-Type", "application/json;charset=utf-8"); | |
51 | - response.setContentType("application/json;charset=utf-8"); | |
52 | - response.getWriter().write("{\"code\":500,\"message\":"+msg+"}"); | |
53 | - } | |
54 | - | |
55 | -} | |
56 | 0 | \ No newline at end of file |
jeecg-boot/jeecg-boot-starter/jeecg-boot-starter-cloud/src/main/java/org/jeecg/starter/cloud/interceptor/DefaultRequestOriginParser.java deleted
1 | -package org.jeecg.starter.cloud.interceptor; | |
2 | - | |
3 | -import com.alibaba.csp.sentinel.adapter.spring.webmvc.callback.RequestOriginParser; | |
4 | -import org.apache.commons.lang3.StringUtils; | |
5 | -import org.jeecg.common.util.IpUtils; | |
6 | -import org.springframework.stereotype.Component; | |
7 | - | |
8 | -import javax.servlet.http.HttpServletRequest; | |
9 | - | |
10 | -/** | |
11 | - * 【示例】sentinel ip和参数授权规则拦截器(黑名单白名单) | |
12 | - * 1. 有参数origin的时候走参数拦截规则 | |
13 | - * 2. 当参数为空时走ip拦截模式 | |
14 | - * | |
15 | - * @author zyf | |
16 | - */ | |
17 | -@Component | |
18 | -public class DefaultRequestOriginParser implements RequestOriginParser { | |
19 | - @Override | |
20 | - public String parseOrigin(HttpServletRequest request) { | |
21 | - //基于请求参数,origin对应授权规则中的流控应用名称,也可通过getHeader传参 | |
22 | - String origin = request.getParameter("origin"); | |
23 | - if (StringUtils.isNotEmpty(origin)) { | |
24 | - return origin; | |
25 | - } else { | |
26 | - //当参数为空使用ip拦截模式 | |
27 | - String ip = IpUtils.getIpAddr(request); | |
28 | - return ip; | |
29 | - } | |
30 | - } | |
31 | -} |
jeecg-boot/jeecg-boot-starter/jeecg-boot-starter-cloud/src/main/resources/bootstrap.yml deleted
1 | -spring: | |
2 | - #升级SpringBoot2.6.6,允许循环依赖 | |
3 | - main: | |
4 | - allow-circular-references: true | |
5 | - profiles: | |
6 | - # 当前激活环境 | |
7 | - active: '@profile.name@' | |
8 | - cloud: | |
9 | - #配置Bus id(远程推送事件) | |
10 | - bus: | |
11 | - id: ${spring.application.name}:${server.port} | |
12 | - nacos: | |
13 | - config: | |
14 | - # Nacos 认证用户 | |
15 | - username: @config.username@ | |
16 | - # Nacos 认证密码 | |
17 | - password: @config.password@ | |
18 | - # 命名空间 常用场景之一是不同环境的配置的区分隔离,例如开发测试环境和生产环境的资源(如配置、服务)隔离等 | |
19 | - namespace: @config.namespace@ | |
20 | - # 配置中心地址 | |
21 | - server-addr: @config.server-addr@ | |
22 | - # 配置对应的分组 | |
23 | - group: @config.group@ | |
24 | - # 配置文件后缀 | |
25 | - file-extension: yaml | |
26 | - prefix: @prefix.name@ | |
27 | - # 支持多个共享 Data Id 的配置,优先级小于extension-configs,自定义 Data Id 配置 属性是个集合,内部由 Config POJO 组成。Config 有 3 个属性,分别是 dataId, group 以及 refresh | |
28 | -# shared-configs[0]: | |
29 | -# data-id: @prefix.name@-sharding.yaml #分库分表配置 | |
30 | -# group: @config.group@ | |
31 | -# refresh: false | |
32 | -# shared-configs[1]: | |
33 | -# data-id: @prefix.name@-common.yaml # 配置文件名-Data Id | |
34 | -# group: @config.group@ # 默认为DEFAULT_GROUP | |
35 | -# refresh: false # 是否动态刷新,默认为false | |
36 | - discovery: | |
37 | - namespace: @config.namespace@ | |
38 | - server-addr: @config.server-addr@ | |
39 | - watch: | |
40 | - enabled: false | |
41 | -# feign启用sentinel | |
42 | -feign: | |
43 | - sentinel: | |
44 | - enabled: true | |
45 | - okhttp: | |
46 | - enabled: true | |
47 | - httpclient: | |
48 | - enabled: false | |
49 | - client: | |
50 | - config: | |
51 | - default: | |
52 | - #不设置connectTimeout会导致readTimeout设置不生效 | |
53 | - connectTimeout: 5000 | |
54 | - readTimeout: 10000 | |
55 | - compression: | |
56 | - request: | |
57 | - enabled: true | |
58 | - response: | |
59 | - enabled: true | |
60 | 0 | \ No newline at end of file |
jeecg-boot/jeecg-boot-starter/jeecg-boot-starter-job/pom.xml deleted
1 | -<?xml version="1.0" encoding="UTF-8"?> | |
2 | -<project xmlns="http://maven.apache.org/POM/4.0.0" | |
3 | - xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | |
4 | - xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | |
5 | - <parent> | |
6 | - <artifactId>jeecg-boot-starter</artifactId> | |
7 | - <groupId>org.jeecgframework.boot</groupId> | |
8 | - <version>3.3.0</version> | |
9 | - </parent> | |
10 | - <modelVersion>4.0.0</modelVersion> | |
11 | - <artifactId>jeecg-boot-starter-job</artifactId> | |
12 | - <description>jeecg-boot-starter-定时任务</description> | |
13 | - <dependencies> | |
14 | - <dependency> | |
15 | - <groupId>com.xuxueli</groupId> | |
16 | - <artifactId>xxl-job-core</artifactId> | |
17 | - <version>${xxl-job-core.version}</version> | |
18 | - </dependency> | |
19 | - </dependencies> | |
20 | - | |
21 | -</project> | |
22 | 0 | \ No newline at end of file |
jeecg-boot/jeecg-boot-starter/jeecg-boot-starter-job/src/main/java/com/xxl/job/core/executor/XxlJobExecutor.java deleted
1 | -package com.xxl.job.core.executor; | |
2 | - | |
3 | -import com.xxl.job.core.biz.AdminBiz; | |
4 | -import com.xxl.job.core.biz.client.AdminBizClient; | |
5 | -import com.xxl.job.core.handler.IJobHandler; | |
6 | -import com.xxl.job.core.log.XxlJobFileAppender; | |
7 | -import com.xxl.job.core.server.EmbedServer; | |
8 | -import com.xxl.job.core.thread.JobLogFileCleanThread; | |
9 | -import com.xxl.job.core.thread.JobThread; | |
10 | -import com.xxl.job.core.thread.TriggerCallbackThread; | |
11 | -import com.xxl.job.core.util.IpUtil; | |
12 | -import com.xxl.job.core.util.NetUtil; | |
13 | -import org.slf4j.Logger; | |
14 | -import org.slf4j.LoggerFactory; | |
15 | - | |
16 | -import java.util.ArrayList; | |
17 | -import java.util.List; | |
18 | -import java.util.Map; | |
19 | -import java.util.concurrent.ConcurrentHashMap; | |
20 | -import java.util.concurrent.ConcurrentMap; | |
21 | - | |
22 | -/** | |
23 | - * 重写目的修改默认端口9999为10000避免和网关冲突 | |
24 | - */ | |
25 | -public class XxlJobExecutor { | |
26 | - private static final Logger logger = LoggerFactory.getLogger(XxlJobExecutor.class); | |
27 | - | |
28 | - // ---------------------- param ---------------------- | |
29 | - private String adminAddresses; | |
30 | - private String accessToken; | |
31 | - private String appname; | |
32 | - private String address; | |
33 | - private String ip; | |
34 | - private int port; | |
35 | - private String logPath; | |
36 | - private int logRetentionDays; | |
37 | - | |
38 | - public void setAdminAddresses(String adminAddresses) { | |
39 | - this.adminAddresses = adminAddresses; | |
40 | - } | |
41 | - | |
42 | - public void setAccessToken(String accessToken) { | |
43 | - this.accessToken = accessToken; | |
44 | - } | |
45 | - | |
46 | - public void setAppname(String appname) { | |
47 | - this.appname = appname; | |
48 | - } | |
49 | - | |
50 | - public void setAddress(String address) { | |
51 | - this.address = address; | |
52 | - } | |
53 | - | |
54 | - public void setIp(String ip) { | |
55 | - this.ip = ip; | |
56 | - } | |
57 | - | |
58 | - public void setPort(int port) { | |
59 | - this.port = port; | |
60 | - } | |
61 | - | |
62 | - public void setLogPath(String logPath) { | |
63 | - this.logPath = logPath; | |
64 | - } | |
65 | - | |
66 | - public void setLogRetentionDays(int logRetentionDays) { | |
67 | - this.logRetentionDays = logRetentionDays; | |
68 | - } | |
69 | - | |
70 | - | |
71 | - // ---------------------- start + stop ---------------------- | |
72 | - public void start() throws Exception { | |
73 | - | |
74 | - // init logpath | |
75 | - XxlJobFileAppender.initLogPath(logPath); | |
76 | - | |
77 | - // init invoker, admin-client | |
78 | - initAdminBizList(adminAddresses, accessToken); | |
79 | - | |
80 | - | |
81 | - // init JobLogFileCleanThread | |
82 | - JobLogFileCleanThread.getInstance().start(logRetentionDays); | |
83 | - | |
84 | - // init TriggerCallbackThread | |
85 | - TriggerCallbackThread.getInstance().start(); | |
86 | - | |
87 | - // init executor-server | |
88 | - initEmbedServer(address, ip, port, appname, accessToken); | |
89 | - } | |
90 | - | |
91 | - public void destroy() { | |
92 | - // destory executor-server | |
93 | - stopEmbedServer(); | |
94 | - | |
95 | - // destory jobThreadRepository | |
96 | - if (jobThreadRepository.size() > 0) { | |
97 | - for (Map.Entry<Integer, JobThread> item : jobThreadRepository.entrySet()) { | |
98 | - JobThread oldJobThread = removeJobThread(item.getKey(), "web container destroy and kill the job."); | |
99 | - // wait for job thread push result to callback queue | |
100 | - if (oldJobThread != null) { | |
101 | - try { | |
102 | - oldJobThread.join(); | |
103 | - } catch (InterruptedException e) { | |
104 | - logger.error(">>>>>>>>>>> xxl-job, JobThread destroy(join) error, jobId:{}", item.getKey(), e); | |
105 | - } | |
106 | - } | |
107 | - } | |
108 | - jobThreadRepository.clear(); | |
109 | - } | |
110 | - jobHandlerRepository.clear(); | |
111 | - | |
112 | - | |
113 | - // destory JobLogFileCleanThread | |
114 | - JobLogFileCleanThread.getInstance().toStop(); | |
115 | - | |
116 | - // destory TriggerCallbackThread | |
117 | - TriggerCallbackThread.getInstance().toStop(); | |
118 | - | |
119 | - } | |
120 | - | |
121 | - | |
122 | - // ---------------------- admin-client (rpc invoker) ---------------------- | |
123 | - private static List<AdminBiz> adminBizList; | |
124 | - | |
125 | - private void initAdminBizList(String adminAddresses, String accessToken) throws Exception { | |
126 | - if (adminAddresses != null && adminAddresses.trim().length() > 0) { | |
127 | - for (String address : adminAddresses.trim().split(",")) { | |
128 | - if (address != null && address.trim().length() > 0) { | |
129 | - | |
130 | - AdminBiz adminBiz = new AdminBizClient(address.trim(), accessToken); | |
131 | - | |
132 | - if (adminBizList == null) { | |
133 | - adminBizList = new ArrayList<AdminBiz>(); | |
134 | - } | |
135 | - adminBizList.add(adminBiz); | |
136 | - } | |
137 | - } | |
138 | - } | |
139 | - } | |
140 | - | |
141 | - public static List<AdminBiz> getAdminBizList() { | |
142 | - return adminBizList; | |
143 | - } | |
144 | - | |
145 | - // ---------------------- executor-server (rpc provider) ---------------------- | |
146 | - private EmbedServer embedServer = null; | |
147 | - | |
148 | - private void initEmbedServer(String address, String ip, int port, String appname, String accessToken) throws Exception { | |
149 | - | |
150 | - // fill ip port 修改默认端口 | |
151 | - port = port > 0 ? port : NetUtil.findAvailablePort(10000); | |
152 | - ip = (ip != null && ip.trim().length() > 0) ? ip : IpUtil.getIp(); | |
153 | - | |
154 | - // generate address | |
155 | - if (address == null || address.trim().length() == 0) { | |
156 | - String ip_port_address = IpUtil.getIpPort(ip, port); // registry-address:default use address to registry , otherwise use ip:port if address is null | |
157 | - address = "http://{ip_port}/".replace("{ip_port}", ip_port_address); | |
158 | - } | |
159 | - | |
160 | - // accessToken | |
161 | - if (accessToken == null || accessToken.trim().length() == 0) { | |
162 | - logger.warn(">>>>>>>>>>> xxl-job accessToken is empty. To ensure system security, please set the accessToken."); | |
163 | - } | |
164 | - | |
165 | - // start | |
166 | - embedServer = new EmbedServer(); | |
167 | - embedServer.start(address, port, appname, accessToken); | |
168 | - } | |
169 | - | |
170 | - private void stopEmbedServer() { | |
171 | - // stop provider factory | |
172 | - if (embedServer != null) { | |
173 | - try { | |
174 | - embedServer.stop(); | |
175 | - } catch (Exception e) { | |
176 | - logger.error(e.getMessage(), e); | |
177 | - } | |
178 | - } | |
179 | - } | |
180 | - | |
181 | - | |
182 | - // ---------------------- job handler repository ---------------------- | |
183 | - private static ConcurrentMap<String, IJobHandler> jobHandlerRepository = new ConcurrentHashMap<String, IJobHandler>(); | |
184 | - | |
185 | - public static IJobHandler loadJobHandler(String name) { | |
186 | - return jobHandlerRepository.get(name); | |
187 | - } | |
188 | - | |
189 | - public static IJobHandler registJobHandler(String name, IJobHandler jobHandler) { | |
190 | - logger.info(">>>>>>>>>>> xxl-job register jobhandler success, name:{}, jobHandler:{}", name, jobHandler); | |
191 | - return jobHandlerRepository.put(name, jobHandler); | |
192 | - } | |
193 | - | |
194 | - | |
195 | - // ---------------------- job thread repository ---------------------- | |
196 | - private static ConcurrentMap<Integer, JobThread> jobThreadRepository = new ConcurrentHashMap<Integer, JobThread>(); | |
197 | - | |
198 | - public static JobThread registJobThread(int jobId, IJobHandler handler, String removeOldReason) { | |
199 | - JobThread newJobThread = new JobThread(jobId, handler); | |
200 | - newJobThread.start(); | |
201 | - logger.info(">>>>>>>>>>> xxl-job regist JobThread success, jobId:{}, handler:{}", new Object[]{jobId, handler}); | |
202 | - | |
203 | - JobThread oldJobThread = jobThreadRepository.put(jobId, newJobThread); // putIfAbsent | oh my god, map's put method return the old value!!! | |
204 | - if (oldJobThread != null) { | |
205 | - oldJobThread.toStop(removeOldReason); | |
206 | - oldJobThread.interrupt(); | |
207 | - } | |
208 | - | |
209 | - return newJobThread; | |
210 | - } | |
211 | - | |
212 | - public static JobThread removeJobThread(int jobId, String removeOldReason) { | |
213 | - JobThread oldJobThread = jobThreadRepository.remove(jobId); | |
214 | - if (oldJobThread != null) { | |
215 | - oldJobThread.toStop(removeOldReason); | |
216 | - oldJobThread.interrupt(); | |
217 | - | |
218 | - return oldJobThread; | |
219 | - } | |
220 | - return null; | |
221 | - } | |
222 | - | |
223 | - public static JobThread loadJobThread(int jobId) { | |
224 | - JobThread jobThread = jobThreadRepository.get(jobId); | |
225 | - return jobThread; | |
226 | - } | |
227 | - | |
228 | -} |
jeecg-boot/jeecg-boot-starter/jeecg-boot-starter-job/src/main/java/org/jeecg/boot/starter/job/annotation/EnableXxlJob.java deleted
1 | -package org.jeecg.boot.starter.job.annotation; | |
2 | - | |
3 | -import org.jeecg.boot.starter.job.config.XxlJobConfiguration; | |
4 | -import org.springframework.context.annotation.Import; | |
5 | - | |
6 | -import java.lang.annotation.*; | |
7 | - | |
8 | -/** | |
9 | - * @author zyf | |
10 | - */ | |
11 | -@Target({ ElementType.TYPE }) | |
12 | -@Retention(RetentionPolicy.RUNTIME) | |
13 | -@Documented | |
14 | -@Inherited | |
15 | -@Import({ XxlJobConfiguration.class }) | |
16 | -public @interface EnableXxlJob { | |
17 | - | |
18 | -} |
jeecg-boot/jeecg-boot-starter/jeecg-boot-starter-job/src/main/java/org/jeecg/boot/starter/job/config/XxlJobConfiguration.java deleted
1 | -package org.jeecg.boot.starter.job.config; | |
2 | - | |
3 | -import com.xxl.job.core.executor.impl.XxlJobSpringExecutor; | |
4 | -import lombok.extern.slf4j.Slf4j; | |
5 | -import org.jeecg.boot.starter.job.prop.XxlJobProperties; | |
6 | -import org.springframework.beans.factory.annotation.Autowired; | |
7 | -import org.springframework.boot.autoconfigure.condition.ConditionalOnClass; | |
8 | -import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; | |
9 | -import org.springframework.boot.context.properties.EnableConfigurationProperties; | |
10 | -import org.springframework.context.annotation.Bean; | |
11 | -import org.springframework.context.annotation.Configuration; | |
12 | - | |
13 | -/** | |
14 | - * 定时任务配置 | |
15 | - * | |
16 | - * @author jeecg | |
17 | - */ | |
18 | -@Slf4j | |
19 | -@Configuration | |
20 | -@EnableConfigurationProperties(value = XxlJobProperties.class) | |
21 | -@ConditionalOnProperty(value = "jeecg.xxljob.enabled", havingValue = "true", matchIfMissing = true) | |
22 | -public class XxlJobConfiguration { | |
23 | - | |
24 | - | |
25 | - @Autowired | |
26 | - private XxlJobProperties xxlJobProperties; | |
27 | - | |
28 | - //@Bean(initMethod = "start", destroyMethod = "destroy") | |
29 | - @Bean | |
30 | - @ConditionalOnClass() | |
31 | - public XxlJobSpringExecutor xxlJobExecutor() { | |
32 | - log.info(">>>>>>>>>>> xxl-job config init."); | |
33 | - //log.info(">>>> ip="+xxlJobProperties.getIp()+",Port="+xxlJobProperties.getPort()+",address="+xxlJobProperties.getAdminAddresses()); | |
34 | - XxlJobSpringExecutor xxlJobSpringExecutor = new XxlJobSpringExecutor(); | |
35 | - xxlJobSpringExecutor.setAdminAddresses(xxlJobProperties.getAdminAddresses()); | |
36 | - xxlJobSpringExecutor.setAppname(xxlJobProperties.getAppname()); | |
37 | - //update-begin--Author:scott -- Date:20210305 -- for:system服务和demo服务有办法同时使用xxl-job吗 #2313--- | |
38 | - //xxlJobSpringExecutor.setIp(xxlJobProperties.getIp()); | |
39 | - //xxlJobSpringExecutor.setPort(xxlJobProperties.getPort()); | |
40 | - //update-end--Author:scott -- Date:20210305 -- for:system服务和demo服务有办法同时使用xxl-job吗 #2313--- | |
41 | - xxlJobSpringExecutor.setAccessToken(xxlJobProperties.getAccessToken()); | |
42 | - xxlJobSpringExecutor.setLogPath(xxlJobProperties.getLogPath()); | |
43 | - xxlJobSpringExecutor.setLogRetentionDays(xxlJobProperties.getLogRetentionDays()); | |
44 | - return xxlJobSpringExecutor; | |
45 | - } | |
46 | - | |
47 | - | |
48 | -} |
jeecg-boot/jeecg-boot-starter/jeecg-boot-starter-job/src/main/java/org/jeecg/boot/starter/job/prop/XxlJobProperties.java deleted
1 | -package org.jeecg.boot.starter.job.prop; | |
2 | - | |
3 | -import lombok.Data; | |
4 | -import org.springframework.boot.context.properties.ConfigurationProperties; | |
5 | - | |
6 | -@Data | |
7 | -@ConfigurationProperties(prefix = "jeecg.xxljob") | |
8 | -public class XxlJobProperties { | |
9 | - | |
10 | - | |
11 | - private String adminAddresses; | |
12 | - | |
13 | - | |
14 | - private String appname; | |
15 | - | |
16 | - | |
17 | - private String ip; | |
18 | - | |
19 | - | |
20 | - private int port; | |
21 | - | |
22 | - | |
23 | - private String accessToken; | |
24 | - | |
25 | - | |
26 | - private String logPath; | |
27 | - | |
28 | - | |
29 | - private int logRetentionDays; | |
30 | - | |
31 | - /** | |
32 | - * 是否开启xxljob | |
33 | - */ | |
34 | - private Boolean enable = true; | |
35 | -} |
jeecg-boot/jeecg-boot-starter/jeecg-boot-starter-job/src/main/resources/META-INF/spring.factories deleted
jeecg-boot/jeecg-boot-starter/jeecg-boot-starter-lock/pom.xml deleted
1 | -<?xml version="1.0" encoding="UTF-8"?> | |
2 | -<project xmlns="http://maven.apache.org/POM/4.0.0" | |
3 | - xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | |
4 | - xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | |
5 | - <parent> | |
6 | - <artifactId>jeecg-boot-starter</artifactId> | |
7 | - <groupId>org.jeecgframework.boot</groupId> | |
8 | - <version>3.3.0</version> | |
9 | - </parent> | |
10 | - <modelVersion>4.0.0</modelVersion> | |
11 | - <artifactId>jeecg-boot-starter-lock</artifactId> | |
12 | - <description>jeecg-boot-starter-分布式锁</description> | |
13 | - <dependencies> | |
14 | - <dependency> | |
15 | - <groupId>org.jeecgframework.boot</groupId> | |
16 | - <artifactId>jeecg-boot-base-tools</artifactId> | |
17 | - </dependency> | |
18 | - <dependency> | |
19 | - <groupId>org.redisson</groupId> | |
20 | - <artifactId>redisson</artifactId> | |
21 | - </dependency> | |
22 | - <dependency> | |
23 | - <groupId>org.projectlombok</groupId> | |
24 | - <artifactId>lombok</artifactId> | |
25 | - <scope>provided</scope> | |
26 | - </dependency> | |
27 | - <dependency> | |
28 | - <groupId>org.apache.commons</groupId> | |
29 | - <artifactId>commons-lang3</artifactId> | |
30 | - </dependency> | |
31 | - <dependency> | |
32 | - <groupId>org.springframework.boot</groupId> | |
33 | - <artifactId>spring-boot-starter-aop</artifactId> | |
34 | - </dependency> | |
35 | - <dependency> | |
36 | - <groupId>com.google.guava</groupId> | |
37 | - <artifactId>guava</artifactId> | |
38 | - </dependency> | |
39 | - </dependencies> | |
40 | - | |
41 | -</project> | |
42 | 0 | \ No newline at end of file |
jeecg-boot/jeecg-boot-starter/jeecg-boot-starter-lock/src/main/java/org/jeecg/boot/starter/lock/annotation/JLock.java deleted
1 | -package org.jeecg.boot.starter.lock.annotation; | |
2 | - | |
3 | -import org.jeecg.boot.starter.lock.enums.LockModel; | |
4 | - | |
5 | -import java.lang.annotation.*; | |
6 | - | |
7 | -/** | |
8 | - * Redisson分布式锁注解 | |
9 | - * | |
10 | - * @author zyf | |
11 | - * @date 2020-11-11 | |
12 | - */ | |
13 | -@Target({ElementType.TYPE, ElementType.METHOD}) | |
14 | -@Retention(RetentionPolicy.RUNTIME) | |
15 | -@Documented | |
16 | -@Inherited | |
17 | -public @interface JLock { | |
18 | - | |
19 | - /** | |
20 | - * 锁的模式:如果不设置,自动模式,当参数只有一个.使用 REENTRANT 参数多个 MULTIPLE | |
21 | - */ | |
22 | - LockModel lockModel() default LockModel.AUTO; | |
23 | - | |
24 | - /** | |
25 | - * 如果keys有多个,如果不设置,则使用 联锁 | |
26 | - * @return | |
27 | - */ | |
28 | - String[] lockKey() default {}; | |
29 | - | |
30 | - /** | |
31 | - * key的静态常量:当key的spel的值是LIST,数组时使用+号连接将会被spel认为这个变量是个字符串 | |
32 | - * @return | |
33 | - */ | |
34 | - String keyConstant() default ""; | |
35 | - | |
36 | - | |
37 | - /** | |
38 | - * 锁超时时间,默认30000毫秒 | |
39 | - * | |
40 | - * @return int | |
41 | - */ | |
42 | - long expireSeconds() default 30000L; | |
43 | - | |
44 | - /** | |
45 | - * 等待加锁超时时间,默认10000毫秒 -1 则表示一直等待 | |
46 | - * | |
47 | - * @return int | |
48 | - */ | |
49 | - long waitTime() default 10000L; | |
50 | - | |
51 | - /** | |
52 | - * 未取到锁时提示信息 | |
53 | - * | |
54 | - * @return | |
55 | - */ | |
56 | - String failMsg() default "获取锁失败,请稍后重试"; | |
57 | -} |
jeecg-boot/jeecg-boot-starter/jeecg-boot-starter-lock/src/main/java/org/jeecg/boot/starter/lock/annotation/JRepeat.java deleted
1 | -package org.jeecg.boot.starter.lock.annotation; | |
2 | - | |
3 | -/** | |
4 | - * @author zyf | |
5 | - */ | |
6 | - | |
7 | -import java.lang.annotation.*; | |
8 | - | |
9 | -/** | |
10 | - * 防止重复提交的注解 | |
11 | - * | |
12 | - * @author 2019年6月18日 | |
13 | - */ | |
14 | -@Retention(RetentionPolicy.RUNTIME) | |
15 | -@Target({ElementType.METHOD}) | |
16 | -@Documented | |
17 | -public @interface JRepeat { | |
18 | - | |
19 | - /** | |
20 | - * 超时时间 | |
21 | - * | |
22 | - * @return | |
23 | - */ | |
24 | - int lockTime(); | |
25 | - | |
26 | - | |
27 | - /** | |
28 | - * redis 锁key的 | |
29 | - * | |
30 | - * @return redis 锁key | |
31 | - */ | |
32 | - String lockKey() default ""; | |
33 | - | |
34 | - | |
35 | - | |
36 | -} |
jeecg-boot/jeecg-boot-starter/jeecg-boot-starter-lock/src/main/java/org/jeecg/boot/starter/lock/annotation/LockConstant.java deleted
1 | -package org.jeecg.boot.starter.lock.annotation; | |
2 | - | |
3 | -/** | |
4 | - * @author zyf | |
5 | - * @date 2019/10/26 18:26 | |
6 | - */ | |
7 | - | |
8 | -/** | |
9 | - * 分布式锁枚举类 | |
10 | - * @author zyf | |
11 | - */ | |
12 | -public enum LockConstant { | |
13 | - /** | |
14 | - * 通用锁常量 | |
15 | - */ | |
16 | - COMMON("commonLock:", 1, 500, "请勿重复点击"); | |
17 | - /** | |
18 | - * 分布式锁前缀 | |
19 | - */ | |
20 | - private String keyPrefix; | |
21 | - /** | |
22 | - * 等到最大时间,强制获取锁 | |
23 | - */ | |
24 | - private int waitTime; | |
25 | - /** | |
26 | - * 锁失效时间 | |
27 | - */ | |
28 | - private int leaseTime; | |
29 | - /** | |
30 | - * 加锁提示 | |
31 | - */ | |
32 | - private String message; | |
33 | - | |
34 | - LockConstant(String keyPrefix, int waitTime, int leaseTime, String message) { | |
35 | - this.keyPrefix = keyPrefix; | |
36 | - this.waitTime = waitTime; | |
37 | - this.leaseTime = leaseTime; | |
38 | - this.message = message; | |
39 | - } | |
40 | - | |
41 | - public String getKeyPrefix() { | |
42 | - return keyPrefix; | |
43 | - } | |
44 | - | |
45 | - public void setKeyPrefix(String keyPrefix) { | |
46 | - this.keyPrefix = keyPrefix; | |
47 | - } | |
48 | - | |
49 | - public int getWaitTime() { | |
50 | - return waitTime; | |
51 | - } | |
52 | - | |
53 | - public void setWaitTime(int waitTime) { | |
54 | - this.waitTime = waitTime; | |
55 | - } | |
56 | - | |
57 | - public int getLeaseTime() { | |
58 | - return leaseTime; | |
59 | - } | |
60 | - | |
61 | - public void setLeaseTime(int leaseTime) { | |
62 | - this.leaseTime = leaseTime; | |
63 | - } | |
64 | - | |
65 | - public String getMessage() { | |
66 | - return message; | |
67 | - } | |
68 | - | |
69 | - public void setMessage(String message) { | |
70 | - this.message = message; | |
71 | - } | |
72 | -} |
jeecg-boot/jeecg-boot-starter/jeecg-boot-starter-lock/src/main/java/org/jeecg/boot/starter/lock/aspect/BaseAspect.java deleted
1 | -package org.jeecg.boot.starter.lock.aspect; | |
2 | - | |
3 | -import lombok.extern.slf4j.Slf4j; | |
4 | -import org.springframework.expression.EvaluationContext; | |
5 | -import org.springframework.expression.Expression; | |
6 | -import org.springframework.expression.ExpressionParser; | |
7 | -import org.springframework.expression.spel.standard.SpelExpressionParser; | |
8 | -import org.springframework.expression.spel.support.StandardEvaluationContext; | |
9 | - | |
10 | -import java.util.ArrayList; | |
11 | -import java.util.List; | |
12 | - | |
13 | -/** | |
14 | - * @author zyf | |
15 | - */ | |
16 | -@Slf4j | |
17 | -public class BaseAspect { | |
18 | - | |
19 | - /** | |
20 | - * 通过spring SpEL 获取参数 | |
21 | - * | |
22 | - * @param key 定义的key值 以#开头 例如:#user | |
23 | - * @param parameterNames 形参 | |
24 | - * @param values 形参值 | |
25 | - * @param keyConstant key的常亮 | |
26 | - * @return | |
27 | - */ | |
28 | - public List<String> getValueBySpEL(String key, String[] parameterNames, Object[] values, String keyConstant) { | |
29 | - List<String> keys = new ArrayList<>(); | |
30 | - if (!key.contains("#")) { | |
31 | - String s = "redis:lock:" + key + keyConstant; | |
32 | - log.debug("lockKey:" + s); | |
33 | - keys.add(s); | |
34 | - return keys; | |
35 | - } | |
36 | - //spel解析器 | |
37 | - ExpressionParser parser = new SpelExpressionParser(); | |
38 | - //spel上下文 | |
39 | - EvaluationContext context = new StandardEvaluationContext(); | |
40 | - for (int i = 0; i < parameterNames.length; i++) { | |
41 | - context.setVariable(parameterNames[i], values[i]); | |
42 | - } | |
43 | - Expression expression = parser.parseExpression(key); | |
44 | - Object value = expression.getValue(context); | |
45 | - if (value != null) { | |
46 | - if (value instanceof List) { | |
47 | - List value1 = (List) value; | |
48 | - for (Object o : value1) { | |
49 | - addKeys(keys, o, keyConstant); | |
50 | - } | |
51 | - } else if (value.getClass().isArray()) { | |
52 | - Object[] obj = (Object[]) value; | |
53 | - for (Object o : obj) { | |
54 | - addKeys(keys, o, keyConstant); | |
55 | - } | |
56 | - } else { | |
57 | - addKeys(keys, value, keyConstant); | |
58 | - } | |
59 | - } | |
60 | - log.info("表达式key={},value={}", key, keys); | |
61 | - return keys; | |
62 | - } | |
63 | - | |
64 | - private void addKeys(List<String> keys, Object o, String keyConstant) { | |
65 | - keys.add("redis:lock:" + o.toString() + keyConstant); | |
66 | - } | |
67 | -} |
jeecg-boot/jeecg-boot-starter/jeecg-boot-starter-lock/src/main/java/org/jeecg/boot/starter/lock/aspect/DistributedLockHandler.java deleted
1 | -package org.jeecg.boot.starter.lock.aspect; | |
2 | - | |
3 | -import lombok.SneakyThrows; | |
4 | -import lombok.extern.slf4j.Slf4j; | |
5 | -import org.aspectj.lang.ProceedingJoinPoint; | |
6 | -import org.aspectj.lang.annotation.Around; | |
7 | -import org.aspectj.lang.annotation.Aspect; | |
8 | -import org.aspectj.lang.reflect.MethodSignature; | |
9 | -import org.jeecg.boot.starter.lock.annotation.JLock; | |
10 | -import org.jeecg.boot.starter.lock.enums.LockModel; | |
11 | -import org.redisson.RedissonMultiLock; | |
12 | -import org.redisson.RedissonRedLock; | |
13 | -import org.redisson.api.RLock; | |
14 | -import org.redisson.api.RedissonClient; | |
15 | -import org.springframework.beans.factory.annotation.Autowired; | |
16 | -import org.springframework.core.LocalVariableTableParameterNameDiscoverer; | |
17 | -import org.springframework.expression.EvaluationContext; | |
18 | -import org.springframework.expression.Expression; | |
19 | -import org.springframework.expression.ExpressionParser; | |
20 | -import org.springframework.expression.spel.standard.SpelExpressionParser; | |
21 | -import org.springframework.expression.spel.support.StandardEvaluationContext; | |
22 | -import org.springframework.stereotype.Component; | |
23 | - | |
24 | -import java.util.ArrayList; | |
25 | -import java.util.List; | |
26 | -import java.util.concurrent.TimeUnit; | |
27 | - | |
28 | - | |
29 | -/** | |
30 | - * 分布式锁解析器 | |
31 | - * | |
32 | - * @author zyf | |
33 | - * @date 2020-11-11 | |
34 | - */ | |
35 | -@Slf4j | |
36 | -@Aspect | |
37 | -@Component | |
38 | -public class DistributedLockHandler extends BaseAspect{ | |
39 | - | |
40 | - | |
41 | - @Autowired(required = false) | |
42 | - private RedissonClient redissonClient; | |
43 | - | |
44 | - /** | |
45 | - * 切面环绕通知 | |
46 | - * | |
47 | - * @param joinPoint | |
48 | - * @param jLock | |
49 | - * @return Object | |
50 | - */ | |
51 | - @SneakyThrows | |
52 | - @Around("@annotation(jLock)") | |
53 | - public Object around(ProceedingJoinPoint joinPoint, JLock jLock) { | |
54 | - Object obj = null; | |
55 | - log.info("进入RedisLock环绕通知..."); | |
56 | - RLock rLock = getLock(joinPoint, jLock); | |
57 | - boolean res = false; | |
58 | - //获取超时时间 | |
59 | - long expireSeconds = jLock.expireSeconds(); | |
60 | - //等待多久,n秒内获取不到锁,则直接返回 | |
61 | - long waitTime = jLock.waitTime(); | |
62 | - //执行aop | |
63 | - if (rLock != null) { | |
64 | - try { | |
65 | - if (waitTime == -1) { | |
66 | - res = true; | |
67 | - //一直等待加锁 | |
68 | - rLock.lock(expireSeconds, TimeUnit.MILLISECONDS); | |
69 | - } else { | |
70 | - res = rLock.tryLock(waitTime, expireSeconds, TimeUnit.MILLISECONDS); | |
71 | - } | |
72 | - if (res) { | |
73 | - obj = joinPoint.proceed(); | |
74 | - } else { | |
75 | - log.error("获取锁异常"); | |
76 | - } | |
77 | - } finally { | |
78 | - if (res) { | |
79 | - rLock.unlock(); | |
80 | - } | |
81 | - } | |
82 | - } | |
83 | - log.info("结束RedisLock环绕通知..."); | |
84 | - return obj; | |
85 | - } | |
86 | - | |
87 | - @SneakyThrows | |
88 | - private RLock getLock(ProceedingJoinPoint joinPoint, JLock jLock) { | |
89 | - String[] keys = jLock.lockKey(); | |
90 | - if (keys.length == 0) { | |
91 | - throw new RuntimeException("keys不能为空"); | |
92 | - } | |
93 | - String[] parameterNames = new LocalVariableTableParameterNameDiscoverer().getParameterNames(((MethodSignature) joinPoint.getSignature()).getMethod()); | |
94 | - Object[] args = joinPoint.getArgs(); | |
95 | - | |
96 | - LockModel lockModel = jLock.lockModel(); | |
97 | - RLock rLock = null; | |
98 | - String keyConstant = jLock.keyConstant(); | |
99 | - if (lockModel.equals(LockModel.AUTO)) { | |
100 | - if (keys.length > 1) { | |
101 | - lockModel = LockModel.REDLOCK; | |
102 | - } else { | |
103 | - lockModel = LockModel.REENTRANT; | |
104 | - } | |
105 | - } | |
106 | - if (!lockModel.equals(LockModel.MULTIPLE) && !lockModel.equals(LockModel.REDLOCK) && keys.length > 1) { | |
107 | - throw new RuntimeException("参数有多个,锁模式为->" + lockModel.name() + ".无法锁定"); | |
108 | - } | |
109 | - switch (lockModel) { | |
110 | - case FAIR: | |
111 | - rLock = redissonClient.getFairLock(getValueBySpEL(keys[0], parameterNames, args, keyConstant).get(0)); | |
112 | - break; | |
113 | - case REDLOCK: | |
114 | - List<RLock> rLocks = new ArrayList<>(); | |
115 | - for (String key : keys) { | |
116 | - List<String> valueBySpEL = getValueBySpEL(key, parameterNames, args, keyConstant); | |
117 | - for (String s : valueBySpEL) { | |
118 | - rLocks.add(redissonClient.getLock(s)); | |
119 | - } | |
120 | - } | |
121 | - RLock[] locks = new RLock[rLocks.size()]; | |
122 | - int index = 0; | |
123 | - for (RLock r : rLocks) { | |
124 | - locks[index++] = r; | |
125 | - } | |
126 | - rLock = new RedissonRedLock(locks); | |
127 | - break; | |
128 | - case MULTIPLE: | |
129 | - rLocks = new ArrayList<>(); | |
130 | - | |
131 | - for (String key : keys) { | |
132 | - List<String> valueBySpEL = getValueBySpEL(key, parameterNames, args, keyConstant); | |
133 | - for (String s : valueBySpEL) { | |
134 | - rLocks.add(redissonClient.getLock(s)); | |
135 | - } | |
136 | - } | |
137 | - locks = new RLock[rLocks.size()]; | |
138 | - index = 0; | |
139 | - for (RLock r : rLocks) { | |
140 | - locks[index++] = r; | |
141 | - } | |
142 | - rLock = new RedissonMultiLock(locks); | |
143 | - break; | |
144 | - case REENTRANT: | |
145 | - List<String> valueBySpEL = getValueBySpEL(keys[0], parameterNames, args, keyConstant); | |
146 | - //如果spel表达式是数组或者LIST 则使用红锁 | |
147 | - if (valueBySpEL.size() == 1) { | |
148 | - rLock = redissonClient.getLock(valueBySpEL.get(0)); | |
149 | - } else { | |
150 | - locks = new RLock[valueBySpEL.size()]; | |
151 | - index = 0; | |
152 | - for (String s : valueBySpEL) { | |
153 | - locks[index++] = redissonClient.getLock(s); | |
154 | - } | |
155 | - rLock = new RedissonRedLock(locks); | |
156 | - } | |
157 | - break; | |
158 | - case READ: | |
159 | - rLock = redissonClient.getReadWriteLock(getValueBySpEL(keys[0], parameterNames, args, keyConstant).get(0)).readLock(); | |
160 | - break; | |
161 | - case WRITE: | |
162 | - rLock = redissonClient.getReadWriteLock(getValueBySpEL(keys[0], parameterNames, args, keyConstant).get(0)).writeLock(); | |
163 | - break; | |
164 | - } | |
165 | - return rLock; | |
166 | - } | |
167 | -} |
jeecg-boot/jeecg-boot-starter/jeecg-boot-starter-lock/src/main/java/org/jeecg/boot/starter/lock/aspect/RepeatSubmitAspect.java deleted
1 | -package org.jeecg.boot.starter.lock.aspect; | |
2 | - | |
3 | -/** | |
4 | - * @author zyf | |
5 | - */ | |
6 | - | |
7 | -import org.aspectj.lang.ProceedingJoinPoint; | |
8 | -import org.aspectj.lang.annotation.Around; | |
9 | -import org.aspectj.lang.annotation.Aspect; | |
10 | -import org.aspectj.lang.annotation.Pointcut; | |
11 | -import org.aspectj.lang.reflect.MethodSignature; | |
12 | -import org.jeecg.boot.starter.lock.annotation.JRepeat; | |
13 | -import org.jeecg.boot.starter.lock.client.RedissonLockClient; | |
14 | -import org.jeecg.common.exception.JeecgCloudException; | |
15 | -import org.springframework.core.LocalVariableTableParameterNameDiscoverer; | |
16 | -import org.springframework.stereotype.Component; | |
17 | - | |
18 | -import javax.annotation.Resource; | |
19 | -import java.util.Objects; | |
20 | -import java.util.concurrent.TimeUnit; | |
21 | - | |
22 | -/** | |
23 | - * 防止重复提交分布式锁拦截器 | |
24 | - * | |
25 | - * @author 2019年6月18日 | |
26 | - */ | |
27 | -@Aspect | |
28 | -@Component | |
29 | -public class RepeatSubmitAspect extends BaseAspect{ | |
30 | - | |
31 | - @Resource | |
32 | - private RedissonLockClient redissonLockClient; | |
33 | - | |
34 | - /*** | |
35 | - * 定义controller切入点拦截规则,拦截JRepeat注解的业务方法 | |
36 | - */ | |
37 | - @Pointcut("@annotation(jRepeat)") | |
38 | - public void pointCut(JRepeat jRepeat) { | |
39 | - } | |
40 | - | |
41 | - /** | |
42 | - * AOP分布式锁拦截 | |
43 | - * | |
44 | - * @param joinPoint | |
45 | - * @return | |
46 | - * @throws Exception | |
47 | - */ | |
48 | - @Around("pointCut(jRepeat)") | |
49 | - public Object repeatSubmit(ProceedingJoinPoint joinPoint,JRepeat jRepeat) throws Throwable { | |
50 | - String[] parameterNames = new LocalVariableTableParameterNameDiscoverer().getParameterNames(((MethodSignature) joinPoint.getSignature()).getMethod()); | |
51 | - if (Objects.nonNull(jRepeat)) { | |
52 | - // 获取参数 | |
53 | - Object[] args = joinPoint.getArgs(); | |
54 | - // 进行一些参数的处理,比如获取订单号,操作人id等 | |
55 | - StringBuffer lockKeyBuffer = new StringBuffer(); | |
56 | - String key =getValueBySpEL(jRepeat.lockKey(), parameterNames, args,"RepeatSubmit").get(0); | |
57 | - // 公平加锁,lockTime后锁自动释放 | |
58 | - boolean isLocked = false; | |
59 | - try { | |
60 | - isLocked = redissonLockClient.fairLock(key, TimeUnit.SECONDS, jRepeat.lockTime()); | |
61 | - // 如果成功获取到锁就继续执行 | |
62 | - if (isLocked) { | |
63 | - // 执行进程 | |
64 | - return joinPoint.proceed(); | |
65 | - } else { | |
66 | - // 未获取到锁 | |
67 | - throw new JeecgCloudException("请勿重复提交"); | |
68 | - } | |
69 | - } finally { | |
70 | - // 如果锁还存在,在方法执行完成后,释放锁 | |
71 | - if (isLocked) { | |
72 | - redissonLockClient.unlock(key); | |
73 | - } | |
74 | - } | |
75 | - } | |
76 | - | |
77 | - return joinPoint.proceed(); | |
78 | - } | |
79 | - | |
80 | - | |
81 | -} |
jeecg-boot/jeecg-boot-starter/jeecg-boot-starter-lock/src/main/java/org/jeecg/boot/starter/lock/client/RedissonLockClient.java deleted
1 | -package org.jeecg.boot.starter.lock.client; | |
2 | - | |
3 | -import lombok.extern.slf4j.Slf4j; | |
4 | -import org.redisson.api.RLock; | |
5 | -import org.redisson.api.RedissonClient; | |
6 | -import org.springframework.beans.factory.annotation.Autowired; | |
7 | -import org.springframework.data.redis.core.RedisTemplate; | |
8 | -import org.springframework.stereotype.Component; | |
9 | - | |
10 | -import java.util.concurrent.TimeUnit; | |
11 | - | |
12 | -/** | |
13 | - * 分布式锁实现基于Redisson | |
14 | - * | |
15 | - * @author zyf | |
16 | - * @date 2020-11-11 | |
17 | - */ | |
18 | -@Slf4j | |
19 | -@Component | |
20 | -public class RedissonLockClient { | |
21 | - | |
22 | - @Autowired | |
23 | - private RedissonClient redissonClient; | |
24 | - | |
25 | - @Autowired | |
26 | - private RedisTemplate<String, Object> redisTemplate; | |
27 | - | |
28 | - /** | |
29 | - * 获取锁 | |
30 | - */ | |
31 | - public RLock getLock(String lockKey) { | |
32 | - return redissonClient.getLock(lockKey); | |
33 | - } | |
34 | - | |
35 | - /** | |
36 | - * 加锁操作 | |
37 | - * | |
38 | - * @return boolean | |
39 | - */ | |
40 | - public boolean tryLock(String lockName, long expireSeconds) { | |
41 | - return tryLock(lockName, 0, expireSeconds); | |
42 | - } | |
43 | - | |
44 | - | |
45 | - /** | |
46 | - * 加锁操作 | |
47 | - * | |
48 | - * @return boolean | |
49 | - */ | |
50 | - public boolean tryLock(String lockName, long waitTime, long expireSeconds) { | |
51 | - RLock rLock = getLock(lockName); | |
52 | - boolean getLock = false; | |
53 | - try { | |
54 | - getLock = rLock.tryLock(waitTime, expireSeconds, TimeUnit.SECONDS); | |
55 | - if (getLock) { | |
56 | - log.info("获取锁成功,lockName={}", lockName); | |
57 | - } else { | |
58 | - log.info("获取锁失败,lockName={}", lockName); | |
59 | - } | |
60 | - } catch (InterruptedException e) { | |
61 | - log.error("获取式锁异常,lockName=" + lockName, e); | |
62 | - getLock = false; | |
63 | - } | |
64 | - return getLock; | |
65 | - } | |
66 | - | |
67 | - | |
68 | - public boolean fairLock(String lockKey, TimeUnit unit, int leaseTime) { | |
69 | - RLock fairLock = redissonClient.getFairLock(lockKey); | |
70 | - try { | |
71 | - boolean existKey = existKey(lockKey); | |
72 | - // 已经存在了,就直接返回 | |
73 | - if (existKey) { | |
74 | - return false; | |
75 | - } | |
76 | - return fairLock.tryLock(3, leaseTime, unit); | |
77 | - } catch (InterruptedException e) { | |
78 | - e.printStackTrace(); | |
79 | - } | |
80 | - return false; | |
81 | - } | |
82 | - | |
83 | - public boolean existKey(String key) { | |
84 | - return redisTemplate.hasKey(key); | |
85 | - } | |
86 | - /** | |
87 | - * 锁lockKey | |
88 | - * | |
89 | - * @param lockKey | |
90 | - * @return | |
91 | - */ | |
92 | - public RLock lock(String lockKey) { | |
93 | - RLock lock = getLock(lockKey); | |
94 | - lock.lock(); | |
95 | - return lock; | |
96 | - } | |
97 | - | |
98 | - /** | |
99 | - * 锁lockKey | |
100 | - * | |
101 | - * @param lockKey | |
102 | - * @param leaseTime | |
103 | - * @return | |
104 | - */ | |
105 | - public RLock lock(String lockKey, long leaseTime) { | |
106 | - RLock lock = getLock(lockKey); | |
107 | - lock.lock(leaseTime, TimeUnit.SECONDS); | |
108 | - return lock; | |
109 | - } | |
110 | - | |
111 | - | |
112 | - /** | |
113 | - * 解锁 | |
114 | - * | |
115 | - * @param lockName 锁名称 | |
116 | - */ | |
117 | - public void unlock(String lockName) { | |
118 | - try { | |
119 | - redissonClient.getLock(lockName).unlock(); | |
120 | - } catch (Exception e) { | |
121 | - log.error("解锁异常,lockName=" + lockName, e); | |
122 | - } | |
123 | - } | |
124 | - | |
125 | - | |
126 | -} |
jeecg-boot/jeecg-boot-starter/jeecg-boot-starter-lock/src/main/java/org/jeecg/boot/starter/lock/config/RedissonConfiguration.java deleted
1 | -package org.jeecg.boot.starter.lock.config; | |
2 | - | |
3 | -import lombok.extern.slf4j.Slf4j; | |
4 | -import org.jeecg.boot.starter.lock.core.RedissonManager; | |
5 | -import org.jeecg.boot.starter.lock.prop.RedissonProperties; | |
6 | -import org.redisson.api.RedissonClient; | |
7 | -import org.springframework.boot.autoconfigure.condition.ConditionalOnClass; | |
8 | -import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; | |
9 | -import org.springframework.boot.context.properties.EnableConfigurationProperties; | |
10 | -import org.springframework.context.annotation.Bean; | |
11 | -import org.springframework.context.annotation.Configuration; | |
12 | - | |
13 | - | |
14 | -/** | |
15 | - * Redisson自动化配置 | |
16 | - * | |
17 | - * @author zyf | |
18 | - * @date 2020-11-11 | |
19 | - */ | |
20 | -@Slf4j | |
21 | -@Configuration | |
22 | -@ConditionalOnClass(RedissonProperties.class) | |
23 | -@EnableConfigurationProperties(RedissonProperties.class) | |
24 | -public class RedissonConfiguration { | |
25 | - | |
26 | - | |
27 | - | |
28 | - @Bean | |
29 | - @ConditionalOnMissingBean(RedissonClient.class) | |
30 | - public RedissonClient redissonClient(RedissonProperties redissonProperties) { | |
31 | - RedissonManager redissonManager = new RedissonManager(redissonProperties); | |
32 | - log.info("RedissonManager初始化完成,当前连接方式:" + redissonProperties.getType() + ",连接地址:" + redissonProperties.getAddress()); | |
33 | - return redissonManager.getRedisson(); | |
34 | - } | |
35 | - | |
36 | -} |
jeecg-boot/jeecg-boot-starter/jeecg-boot-starter-lock/src/main/java/org/jeecg/boot/starter/lock/core/RedissonManager.java deleted
1 | -package org.jeecg.boot.starter.lock.core; | |
2 | - | |
3 | - | |
4 | -import com.google.common.base.Preconditions; | |
5 | -import lombok.extern.slf4j.Slf4j; | |
6 | -import org.jeecg.boot.starter.lock.core.strategy.RedissonConfigStrategy; | |
7 | -import org.jeecg.boot.starter.lock.prop.RedissonProperties; | |
8 | -import org.jeecg.boot.starter.lock.core.strategy.impl.ClusterRedissonConfigStrategyImpl; | |
9 | -import org.jeecg.boot.starter.lock.core.strategy.impl.MasterslaveRedissonConfigStrategyImpl; | |
10 | -import org.jeecg.boot.starter.lock.core.strategy.impl.SentinelRedissonConfigStrategyImpl; | |
11 | -import org.jeecg.boot.starter.lock.core.strategy.impl.StandaloneRedissonConfigStrategyImpl; | |
12 | -import org.jeecg.boot.starter.lock.enums.RedisConnectionType; | |
13 | -import org.redisson.Redisson; | |
14 | -import org.redisson.config.Config; | |
15 | - | |
16 | - | |
17 | -/** | |
18 | - * Redisson配置管理器,用于初始化的redisson实例 | |
19 | - * | |
20 | - * @author zyf | |
21 | - * @date 2020-11-12 | |
22 | - */ | |
23 | -@Slf4j | |
24 | -public class RedissonManager { | |
25 | - | |
26 | - private Config config = new Config(); | |
27 | - | |
28 | - private Redisson redisson = null; | |
29 | - | |
30 | - public RedissonManager() { | |
31 | - } | |
32 | - | |
33 | - public RedissonManager(RedissonProperties redissonProperties) { | |
34 | - //装配开关 | |
35 | - Boolean enabled = redissonProperties.getEnabled(); | |
36 | - if (enabled) { | |
37 | - try { | |
38 | - config = RedissonConfigFactory.getInstance().createConfig(redissonProperties); | |
39 | - redisson = (Redisson) Redisson.create(config); | |
40 | - } catch (Exception e) { | |
41 | - log.error("Redisson初始化错误", e); | |
42 | - } | |
43 | - } | |
44 | - } | |
45 | - | |
46 | - public Redisson getRedisson() { | |
47 | - return redisson; | |
48 | - } | |
49 | - | |
50 | - /** | |
51 | - * Redisson连接方式配置工厂 | |
52 | - * 双重检查锁 | |
53 | - */ | |
54 | - static class RedissonConfigFactory { | |
55 | - | |
56 | - private RedissonConfigFactory() { | |
57 | - } | |
58 | - | |
59 | - private static volatile RedissonConfigFactory factory = null; | |
60 | - | |
61 | - public static RedissonConfigFactory getInstance() { | |
62 | - if (factory == null) { | |
63 | - synchronized (Object.class) { | |
64 | - if (factory == null) { | |
65 | - factory = new RedissonConfigFactory(); | |
66 | - } | |
67 | - } | |
68 | - } | |
69 | - return factory; | |
70 | - } | |
71 | - | |
72 | - /** | |
73 | - * 根据连接类型創建连接方式的配置 | |
74 | - * | |
75 | - * @param redissonProperties | |
76 | - * @return Config | |
77 | - */ | |
78 | - Config createConfig(RedissonProperties redissonProperties) { | |
79 | - Preconditions.checkNotNull(redissonProperties); | |
80 | - Preconditions.checkNotNull(redissonProperties.getAddress(), "redis地址未配置"); | |
81 | - RedisConnectionType connectionType = redissonProperties.getType(); | |
82 | - // 声明连接方式 | |
83 | - RedissonConfigStrategy redissonConfigStrategy; | |
84 | - if (connectionType.equals(RedisConnectionType.SENTINEL)) { | |
85 | - redissonConfigStrategy = new SentinelRedissonConfigStrategyImpl(); | |
86 | - } else if (connectionType.equals(RedisConnectionType.CLUSTER)) { | |
87 | - redissonConfigStrategy = new ClusterRedissonConfigStrategyImpl(); | |
88 | - } else if (connectionType.equals(RedisConnectionType.MASTERSLAVE)) { | |
89 | - redissonConfigStrategy = new MasterslaveRedissonConfigStrategyImpl(); | |
90 | - } else { | |
91 | - redissonConfigStrategy = new StandaloneRedissonConfigStrategyImpl(); | |
92 | - } | |
93 | - Preconditions.checkNotNull(redissonConfigStrategy, "连接方式创建异常"); | |
94 | - | |
95 | - return redissonConfigStrategy.createRedissonConfig(redissonProperties); | |
96 | - } | |
97 | - } | |
98 | - | |
99 | - | |
100 | -} |
jeecg-boot/jeecg-boot-starter/jeecg-boot-starter-lock/src/main/java/org/jeecg/boot/starter/lock/core/strategy/RedissonConfigStrategy.java deleted
1 | -package org.jeecg.boot.starter.lock.core.strategy; | |
2 | - | |
3 | -import org.jeecg.boot.starter.lock.prop.RedissonProperties; | |
4 | -import org.redisson.config.Config; | |
5 | - | |
6 | -/** | |
7 | - * Redisson配置构建接口 | |
8 | - * | |
9 | - * @author zyf | |
10 | - * @date 2020-11-11 | |
11 | - */ | |
12 | -public interface RedissonConfigStrategy { | |
13 | - | |
14 | - /** | |
15 | - * 根据不同的Redis配置策略创建对应的Config | |
16 | - * | |
17 | - * @param redissonProperties | |
18 | - * @return Config | |
19 | - */ | |
20 | - Config createRedissonConfig(RedissonProperties redissonProperties); | |
21 | -} |
jeecg-boot/jeecg-boot-starter/jeecg-boot-starter-lock/src/main/java/org/jeecg/boot/starter/lock/core/strategy/impl/ClusterRedissonConfigStrategyImpl.java deleted
1 | -package org.jeecg.boot.starter.lock.core.strategy.impl; | |
2 | - | |
3 | -import lombok.extern.slf4j.Slf4j; | |
4 | -import org.apache.commons.lang3.StringUtils; | |
5 | -import org.jeecg.boot.starter.lock.core.strategy.RedissonConfigStrategy; | |
6 | -import org.jeecg.boot.starter.lock.prop.RedissonProperties; | |
7 | -import org.jeecg.boot.starter.lock.enums.GlobalConstant; | |
8 | -import org.redisson.config.Config; | |
9 | - | |
10 | - | |
11 | -/** | |
12 | - * 集群方式Redisson配置 | |
13 | - * cluster方式至少6个节点(3主3从) | |
14 | - * 配置方式:127.0.0.1:6379,127.0.0.1:6380,127.0.0.1:6381,127.0.0.1:6382,127.0.0.1:6383,127.0.0.1:6384 | |
15 | - * | |
16 | - * @author zyf | |
17 | - * @date 2020-11-11 | |
18 | - */ | |
19 | -@Slf4j | |
20 | -public class ClusterRedissonConfigStrategyImpl implements RedissonConfigStrategy { | |
21 | - | |
22 | - @Override | |
23 | - public Config createRedissonConfig(RedissonProperties redissonProperties) { | |
24 | - Config config = new Config(); | |
25 | - try { | |
26 | - String address = redissonProperties.getAddress(); | |
27 | - String password = redissonProperties.getPassword(); | |
28 | - String[] addrTokens = address.split(","); | |
29 | - // 设置集群(cluster)节点的服务IP和端口 | |
30 | - for (int i = 0; i < addrTokens.length; i++) { | |
31 | - config.useClusterServers().addNodeAddress(GlobalConstant.REDIS_CONNECTION_PREFIX + addrTokens[i]); | |
32 | - if (StringUtils.isNotBlank(password)) { | |
33 | - config.useClusterServers().setPassword(password); | |
34 | - } | |
35 | - } | |
36 | - log.info("初始化集群方式Config,连接地址:" + address); | |
37 | - } catch (Exception e) { | |
38 | - log.error("集群Redisson初始化错误", e); | |
39 | - e.printStackTrace(); | |
40 | - } | |
41 | - return config; | |
42 | - } | |
43 | -} |
jeecg-boot/jeecg-boot-starter/jeecg-boot-starter-lock/src/main/java/org/jeecg/boot/starter/lock/core/strategy/impl/MasterslaveRedissonConfigStrategyImpl.java deleted
1 | -package org.jeecg.boot.starter.lock.core.strategy.impl; | |
2 | - | |
3 | -import lombok.extern.slf4j.Slf4j; | |
4 | -import org.apache.commons.lang3.StringUtils; | |
5 | -import org.jeecg.boot.starter.lock.core.strategy.RedissonConfigStrategy; | |
6 | -import org.jeecg.boot.starter.lock.prop.RedissonProperties; | |
7 | -import org.jeecg.boot.starter.lock.enums.GlobalConstant; | |
8 | -import org.redisson.config.Config; | |
9 | - | |
10 | - | |
11 | -import java.util.ArrayList; | |
12 | -import java.util.List; | |
13 | - | |
14 | -/** | |
15 | - * 主从方式Redisson配置 | |
16 | - * <p>配置方式: 127.0.0.1:6379(主),127.0.0.1:6380(子),127.0.0.1:6381(子)</p> | |
17 | - * | |
18 | - * @author zyf | |
19 | - * @date 2020-11-11 | |
20 | - */ | |
21 | -@Slf4j | |
22 | -public class MasterslaveRedissonConfigStrategyImpl implements RedissonConfigStrategy { | |
23 | - | |
24 | - @Override | |
25 | - public Config createRedissonConfig(RedissonProperties redissonProperties) { | |
26 | - Config config = new Config(); | |
27 | - try { | |
28 | - String address = redissonProperties.getAddress(); | |
29 | - String password = redissonProperties.getPassword(); | |
30 | - int database = redissonProperties.getDatabase(); | |
31 | - String[] addrTokens = address.split(","); | |
32 | - String masterNodeAddr = addrTokens[0]; | |
33 | - // 设置主节点ip | |
34 | - config.useMasterSlaveServers().setMasterAddress(masterNodeAddr); | |
35 | - if (StringUtils.isNotBlank(password)) { | |
36 | - config.useMasterSlaveServers().setPassword(password); | |
37 | - } | |
38 | - config.useMasterSlaveServers().setDatabase(database); | |
39 | - // 设置从节点,移除第一个节点,默认第一个为主节点 | |
40 | - List<String> slaveList = new ArrayList<>(); | |
41 | - for (String addrToken : addrTokens) { | |
42 | - slaveList.add(GlobalConstant.REDIS_CONNECTION_PREFIX + addrToken); | |
43 | - } | |
44 | - slaveList.remove(0); | |
45 | - | |
46 | - config.useMasterSlaveServers().addSlaveAddress((String[]) slaveList.toArray()); | |
47 | - log.info("初始化主从方式Config,redisAddress:" + address); | |
48 | - } catch (Exception e) { | |
49 | - log.error("主从Redisson初始化错误", e); | |
50 | - e.printStackTrace(); | |
51 | - } | |
52 | - return config; | |
53 | - } | |
54 | -} |
jeecg-boot/jeecg-boot-starter/jeecg-boot-starter-lock/src/main/java/org/jeecg/boot/starter/lock/core/strategy/impl/SentinelRedissonConfigStrategyImpl.java deleted
1 | -package org.jeecg.boot.starter.lock.core.strategy.impl; | |
2 | - | |
3 | -import lombok.extern.slf4j.Slf4j; | |
4 | -import org.apache.commons.lang3.StringUtils; | |
5 | -import org.jeecg.boot.starter.lock.core.strategy.RedissonConfigStrategy; | |
6 | -import org.jeecg.boot.starter.lock.prop.RedissonProperties; | |
7 | -import org.jeecg.boot.starter.lock.enums.GlobalConstant; | |
8 | -import org.redisson.config.Config; | |
9 | - | |
10 | - | |
11 | -/** | |
12 | - * 哨兵方式Redis连接配置 | |
13 | - * 比如sentinel.conf里配置为sentinel monitor my-sentinel-name 127.0.0.1 6379 2,那么这里就配置my-sentinel-name | |
14 | - * 配置方式:my-sentinel-name,127.0.0.1:26379,127.0.0.1:26389,127.0.0.1:26399 | |
15 | - * @author zyf | |
16 | - * @date 2020-11-11 | |
17 | - */ | |
18 | -@Slf4j | |
19 | -public class SentinelRedissonConfigStrategyImpl implements RedissonConfigStrategy { | |
20 | - | |
21 | - @Override | |
22 | - public Config createRedissonConfig(RedissonProperties redissonProperties) { | |
23 | - Config config = new Config(); | |
24 | - try { | |
25 | - String address = redissonProperties.getAddress(); | |
26 | - String password = redissonProperties.getPassword(); | |
27 | - int database = redissonProperties.getDatabase(); | |
28 | - String[] addrTokens = address.split(","); | |
29 | - String sentinelAliasName = addrTokens[0]; | |
30 | - // 设置redis配置文件sentinel.conf配置的sentinel别名 | |
31 | - config.useSentinelServers().setMasterName(sentinelAliasName); | |
32 | - config.useSentinelServers().setDatabase(database); | |
33 | - if (StringUtils.isNotBlank(password)) { | |
34 | - config.useSentinelServers().setPassword(password); | |
35 | - } | |
36 | - // 设置哨兵节点的服务IP和端口 | |
37 | - for (int i = 1; i < addrTokens.length; i++) { | |
38 | - config.useSentinelServers().addSentinelAddress(GlobalConstant.REDIS_CONNECTION_PREFIX+ addrTokens[i]); | |
39 | - } | |
40 | - log.info("初始化哨兵方式Config,redisAddress:" + address); | |
41 | - } catch (Exception e) { | |
42 | - log.error("哨兵Redisson初始化错误", e); | |
43 | - e.printStackTrace(); | |
44 | - } | |
45 | - return config; | |
46 | - } | |
47 | -} |
jeecg-boot/jeecg-boot-starter/jeecg-boot-starter-lock/src/main/java/org/jeecg/boot/starter/lock/core/strategy/impl/StandaloneRedissonConfigStrategyImpl.java deleted
1 | -package org.jeecg.boot.starter.lock.core.strategy.impl; | |
2 | - | |
3 | -import lombok.extern.slf4j.Slf4j; | |
4 | -import org.apache.commons.lang3.StringUtils; | |
5 | -import org.jeecg.boot.starter.lock.core.strategy.RedissonConfigStrategy; | |
6 | -import org.jeecg.boot.starter.lock.prop.RedissonProperties; | |
7 | -import org.jeecg.boot.starter.lock.enums.GlobalConstant; | |
8 | -import org.redisson.config.Config; | |
9 | - | |
10 | - | |
11 | -/** | |
12 | - * 单机方式Redisson配置 | |
13 | - * | |
14 | - * @author zyf | |
15 | - * @date 2020-11-11 | |
16 | - */ | |
17 | -@Slf4j | |
18 | -public class StandaloneRedissonConfigStrategyImpl implements RedissonConfigStrategy { | |
19 | - | |
20 | - @Override | |
21 | - public Config createRedissonConfig(RedissonProperties redissonProperties) { | |
22 | - Config config = new Config(); | |
23 | - try { | |
24 | - String address = redissonProperties.getAddress(); | |
25 | - String password = redissonProperties.getPassword(); | |
26 | - int database = redissonProperties.getDatabase(); | |
27 | - String redisAddr = GlobalConstant.REDIS_CONNECTION_PREFIX + address; | |
28 | - config.useSingleServer().setAddress(redisAddr); | |
29 | - config.useSingleServer().setDatabase(database); | |
30 | - if (StringUtils.isNotBlank(password)) { | |
31 | - config.useSingleServer().setPassword(password); | |
32 | - } | |
33 | - log.info("初始化Redisson单机配置,连接地址:" + address); | |
34 | - } catch (Exception e) { | |
35 | - log.error("单机Redisson初始化错误", e); | |
36 | - e.printStackTrace(); | |
37 | - } | |
38 | - return config; | |
39 | - } | |
40 | -} |
jeecg-boot/jeecg-boot-starter/jeecg-boot-starter-lock/src/main/java/org/jeecg/boot/starter/lock/enums/GlobalConstant.java deleted
jeecg-boot/jeecg-boot-starter/jeecg-boot-starter-lock/src/main/java/org/jeecg/boot/starter/lock/enums/LockModel.java deleted
1 | -package org.jeecg.boot.starter.lock.enums; | |
2 | - | |
3 | -/** | |
4 | - * 锁的模式 | |
5 | - * @author jeecg | |
6 | - */ | |
7 | -public enum LockModel { | |
8 | - //可重入锁 | |
9 | - REENTRANT, | |
10 | - //公平锁 | |
11 | - FAIR, | |
12 | - //联锁(可以把一组锁当作一个锁来加锁和释放) | |
13 | - MULTIPLE, | |
14 | - //红锁 | |
15 | - REDLOCK, | |
16 | - //读锁 | |
17 | - READ, | |
18 | - //写锁 | |
19 | - WRITE, | |
20 | - //自动模式,当参数只有一个.使用 REENTRANT 参数多个 REDLOCK | |
21 | - AUTO | |
22 | -} |
jeecg-boot/jeecg-boot-starter/jeecg-boot-starter-lock/src/main/java/org/jeecg/boot/starter/lock/enums/RedisConnectionType.java deleted
1 | -package org.jeecg.boot.starter.lock.enums; | |
2 | - | |
3 | -import lombok.AllArgsConstructor; | |
4 | -import lombok.Getter; | |
5 | - | |
6 | -/** | |
7 | - * Redis连接方式 | |
8 | - * @author zyf | |
9 | - * @date 2020-11-11 | |
10 | - */ | |
11 | -@Getter | |
12 | -@AllArgsConstructor | |
13 | -public enum RedisConnectionType { | |
14 | - /** | |
15 | - * 单机部署方式(默认) | |
16 | - */ | |
17 | - STANDALONE("standalone", "单机部署方式"), | |
18 | - /** | |
19 | - * 哨兵部署方式 | |
20 | - */ | |
21 | - SENTINEL("sentinel", "哨兵部署方式"), | |
22 | - /** | |
23 | - * 集群部署方式 | |
24 | - */ | |
25 | - CLUSTER("cluster", "集群方式"), | |
26 | - /** | |
27 | - * 主从部署方式 | |
28 | - */ | |
29 | - MASTERSLAVE("masterslave", "主从部署方式"); | |
30 | - | |
31 | - /** | |
32 | - * 编码 | |
33 | - */ | |
34 | - private final String code; | |
35 | - /** | |
36 | - * 名称 | |
37 | - */ | |
38 | - private final String name; | |
39 | -} |
jeecg-boot/jeecg-boot-starter/jeecg-boot-starter-lock/src/main/java/org/jeecg/boot/starter/lock/prop/RedissonProperties.java deleted
1 | -package org.jeecg.boot.starter.lock.prop; | |
2 | - | |
3 | -import lombok.Data; | |
4 | -import org.jeecg.boot.starter.lock.enums.RedisConnectionType; | |
5 | -import org.springframework.boot.context.properties.ConfigurationProperties; | |
6 | - | |
7 | -/** | |
8 | - * Redisson配置映射类 | |
9 | - * | |
10 | - * @author zyf | |
11 | - * @date 2020-11-11 | |
12 | - */ | |
13 | -@Data | |
14 | -@ConfigurationProperties(prefix = "jeecg.redisson") | |
15 | -public class RedissonProperties { | |
16 | - | |
17 | - /** | |
18 | - * redis主机地址,ip:port,多个用逗号(,)分隔 | |
19 | - */ | |
20 | - private String address; | |
21 | - /** | |
22 | - * 连接类型 | |
23 | - */ | |
24 | - private RedisConnectionType type; | |
25 | - /** | |
26 | - * 密码 | |
27 | - */ | |
28 | - private String password; | |
29 | - /** | |
30 | - * 数据库(默认0) | |
31 | - */ | |
32 | - private int database; | |
33 | - | |
34 | - /** | |
35 | - * 是否装配redisson配置 | |
36 | - */ | |
37 | - private Boolean enabled = true; | |
38 | - | |
39 | -} |
jeecg-boot/jeecg-boot-starter/jeecg-boot-starter-lock/src/main/resources/META-INF/spring.factories deleted
jeecg-boot/jeecg-boot-starter/jeecg-boot-starter-lock/src/test/java/org/jeecg/boot/starter/lock/test/LockService.java deleted
1 | -package org.jeecg.boot.starter.lock.test; | |
2 | - | |
3 | -import org.jeecg.boot.starter.lock.annotation.JLock; | |
4 | -import org.jeecg.boot.starter.lock.annotation.JRepeat; | |
5 | -import org.jeecg.boot.starter.lock.annotation.LockConstant; | |
6 | -import org.jeecg.boot.starter.lock.client.RedissonLockClient; | |
7 | -import org.springframework.stereotype.Service; | |
8 | - | |
9 | -import javax.annotation.Resource; | |
10 | - | |
11 | -@Service | |
12 | -public class LockService { | |
13 | - | |
14 | - @Resource | |
15 | - private RedissonLockClient redissonLockClient; | |
16 | - | |
17 | - int n = 10; | |
18 | - | |
19 | - /** | |
20 | - * 模拟秒杀(注解方式) | |
21 | - */ | |
22 | - @JLock(lockKey = "#productId", expireSeconds = 5000) | |
23 | - public void seckill(String productId) { | |
24 | - if (n <= 0) { | |
25 | - System.out.println("活动已结束,请下次再来"); | |
26 | - return; | |
27 | - } | |
28 | - System.out.println(Thread.currentThread().getName() + ":秒杀到了商品"); | |
29 | - System.out.println(--n); | |
30 | - } | |
31 | - | |
32 | - /** | |
33 | - * 模拟秒杀(编程方式) | |
34 | - */ | |
35 | - public void seckill2(String productId) { | |
36 | - redissonLockClient.tryLock(productId, 5000); | |
37 | - if (n <= 0) { | |
38 | - System.out.println("活动已结束,请下次再来"); | |
39 | - return; | |
40 | - } | |
41 | - System.out.println(Thread.currentThread().getName() + ":秒杀到了商品"); | |
42 | - System.out.println(--n); | |
43 | - redissonLockClient.unlock(productId); | |
44 | - } | |
45 | - | |
46 | - | |
47 | - /** | |
48 | - * 测试重复提交 | |
49 | - */ | |
50 | - @JRepeat(lockKey = "#name", lockTime = 5) | |
51 | - public void reSubmit(String name) { | |
52 | - try { | |
53 | - Thread.sleep(1500); | |
54 | - } catch (InterruptedException e) { | |
55 | - e.printStackTrace(); | |
56 | - } | |
57 | - System.out.println("提交成功" + name); | |
58 | - } | |
59 | -} |
jeecg-boot/jeecg-boot-starter/jeecg-boot-starter-lock/src/test/java/org/jeecg/boot/starter/lock/test/LockTest.java deleted
1 | -package org.jeecg.boot.starter.lock.test; | |
2 | - | |
3 | -import org.junit.Test; | |
4 | -import org.junit.runner.RunWith; | |
5 | -import org.springframework.beans.factory.annotation.Autowired; | |
6 | -import org.springframework.boot.test.context.SpringBootTest; | |
7 | -import org.springframework.test.context.junit4.SpringRunner; | |
8 | - | |
9 | -import java.util.concurrent.ExecutorService; | |
10 | -import java.util.concurrent.Executors; | |
11 | -import java.util.concurrent.TimeUnit; | |
12 | -import java.util.stream.IntStream; | |
13 | - | |
14 | -@RunWith(SpringRunner.class) | |
15 | -@SpringBootTest(classes = LockTestApplication.class) | |
16 | -public class LockTest { | |
17 | - @Autowired | |
18 | - LockService lockService; | |
19 | - | |
20 | - /** | |
21 | - * 测试分布式锁(模拟秒杀) | |
22 | - */ | |
23 | - @Test | |
24 | - public void test1() throws Exception { | |
25 | - ExecutorService executorService = Executors.newFixedThreadPool(6); | |
26 | - IntStream.range(0, 30).forEach(i -> executorService.submit(() -> { | |
27 | - try { | |
28 | - lockService.seckill("20120508784"); | |
29 | - } catch (Exception e) { | |
30 | - e.printStackTrace(); | |
31 | - } | |
32 | - })); | |
33 | - executorService.awaitTermination(30, TimeUnit.SECONDS); | |
34 | - } | |
35 | - | |
36 | - /** | |
37 | - * 测试分布式锁(模拟秒杀) | |
38 | - */ | |
39 | - @Test | |
40 | - public void test2() throws Exception { | |
41 | - ExecutorService executorService = Executors.newFixedThreadPool(6); | |
42 | - IntStream.range(0, 30).forEach(i -> executorService.submit(() -> { | |
43 | - try { | |
44 | - lockService.seckill2("20120508784"); | |
45 | - } catch (Exception e) { | |
46 | - e.printStackTrace(); | |
47 | - } | |
48 | - })); | |
49 | - executorService.awaitTermination(30, TimeUnit.SECONDS); | |
50 | - } | |
51 | - | |
52 | - /** | |
53 | - * 测试分布式锁(模拟重复提交) | |
54 | - */ | |
55 | - @Test | |
56 | - public void test3() throws Exception { | |
57 | - ExecutorService executorService = Executors.newFixedThreadPool(6); | |
58 | - IntStream.range(0, 20).forEach(i -> executorService.submit(() -> { | |
59 | - try { | |
60 | - lockService.reSubmit("test"); | |
61 | - } catch (Exception e) { | |
62 | - e.printStackTrace(); | |
63 | - } | |
64 | - })); | |
65 | - executorService.awaitTermination(30, TimeUnit.SECONDS); | |
66 | - } | |
67 | -} |
jeecg-boot/jeecg-boot-starter/jeecg-boot-starter-lock/src/test/java/org/jeecg/boot/starter/lock/test/LockTestApplication.java deleted
1 | -package org.jeecg.boot.starter.lock.test; | |
2 | - | |
3 | -import org.springframework.boot.SpringApplication; | |
4 | -import org.springframework.boot.autoconfigure.SpringBootApplication; | |
5 | -import org.springframework.context.annotation.EnableAspectJAutoProxy; | |
6 | - | |
7 | -@SpringBootApplication(scanBasePackages = "org.jeecg") | |
8 | -@EnableAspectJAutoProxy | |
9 | -public class LockTestApplication { | |
10 | - | |
11 | - public static void main(String[] args) { | |
12 | - SpringApplication.run(LockTestApplication.class, args); | |
13 | - } | |
14 | - | |
15 | -} | |
16 | 0 | \ No newline at end of file |
jeecg-boot/jeecg-boot-starter/jeecg-boot-starter-lock/src/test/java/org/jeecg/boot/starter/lock/test/TestUser.java deleted
jeecg-boot/jeecg-boot-starter/jeecg-boot-starter-lock/src/test/resources/application.yml deleted
1 | -spring: | |
2 | - redis: | |
3 | - database: 0 | |
4 | - host: 127.0.0.1 | |
5 | - lettuce: | |
6 | - pool: | |
7 | - max-active: 8 #最大连接数据库连接数,设 0 为没有限制 | |
8 | - max-idle: 8 #最大等待连接中的数量,设 0 为没有限制 | |
9 | - max-wait: -1ms #最大建立连接等待时间。如果超过此时间将接到异常。设为-1表示无限制。 | |
10 | - min-idle: 0 #最小等待连接中的数量,设 0 为没有限制 | |
11 | - shutdown-timeout: 100ms | |
12 | - password: jeecg | |
13 | - port: 6379 | |
14 | -jeecg : | |
15 | - redisson: | |
16 | - address: 127.0.0.1:6379 | |
17 | - password: jeecg | |
18 | - type: STANDALONE | |
19 | - enabled: true | |
20 | 0 | \ No newline at end of file |
jeecg-boot/jeecg-boot-starter/jeecg-boot-starter-rabbitmq/pom.xml deleted
1 | -<?xml version="1.0" encoding="UTF-8"?> | |
2 | -<project xmlns="http://maven.apache.org/POM/4.0.0" | |
3 | - xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | |
4 | - xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | |
5 | - <parent> | |
6 | - <artifactId>jeecg-boot-starter</artifactId> | |
7 | - <groupId>org.jeecgframework.boot</groupId> | |
8 | - <version>3.3.0</version> | |
9 | - </parent> | |
10 | - <modelVersion>4.0.0</modelVersion> | |
11 | - <artifactId>jeecg-boot-starter-rabbitmq</artifactId> | |
12 | - <description>jeecg-boot-starter-消息队列</description> | |
13 | - <dependencies> | |
14 | - <!-- 消息总线 rabbitmq --> | |
15 | - <dependency> | |
16 | - <groupId>org.springframework.cloud</groupId> | |
17 | - <artifactId>spring-cloud-starter-bus-amqp</artifactId> | |
18 | - </dependency> | |
19 | - </dependencies> | |
20 | - | |
21 | -</project> | |
22 | 0 | \ No newline at end of file |
jeecg-boot/jeecg-boot-starter/jeecg-boot-starter-rabbitmq/src/main/java/org/jeecg/boot/starter/rabbitmq/client/RabbitMqClient.java deleted
1 | -package org.jeecg.boot.starter.rabbitmq.client; | |
2 | - | |
3 | - | |
4 | -import cn.hutool.core.util.ObjectUtil; | |
5 | -import lombok.extern.slf4j.Slf4j; | |
6 | -import org.jeecg.boot.starter.rabbitmq.event.EventObj; | |
7 | -import org.jeecg.boot.starter.rabbitmq.event.JeecgRemoteApplicationEvent; | |
8 | -import org.jeecg.boot.starter.rabbitmq.exchange.DelayExchangeBuilder; | |
9 | -import org.jeecg.common.annotation.RabbitComponent; | |
10 | -import org.jeecg.common.base.BaseMap; | |
11 | -import org.slf4j.Logger; | |
12 | -import org.slf4j.LoggerFactory; | |
13 | -import org.springframework.amqp.core.*; | |
14 | -import org.springframework.amqp.rabbit.annotation.RabbitListener; | |
15 | -import org.springframework.amqp.rabbit.core.RabbitAdmin; | |
16 | -import org.springframework.amqp.rabbit.core.RabbitTemplate; | |
17 | -import org.springframework.amqp.rabbit.listener.SimpleMessageListenerContainer; | |
18 | -import org.springframework.beans.factory.annotation.Autowired; | |
19 | -import org.springframework.cloud.bus.BusProperties; | |
20 | -import org.springframework.context.ApplicationContext; | |
21 | -import org.springframework.context.ApplicationEventPublisher; | |
22 | -import org.springframework.context.annotation.Bean; | |
23 | -import org.springframework.context.annotation.Configuration; | |
24 | - | |
25 | -import javax.annotation.Resource; | |
26 | -import java.lang.reflect.Method; | |
27 | -import java.text.SimpleDateFormat; | |
28 | -import java.util.Date; | |
29 | -import java.util.HashMap; | |
30 | -import java.util.Map; | |
31 | -import java.util.Properties; | |
32 | - | |
33 | -/** | |
34 | - * 消息队列客户端 | |
35 | - */ | |
36 | -@Slf4j | |
37 | -@Configuration | |
38 | -public class RabbitMqClient { | |
39 | - | |
40 | - private static final Logger logger = LoggerFactory.getLogger(RabbitMqClient.class); | |
41 | - | |
42 | - private final RabbitAdmin rabbitAdmin; | |
43 | - | |
44 | - private final RabbitTemplate rabbitTemplate; | |
45 | - | |
46 | - | |
47 | - @Resource | |
48 | - private SimpleMessageListenerContainer messageListenerContainer; | |
49 | - | |
50 | - @Resource | |
51 | - BusProperties busProperties; | |
52 | - @Resource | |
53 | - private ApplicationEventPublisher publisher; | |
54 | - | |
55 | - | |
56 | - @Resource | |
57 | - private ApplicationContext applicationContext; | |
58 | - | |
59 | - | |
60 | - @Bean | |
61 | - public void initQueue() { | |
62 | - Map<String, Object> beansWithRqbbitComponentMap = this.applicationContext.getBeansWithAnnotation(RabbitComponent.class); | |
63 | - Class<? extends Object> clazz = null; | |
64 | - for (Map.Entry<String, Object> entry : beansWithRqbbitComponentMap.entrySet()) { | |
65 | - log.info("初始化队列............"); | |
66 | - //获取到实例对象的class信息 | |
67 | - clazz = entry.getValue().getClass(); | |
68 | - Method[] methods = clazz.getMethods(); | |
69 | - RabbitListener rabbitListener = clazz.getAnnotation(RabbitListener.class); | |
70 | - if (ObjectUtil.isNotEmpty(rabbitListener)) { | |
71 | - createQueue(rabbitListener); | |
72 | - } | |
73 | - for (Method method : methods) { | |
74 | - RabbitListener methodRabbitListener = method.getAnnotation(RabbitListener.class); | |
75 | - if (ObjectUtil.isNotEmpty(methodRabbitListener)) { | |
76 | - createQueue(methodRabbitListener); | |
77 | - } | |
78 | - } | |
79 | - | |
80 | - } | |
81 | - } | |
82 | - | |
83 | - /** | |
84 | - * 初始化队列 | |
85 | - * | |
86 | - * @param rabbitListener | |
87 | - */ | |
88 | - private void createQueue(RabbitListener rabbitListener) { | |
89 | - String[] queues = rabbitListener.queues(); | |
90 | - DirectExchange directExchange = createExchange(DelayExchangeBuilder.DELAY_EXCHANGE); | |
91 | - //创建交换机 | |
92 | - rabbitAdmin.declareExchange(directExchange); | |
93 | - if (ObjectUtil.isNotEmpty(queues)) { | |
94 | - for (String queueName : queues) { | |
95 | - Properties result = rabbitAdmin.getQueueProperties(queueName); | |
96 | - if (ObjectUtil.isEmpty(result)) { | |
97 | - Queue queue = new Queue(queueName); | |
98 | - addQueue(queue); | |
99 | - Binding binding = BindingBuilder.bind(queue).to(directExchange).with(queueName); | |
100 | - rabbitAdmin.declareBinding(binding); | |
101 | - log.info("创建队列:" + queueName); | |
102 | - }else{ | |
103 | - log.info("已有队列:" + queueName); | |
104 | - } | |
105 | - } | |
106 | - } | |
107 | - } | |
108 | - | |
109 | - | |
110 | - private Map sentObj = new HashMap<>(); | |
111 | - | |
112 | - | |
113 | - @Autowired | |
114 | - public RabbitMqClient(RabbitAdmin rabbitAdmin, RabbitTemplate rabbitTemplate) { | |
115 | - this.rabbitAdmin = rabbitAdmin; | |
116 | - this.rabbitTemplate = rabbitTemplate; | |
117 | - } | |
118 | - | |
119 | - | |
120 | - /** | |
121 | - * 发送远程事件 | |
122 | - * | |
123 | - * @param handlerName | |
124 | - * @param baseMap | |
125 | - */ | |
126 | - public void publishEvent(String handlerName, BaseMap baseMap) { | |
127 | - EventObj eventObj = new EventObj(); | |
128 | - eventObj.setHandlerName(handlerName); | |
129 | - eventObj.setBaseMap(baseMap); | |
130 | - publisher.publishEvent(new JeecgRemoteApplicationEvent(eventObj, busProperties.getId())); | |
131 | - } | |
132 | - | |
133 | - /** | |
134 | - * 转换Message对象 | |
135 | - * | |
136 | - * @param messageType 返回消息类型 MessageProperties类中常量 | |
137 | - * @param msg | |
138 | - * @return | |
139 | - */ | |
140 | - public Message getMessage(String messageType, Object msg) { | |
141 | - MessageProperties messageProperties = new MessageProperties(); | |
142 | - messageProperties.setContentType(messageType); | |
143 | - Message message = new Message(msg.toString().getBytes(), messageProperties); | |
144 | - return message; | |
145 | - } | |
146 | - | |
147 | - /** | |
148 | - * 有绑定Key的Exchange发送 | |
149 | - * | |
150 | - * @param routingKey | |
151 | - * @param msg | |
152 | - */ | |
153 | - public void sendMessageToExchange(TopicExchange topicExchange, String routingKey, Object msg) { | |
154 | - Message message = getMessage(MessageProperties.CONTENT_TYPE_JSON, msg); | |
155 | - rabbitTemplate.send(topicExchange.getName(), routingKey, message); | |
156 | - } | |
157 | - | |
158 | - /** | |
159 | - * 没有绑定KEY的Exchange发送 | |
160 | - * | |
161 | - * @param exchange | |
162 | - * @param msg | |
163 | - */ | |
164 | - public void sendMessageToExchange(TopicExchange topicExchange, AbstractExchange exchange, String msg) { | |
165 | - addExchange(exchange); | |
166 | - logger.info("RabbitMQ send " + exchange.getName() + "->" + msg); | |
167 | - rabbitTemplate.convertAndSend(topicExchange.getName(), msg); | |
168 | - } | |
169 | - | |
170 | - | |
171 | - /** | |
172 | - * 发送消息 | |
173 | - * | |
174 | - * @param queueName 队列名称 | |
175 | - * @param params 消息内容map | |
176 | - */ | |
177 | - public void sendMessage(String queueName, Object params) { | |
178 | - log.info("发送消息到mq"); | |
179 | - try { | |
180 | - rabbitTemplate.convertAndSend(DelayExchangeBuilder.DELAY_EXCHANGE, queueName, params, message -> { | |
181 | - return message; | |
182 | - }); | |
183 | - } catch (Exception e) { | |
184 | - e.printStackTrace(); | |
185 | - } | |
186 | - } | |
187 | - | |
188 | - /** | |
189 | - * 发送消息 | |
190 | - * | |
191 | - * @param queueName 队列名称 | |
192 | - */ | |
193 | - public void sendMessage(String queueName) { | |
194 | - this.send(queueName, this.sentObj, 0); | |
195 | - this.sentObj.clear(); | |
196 | - } | |
197 | - | |
198 | - | |
199 | - public RabbitMqClient put(String key, Object value) { | |
200 | - this.sentObj.put(key, value); | |
201 | - return this; | |
202 | - } | |
203 | - | |
204 | - /** | |
205 | - * 延迟发送消息 | |
206 | - * | |
207 | - * @param queueName 队列名称 | |
208 | - * @param params 消息内容params | |
209 | - * @param expiration 延迟时间 单位毫秒 | |
210 | - */ | |
211 | - public void sendMessage(String queueName, Object params, Integer expiration) { | |
212 | - this.send(queueName, params, expiration); | |
213 | - } | |
214 | - | |
215 | - private void send(String queueName, Object params, Integer expiration) { | |
216 | - Queue queue = new Queue(queueName); | |
217 | - addQueue(queue); | |
218 | - CustomExchange customExchange = DelayExchangeBuilder.buildExchange(); | |
219 | - rabbitAdmin.declareExchange(customExchange); | |
220 | - Binding binding = BindingBuilder.bind(queue).to(customExchange).with(queueName).noargs(); | |
221 | - rabbitAdmin.declareBinding(binding); | |
222 | - SimpleDateFormat sf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); | |
223 | - log.debug("发送时间:" + sf.format(new Date())); | |
224 | - rabbitTemplate.convertAndSend(DelayExchangeBuilder.DEFAULT_DELAY_EXCHANGE, queueName, params, message -> { | |
225 | - if (expiration != null && expiration > 0) { | |
226 | - message.getMessageProperties().setHeader("x-delay", expiration); | |
227 | - } | |
228 | - return message; | |
229 | - }); | |
230 | - } | |
231 | - | |
232 | - | |
233 | - /** | |
234 | - * 给queue发送消息 | |
235 | - * | |
236 | - * @param queueName | |
237 | - */ | |
238 | - public String receiveFromQueue(String queueName) { | |
239 | - return receiveFromQueue(DirectExchange.DEFAULT, queueName); | |
240 | - } | |
241 | - | |
242 | - /** | |
243 | - * 给direct交换机指定queue发送消息 | |
244 | - * | |
245 | - * @param directExchange | |
246 | - * @param queueName | |
247 | - */ | |
248 | - public String receiveFromQueue(DirectExchange directExchange, String queueName) { | |
249 | - Queue queue = new Queue(queueName); | |
250 | - addQueue(queue); | |
251 | - Binding binding = BindingBuilder.bind(queue).to(directExchange).withQueueName(); | |
252 | - rabbitAdmin.declareBinding(binding); | |
253 | - String messages = (String) rabbitTemplate.receiveAndConvert(queueName); | |
254 | - System.out.println("Receive:" + messages); | |
255 | - return messages; | |
256 | - } | |
257 | - | |
258 | - /** | |
259 | - * 创建Exchange | |
260 | - * | |
261 | - * @param exchange | |
262 | - */ | |
263 | - public void addExchange(AbstractExchange exchange) { | |
264 | - rabbitAdmin.declareExchange(exchange); | |
265 | - } | |
266 | - | |
267 | - /** | |
268 | - * 删除一个Exchange | |
269 | - * | |
270 | - * @param exchangeName | |
271 | - */ | |
272 | - public boolean deleteExchange(String exchangeName) { | |
273 | - return rabbitAdmin.deleteExchange(exchangeName); | |
274 | - } | |
275 | - | |
276 | - | |
277 | - /** | |
278 | - * 声明其名称自动命名的队列。它是用exclusive=true、autoDelete=true和 durable = false | |
279 | - * | |
280 | - * @return Queue | |
281 | - */ | |
282 | - public Queue addQueue() { | |
283 | - return rabbitAdmin.declareQueue(); | |
284 | - } | |
285 | - | |
286 | - /** | |
287 | - * 创建一个指定的Queue | |
288 | - * | |
289 | - * @param queue | |
290 | - * @return queueName | |
291 | - */ | |
292 | - public String addQueue(Queue queue) { | |
293 | - return rabbitAdmin.declareQueue(queue); | |
294 | - } | |
295 | - | |
296 | - /** | |
297 | - * 删除一个队列 | |
298 | - * | |
299 | - * @param queueName the name of the queue. | |
300 | - * @param unused true if the queue should be deleted only if not in use. | |
301 | - * @param empty true if the queue should be deleted only if empty. | |
302 | - */ | |
303 | - public void deleteQueue(String queueName, boolean unused, boolean empty) { | |
304 | - rabbitAdmin.deleteQueue(queueName, unused, empty); | |
305 | - } | |
306 | - | |
307 | - /** | |
308 | - * 删除一个队列 | |
309 | - * | |
310 | - * @param queueName | |
311 | - * @return true if the queue existed and was deleted. | |
312 | - */ | |
313 | - public boolean deleteQueue(String queueName) { | |
314 | - return rabbitAdmin.deleteQueue(queueName); | |
315 | - } | |
316 | - | |
317 | - /** | |
318 | - * 绑定一个队列到一个匹配型交换器使用一个routingKey | |
319 | - * | |
320 | - * @param queue | |
321 | - * @param exchange | |
322 | - * @param routingKey | |
323 | - */ | |
324 | - public void addBinding(Queue queue, TopicExchange exchange, String routingKey) { | |
325 | - Binding binding = BindingBuilder.bind(queue).to(exchange).with(routingKey); | |
326 | - rabbitAdmin.declareBinding(binding); | |
327 | - } | |
328 | - | |
329 | - /** | |
330 | - * 绑定一个Exchange到一个匹配型Exchange 使用一个routingKey | |
331 | - * | |
332 | - * @param exchange | |
333 | - * @param topicExchange | |
334 | - * @param routingKey | |
335 | - */ | |
336 | - public void addBinding(Exchange exchange, TopicExchange topicExchange, String routingKey) { | |
337 | - Binding binding = BindingBuilder.bind(exchange).to(topicExchange).with(routingKey); | |
338 | - rabbitAdmin.declareBinding(binding); | |
339 | - } | |
340 | - | |
341 | - /** | |
342 | - * 去掉一个binding | |
343 | - * | |
344 | - * @param binding | |
345 | - */ | |
346 | - public void removeBinding(Binding binding) { | |
347 | - rabbitAdmin.removeBinding(binding); | |
348 | - } | |
349 | - | |
350 | - /** | |
351 | - * 创建交换器 | |
352 | - * | |
353 | - * @param exchangeName | |
354 | - * @return | |
355 | - */ | |
356 | - public DirectExchange createExchange(String exchangeName) { | |
357 | - return new DirectExchange(exchangeName, true, false); | |
358 | - } | |
359 | -} |
jeecg-boot/jeecg-boot-starter/jeecg-boot-starter-rabbitmq/src/main/java/org/jeecg/boot/starter/rabbitmq/config/RabbitMqConfig.java deleted
1 | -package org.jeecg.boot.starter.rabbitmq.config; | |
2 | - | |
3 | - | |
4 | -import java.util.UUID; | |
5 | - | |
6 | -import org.jeecg.boot.starter.rabbitmq.event.JeecgRemoteApplicationEvent; | |
7 | -import org.jeecg.common.config.mqtoken.TransmitUserTokenFilter; | |
8 | -import org.springframework.amqp.core.AcknowledgeMode; | |
9 | -import org.springframework.amqp.rabbit.connection.ConnectionFactory; | |
10 | -import org.springframework.amqp.rabbit.core.RabbitAdmin; | |
11 | -import org.springframework.amqp.rabbit.listener.SimpleMessageListenerContainer; | |
12 | -import org.springframework.amqp.support.ConsumerTagStrategy; | |
13 | -import org.springframework.cloud.bus.jackson.RemoteApplicationEventScan; | |
14 | -import org.springframework.context.annotation.Bean; | |
15 | -import org.springframework.context.annotation.Configuration; | |
16 | - | |
17 | -/** | |
18 | - * 消息队列配置类 | |
19 | - * | |
20 | - * @author zyf | |
21 | - */ | |
22 | -@Configuration | |
23 | -@RemoteApplicationEventScan(basePackageClasses = JeecgRemoteApplicationEvent.class) | |
24 | -public class RabbitMqConfig { | |
25 | - | |
26 | - | |
27 | - @Bean | |
28 | - public RabbitAdmin rabbitAdmin(ConnectionFactory connectionFactory) { | |
29 | - RabbitAdmin rabbitAdmin = new RabbitAdmin(connectionFactory); | |
30 | - //设置忽略声明异常 | |
31 | - rabbitAdmin.setIgnoreDeclarationExceptions(true); | |
32 | - return rabbitAdmin; | |
33 | - } | |
34 | - | |
35 | - /** | |
36 | - * 注入获取token过滤器 | |
37 | - * @return | |
38 | - */ | |
39 | - @Bean | |
40 | - public TransmitUserTokenFilter transmitUserInfoFromHttpHeader(){ | |
41 | - return new TransmitUserTokenFilter(); | |
42 | - } | |
43 | - | |
44 | - @Bean | |
45 | - public SimpleMessageListenerContainer messageListenerContainer(ConnectionFactory connectionFactory) { | |
46 | - SimpleMessageListenerContainer container = new SimpleMessageListenerContainer(); | |
47 | - container.setConnectionFactory(connectionFactory); | |
48 | - //手动确认 | |
49 | - container.setAcknowledgeMode(AcknowledgeMode.MANUAL); | |
50 | - //当前的消费者数量 | |
51 | - container.setConcurrentConsumers(1); | |
52 | - //最大的消费者数量 | |
53 | - container.setMaxConcurrentConsumers(1); | |
54 | - //是否重回队列 | |
55 | - container.setDefaultRequeueRejected(true); | |
56 | - | |
57 | - //消费端的标签策略 | |
58 | - container.setConsumerTagStrategy(new ConsumerTagStrategy() { | |
59 | - @Override | |
60 | - public String createConsumerTag(String queue) { | |
61 | - return queue + "_" + UUID.randomUUID().toString(); | |
62 | - } | |
63 | - }); | |
64 | - return container; | |
65 | - } | |
66 | - | |
67 | -} |
jeecg-boot/jeecg-boot-starter/jeecg-boot-starter-rabbitmq/src/main/java/org/jeecg/boot/starter/rabbitmq/core/BaseRabbiMqHandler.java deleted
1 | -package org.jeecg.boot.starter.rabbitmq.core; | |
2 | - | |
3 | -import com.rabbitmq.client.Channel; | |
4 | -import lombok.extern.slf4j.Slf4j; | |
5 | - | |
6 | -import org.jeecg.boot.starter.rabbitmq.listenter.MqListener; | |
7 | -import org.jeecg.common.config.mqtoken.UserTokenContext; | |
8 | - | |
9 | -import java.io.IOException; | |
10 | - | |
11 | -/** | |
12 | - * | |
13 | - * @author zyf | |
14 | - */ | |
15 | -@Slf4j | |
16 | -public class BaseRabbiMqHandler<T> { | |
17 | - | |
18 | - private String token= UserTokenContext.getToken(); | |
19 | - | |
20 | - public void onMessage(T t, Long deliveryTag, Channel channel, MqListener mqListener) { | |
21 | - try { | |
22 | - UserTokenContext.setToken(token); | |
23 | - mqListener.handler(t, channel); | |
24 | - channel.basicAck(deliveryTag, false); | |
25 | - } catch (Exception e) { | |
26 | - log.info("接收消息失败,重新放回队列"); | |
27 | - try { | |
28 | - /** | |
29 | - * deliveryTag:该消息的index | |
30 | - * multiple:是否批量.true:将一次性拒绝所有小于deliveryTag的消息。 | |
31 | - * requeue:被拒绝的是否重新入队列 | |
32 | - */ | |
33 | - channel.basicNack(deliveryTag, false, true); | |
34 | - } catch (IOException ex) { | |
35 | - ex.printStackTrace(); | |
36 | - } | |
37 | - } | |
38 | - | |
39 | - } | |
40 | -} |
jeecg-boot/jeecg-boot-starter/jeecg-boot-starter-rabbitmq/src/main/java/org/jeecg/boot/starter/rabbitmq/core/MapMessageConverter.java deleted
1 | -package org.jeecg.boot.starter.rabbitmq.core; | |
2 | - | |
3 | -import org.springframework.amqp.core.Message; | |
4 | -import org.springframework.amqp.core.MessageProperties; | |
5 | -import org.springframework.amqp.support.converter.MessageConversionException; | |
6 | -import org.springframework.amqp.support.converter.MessageConverter; | |
7 | - | |
8 | -import java.io.ByteArrayInputStream; | |
9 | -import java.io.ObjectInputStream; | |
10 | -import java.util.HashMap; | |
11 | -import java.util.Map; | |
12 | - | |
13 | -public class MapMessageConverter implements MessageConverter { | |
14 | - @Override | |
15 | - public Message toMessage(Object object, MessageProperties messageProperties) throws MessageConversionException { | |
16 | - return new Message(object.toString().getBytes(), messageProperties); | |
17 | - } | |
18 | - | |
19 | - @Override | |
20 | - public Object fromMessage(Message message) throws MessageConversionException { | |
21 | - String contentType = message.getMessageProperties().getContentType(); | |
22 | - if (null != contentType && contentType.contains("text")) { | |
23 | - return new String(message.getBody()); | |
24 | - } else { | |
25 | - ObjectInputStream objInt = null; | |
26 | - try { | |
27 | - ByteArrayInputStream byteInt = new ByteArrayInputStream(message.getBody()); | |
28 | - objInt = new ObjectInputStream(byteInt); | |
29 | - //byte[]转map | |
30 | - Map map = (HashMap) objInt.readObject(); | |
31 | - return map; | |
32 | - } catch (Exception e) { | |
33 | - e.printStackTrace(); | |
34 | - } | |
35 | - } | |
36 | - return null; | |
37 | - | |
38 | - } | |
39 | -} |
jeecg-boot/jeecg-boot-starter/jeecg-boot-starter-rabbitmq/src/main/java/org/jeecg/boot/starter/rabbitmq/event/BaseApplicationEvent.java deleted
1 | -package org.jeecg.boot.starter.rabbitmq.event; | |
2 | - | |
3 | -import cn.hutool.core.util.ObjectUtil; | |
4 | - | |
5 | -import org.jeecg.common.util.SpringContextHolder; | |
6 | -import org.springframework.context.ApplicationListener; | |
7 | -import org.springframework.stereotype.Component; | |
8 | - | |
9 | -/** | |
10 | - * 监听远程事件,并分发消息到业务模块消息处理器 | |
11 | - */ | |
12 | -@Component | |
13 | -public class BaseApplicationEvent implements ApplicationListener<JeecgRemoteApplicationEvent> { | |
14 | - | |
15 | - @Override | |
16 | - public void onApplicationEvent(JeecgRemoteApplicationEvent jeecgRemoteApplicationEvent) { | |
17 | - EventObj eventObj = jeecgRemoteApplicationEvent.getEventObj(); | |
18 | - if (ObjectUtil.isNotEmpty(eventObj)) { | |
19 | - //获取业务模块消息处理器 | |
20 | - JeecgBusEventHandler busEventHandler = SpringContextHolder.getHandler(eventObj.getHandlerName(), JeecgBusEventHandler.class); | |
21 | - if (ObjectUtil.isNotEmpty(busEventHandler)) { | |
22 | - //通知业务模块 | |
23 | - busEventHandler.onMessage(eventObj); | |
24 | - } | |
25 | - } | |
26 | - } | |
27 | - | |
28 | -} |
jeecg-boot/jeecg-boot-starter/jeecg-boot-starter-rabbitmq/src/main/java/org/jeecg/boot/starter/rabbitmq/event/EventObj.java deleted
1 | -package org.jeecg.boot.starter.rabbitmq.event; | |
2 | - | |
3 | -import lombok.Data; | |
4 | -import org.jeecg.common.base.BaseMap; | |
5 | - | |
6 | -import java.io.Serializable; | |
7 | - | |
8 | -/** | |
9 | - * 远程事件数据对象 | |
10 | - */ | |
11 | -@Data | |
12 | -public class EventObj implements Serializable { | |
13 | - /** | |
14 | - * 数据对象 | |
15 | - */ | |
16 | - private BaseMap baseMap; | |
17 | - /** | |
18 | - * 自定义业务模块消息处理器beanName | |
19 | - */ | |
20 | - private String handlerName; | |
21 | -} |
jeecg-boot/jeecg-boot-starter/jeecg-boot-starter-rabbitmq/src/main/java/org/jeecg/boot/starter/rabbitmq/event/JeecgBusEventHandler.java deleted
jeecg-boot/jeecg-boot-starter/jeecg-boot-starter-rabbitmq/src/main/java/org/jeecg/boot/starter/rabbitmq/event/JeecgRemoteApplicationEvent.java deleted
1 | -package org.jeecg.boot.starter.rabbitmq.event; | |
2 | - | |
3 | -import lombok.Data; | |
4 | -import org.springframework.cloud.bus.event.RemoteApplicationEvent; | |
5 | - | |
6 | -/** | |
7 | - * 自定义网关刷新远程事件 | |
8 | - * | |
9 | - * @author : zyf | |
10 | - * @date :2020-11-10 | |
11 | - */ | |
12 | -@Data | |
13 | -public class JeecgRemoteApplicationEvent extends RemoteApplicationEvent { | |
14 | - | |
15 | - private JeecgRemoteApplicationEvent() { | |
16 | - } | |
17 | - | |
18 | - private EventObj eventObj; | |
19 | - | |
20 | - public JeecgRemoteApplicationEvent(EventObj source, String originService, String destinationService) { | |
21 | - super(source, originService, destinationService); | |
22 | - this.eventObj = source; | |
23 | - } | |
24 | - | |
25 | - public JeecgRemoteApplicationEvent(EventObj source, String originService) { | |
26 | - super(source, originService, ""); | |
27 | - this.eventObj = source; | |
28 | - } | |
29 | -} |
jeecg-boot/jeecg-boot-starter/jeecg-boot-starter-rabbitmq/src/main/java/org/jeecg/boot/starter/rabbitmq/exchange/DelayExchangeBuilder.java deleted
1 | -package org.jeecg.boot.starter.rabbitmq.exchange; | |
2 | - | |
3 | -import org.springframework.amqp.core.CustomExchange; | |
4 | - | |
5 | -import java.util.HashMap; | |
6 | -import java.util.Map; | |
7 | - | |
8 | -/** | |
9 | - * 延迟交换器构造器 | |
10 | - * @author: zyf | |
11 | - * @date: 2019/3/8 13:31 | |
12 | - * @description: | |
13 | - */ | |
14 | -public class DelayExchangeBuilder { | |
15 | - /** | |
16 | - * 默认延迟消息交换器 | |
17 | - */ | |
18 | - public final static String DEFAULT_DELAY_EXCHANGE = "jeecg.delayed.exchange"; | |
19 | - /** | |
20 | - * 普通交换器 | |
21 | - */ | |
22 | - public final static String DELAY_EXCHANGE = "jeecg.direct.exchange"; | |
23 | - | |
24 | - /** | |
25 | - * 构建延迟消息交换器 | |
26 | - * @return | |
27 | - */ | |
28 | - public static CustomExchange buildExchange() { | |
29 | - Map<String, Object> args = new HashMap<String, Object>(); | |
30 | - args.put("x-delayed-type", "direct"); | |
31 | - return new CustomExchange(DEFAULT_DELAY_EXCHANGE, "x-delayed-message", true, false, args); | |
32 | - } | |
33 | -} |
jeecg-boot/jeecg-boot-starter/jeecg-boot-starter-rabbitmq/src/main/java/org/jeecg/boot/starter/rabbitmq/listenter/MqListener.java deleted
jeecg-boot/jeecg-boot-starter/jeecg-boot-starter-seata/pom.xml deleted
1 | -<?xml version="1.0" encoding="UTF-8"?> | |
2 | -<project xmlns="http://maven.apache.org/POM/4.0.0" | |
3 | - xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | |
4 | - xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | |
5 | - <parent> | |
6 | - <artifactId>jeecg-boot-starter</artifactId> | |
7 | - <groupId>org.jeecgframework.boot</groupId> | |
8 | - <version>3.3.0</version> | |
9 | - </parent> | |
10 | - <modelVersion>4.0.0</modelVersion> | |
11 | - <artifactId>jeecg-boot-starter-seata</artifactId> | |
12 | - <description>分布式事务</description> | |
13 | - <dependencies> | |
14 | - <!-- seata依赖 --> | |
15 | - <dependency> | |
16 | - <groupId>io.seata</groupId> | |
17 | - <artifactId>seata-spring-boot-starter</artifactId> | |
18 | - <version>1.4.2</version> | |
19 | - </dependency> | |
20 | - <dependency> | |
21 | - <groupId>com.alibaba.nacos</groupId> | |
22 | - <artifactId>nacos-client</artifactId> | |
23 | - <version>1.3.3</version> | |
24 | - </dependency> | |
25 | - | |
26 | - </dependencies> | |
27 | -</project> | |
28 | 0 | \ No newline at end of file |
jeecg-boot/jeecg-boot-starter/jeecg-boot-starter-shardingsphere/pom.xml deleted
1 | -<?xml version="1.0" encoding="UTF-8"?> | |
2 | -<project xmlns="http://maven.apache.org/POM/4.0.0" | |
3 | - xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | |
4 | - xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | |
5 | - <parent> | |
6 | - <artifactId>jeecg-boot-starter</artifactId> | |
7 | - <groupId>org.jeecgframework.boot</groupId> | |
8 | - <version>3.3.0</version> | |
9 | - </parent> | |
10 | - <modelVersion>4.0.0</modelVersion> | |
11 | - <artifactId>jeecg-boot-starter-shardingsphere</artifactId> | |
12 | - <description>分库分表</description> | |
13 | - <dependencies> | |
14 | - <!-- 动态数据源 --> | |
15 | - <dependency> | |
16 | - <groupId>com.baomidou</groupId> | |
17 | - <artifactId>dynamic-datasource-spring-boot-starter</artifactId> | |
18 | - <version>${dynamic-datasource-spring-boot-starter.version}</version> | |
19 | - </dependency> | |
20 | - <!-- 分库分表 --> | |
21 | - <dependency> | |
22 | - <groupId>org.apache.shardingsphere</groupId> | |
23 | - <artifactId>shardingsphere-jdbc-core-spring-boot-starter</artifactId> | |
24 | - <version>5.0.0</version> | |
25 | - </dependency> | |
26 | - </dependencies> | |
27 | - | |
28 | -</project> | |
29 | 0 | \ No newline at end of file |
jeecg-boot/jeecg-boot-starter/jeecg-boot-starter-shardingsphere/src/main/java/org/jeecg/boot/shardingsphere/config/DataSourceConfiguration.java deleted
1 | -package org.jeecg.boot.shardingsphere.config; | |
2 | - | |
3 | -import com.baomidou.dynamic.datasource.DynamicRoutingDataSource; | |
4 | -import com.baomidou.dynamic.datasource.provider.AbstractDataSourceProvider; | |
5 | -import com.baomidou.dynamic.datasource.provider.DynamicDataSourceProvider; | |
6 | -import com.baomidou.dynamic.datasource.spring.boot.autoconfigure.DataSourceProperty; | |
7 | -import com.baomidou.dynamic.datasource.spring.boot.autoconfigure.DynamicDataSourceAutoConfiguration; | |
8 | -import com.baomidou.dynamic.datasource.spring.boot.autoconfigure.DynamicDataSourceProperties; | |
9 | -import org.springframework.boot.SpringBootConfiguration; | |
10 | -import org.springframework.boot.autoconfigure.AutoConfigureBefore; | |
11 | -import org.springframework.context.annotation.Bean; | |
12 | -import org.springframework.context.annotation.Configuration; | |
13 | -import org.springframework.context.annotation.Lazy; | |
14 | -import org.springframework.context.annotation.Primary; | |
15 | - | |
16 | -import javax.annotation.Resource; | |
17 | -import javax.sql.DataSource; | |
18 | -import java.util.Map; | |
19 | - | |
20 | -/** | |
21 | - * 分库分表数据源配置 | |
22 | - * @author zyf | |
23 | - */ | |
24 | -@Configuration | |
25 | -@AutoConfigureBefore({DynamicDataSourceAutoConfiguration.class, SpringBootConfiguration.class}) | |
26 | -public class DataSourceConfiguration { | |
27 | - /** | |
28 | - * 分表数据源名称 | |
29 | - */ | |
30 | - public static final String SHARDING_DATA_SOURCE_NAME = "sharding"; | |
31 | - /** | |
32 | - * 动态数据源配置项 | |
33 | - */ | |
34 | - @Resource | |
35 | - private DynamicDataSourceProperties dynamicDataSourceProperties; | |
36 | - | |
37 | - @Lazy | |
38 | - @Resource | |
39 | - DataSource shardingDataSource; | |
40 | - | |
41 | - /** | |
42 | - * 将shardingDataSource放到了多数据源(dataSourceMap)中 | |
43 | - * 注意有个版本的bug,3.1.1版本 不会进入loadDataSources 方法,这样就一直造成数据源注册失败 | |
44 | - */ | |
45 | - @Bean | |
46 | - public DynamicDataSourceProvider dynamicDataSourceProvider() { | |
47 | - Map<String, DataSourceProperty> datasourceMap = dynamicDataSourceProperties.getDatasource(); | |
48 | - return new AbstractDataSourceProvider() { | |
49 | - @Override | |
50 | - public Map<String, DataSource> loadDataSources() { | |
51 | - Map<String, DataSource> dataSourceMap = createDataSourceMap(datasourceMap); | |
52 | - // 将 shardingjdbc 管理的数据源也交给动态数据源管理 | |
53 | - dataSourceMap.put(SHARDING_DATA_SOURCE_NAME, shardingDataSource); | |
54 | - return dataSourceMap; | |
55 | - } | |
56 | - }; | |
57 | - } | |
58 | - | |
59 | - /** | |
60 | - * 将动态数据源设置为首选的 | |
61 | - * 当spring存在多个数据源时, 自动注入的是首选的对象 | |
62 | - * 设置为主要的数据源之后,就可以支持shardingjdbc原生的配置方式了 | |
63 | - * | |
64 | - * @return | |
65 | - */ | |
66 | - @Primary | |
67 | - @Bean | |
68 | - public DataSource dataSource(DynamicDataSourceProvider dynamicDataSourceProvider) { | |
69 | - DynamicRoutingDataSource dataSource = new DynamicRoutingDataSource(); | |
70 | - dataSource.setPrimary(dynamicDataSourceProperties.getPrimary()); | |
71 | - dataSource.setStrict(dynamicDataSourceProperties.getStrict()); | |
72 | - dataSource.setStrategy(dynamicDataSourceProperties.getStrategy()); | |
73 | - dataSource.setProvider(dynamicDataSourceProvider); | |
74 | - dataSource.setP6spy(dynamicDataSourceProperties.getP6spy()); | |
75 | - dataSource.setSeata(dynamicDataSourceProperties.getSeata()); | |
76 | - return dataSource; | |
77 | - } | |
78 | -} |
jeecg-boot/jeecg-boot-starter/jeecg-boot-starter-shardingsphere/src/main/resources/application.yml deleted
jeecg-boot/jeecg-boot-starter/pom.xml deleted
1 | -<project xmlns="http://maven.apache.org/POM/4.0.0" | |
2 | - xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | |
3 | - xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | |
4 | - <parent> | |
5 | - <groupId>org.jeecgframework.boot</groupId> | |
6 | - <artifactId>jeecg-boot-parent</artifactId> | |
7 | - <version>3.3.0</version> | |
8 | - </parent> | |
9 | - <modelVersion>4.0.0</modelVersion> | |
10 | - <artifactId>jeecg-boot-starter</artifactId> | |
11 | - <packaging>pom</packaging> | |
12 | - | |
13 | - <properties> | |
14 | - <java.version>1.8</java.version> | |
15 | - <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> | |
16 | - </properties> | |
17 | - | |
18 | - <modules> | |
19 | - <module>jeecg-boot-starter-cloud</module> | |
20 | - <module>jeecg-boot-starter-job</module> | |
21 | - <module>jeecg-boot-starter-lock</module> | |
22 | - <module>jeecg-boot-starter-rabbitmq</module> | |
23 | - <module>jeecg-boot-starter-shardingsphere</module> | |
24 | - <module>jeecg-boot-starter-seata</module> | |
25 | - </modules> | |
26 | - <dependencies> | |
27 | - <!--jeecg-tools--> | |
28 | - <dependency> | |
29 | - <groupId>org.jeecgframework.boot</groupId> | |
30 | - <artifactId>jeecg-boot-base-tools</artifactId> | |
31 | - </dependency> | |
32 | - <!--加载配置信息--> | |
33 | - <dependency> | |
34 | - <groupId>org.springframework.boot</groupId> | |
35 | - <artifactId>spring-boot-autoconfigure</artifactId> | |
36 | - </dependency> | |
37 | - <dependency> | |
38 | - <groupId>org.springframework.boot</groupId> | |
39 | - <artifactId>spring-boot-configuration-processor</artifactId> | |
40 | - <optional>true</optional> | |
41 | - </dependency> | |
42 | - </dependencies> | |
43 | - | |
44 | - | |
45 | - <build> | |
46 | - <plugins> | |
47 | - <plugin> | |
48 | - <artifactId>maven-compiler-plugin</artifactId> | |
49 | - <configuration> | |
50 | - <source>1.8</source> | |
51 | - <target>1.8</target> | |
52 | - <encoding>UTF-8</encoding> | |
53 | - </configuration> | |
54 | - </plugin> | |
55 | - </plugins> | |
56 | - </build> | |
57 | -</project> | |
58 | 0 | \ No newline at end of file |