Commit 5008ebdf22f4c2dfec7aced08b99a883fc6e408c
1 parent
5aab4c85
删除jeecg-cloud-example例子模块,测试示例重构到jeecg-cloud-system-start中
Showing
27 changed files
with
204 additions
and
526 deletions
jeecg-boot/jeecg-boot-module-demo/src/main/java/org/jeecg/modules/demo/cloud/controller/JcloudDemoController.java
0 → 100644
1 | +//package org.jeecg.modules.demo.cloud.controller; | |
2 | +// | |
3 | +//import io.swagger.annotations.Api; | |
4 | +//import io.swagger.annotations.ApiOperation; | |
5 | +//import lombok.extern.slf4j.Slf4j; | |
6 | +//import org.jeecg.common.api.vo.Result; | |
7 | +//import org.jeecg.common.system.api.ISysBaseAPI; | |
8 | +//import org.jeecg.common.system.vo.DictModel; | |
9 | +//import org.springframework.web.bind.annotation.GetMapping; | |
10 | +//import org.springframework.web.bind.annotation.RequestMapping; | |
11 | +//import org.springframework.web.bind.annotation.RestController; | |
12 | +// | |
13 | +//import javax.annotation.Resource; | |
14 | +//import java.util.List; | |
15 | +// | |
16 | +///** | |
17 | +// * | |
18 | +// */ | |
19 | +//@Slf4j | |
20 | +//@Api(tags = "Cloud示例") | |
21 | +//@RestController | |
22 | +//@RequestMapping("/test") | |
23 | +//public class JcloudDemoController { | |
24 | +// | |
25 | +// | |
26 | +// @Resource | |
27 | +// private ISysBaseAPI sysBaseAPI; | |
28 | +// | |
29 | +// /** | |
30 | +// * 测试 | |
31 | +// * | |
32 | +// * @return | |
33 | +// */ | |
34 | +// @GetMapping("/remote") | |
35 | +// @ApiOperation(value = "测试feign", notes = "测试feign") | |
36 | +// public Result remoteDict() { | |
37 | +//// try{ | |
38 | +//// //睡5秒,网关Hystrix3秒超时,会触发熔断降级操作 | |
39 | +//// Thread.sleep(5000); | |
40 | +//// }catch (Exception e){ | |
41 | +//// e.printStackTrace(); | |
42 | +//// } | |
43 | +// List<DictModel> list = sysBaseAPI.queryAllDict(); | |
44 | +// return Result.OK(list); | |
45 | +// } | |
46 | +// | |
47 | +// | |
48 | +//} | |
... | ... |
jeecg-boot/jeecg-cloud-module/jeecg-cloud-example/src/main/java/org/jeecg/cloud/demo/test/provider/JeecgDemoProvider.java renamed to jeecg-boot/jeecg-boot-module-demo/src/main/java/org/jeecg/modules/demo/cloud/provider/JcloudDemoProvider.java
1 | -package org.jeecg.cloud.demo.test.provider; | |
1 | +package org.jeecg.modules.demo.cloud.provider; | |
2 | 2 | |
3 | -import org.jeecg.cloud.demo.test.service.JeecgDemoService; | |
4 | 3 | import org.jeecg.common.api.vo.Result; |
4 | +import org.jeecg.modules.demo.cloud.service.JcloudDemoService; | |
5 | 5 | import org.springframework.web.bind.annotation.GetMapping; |
6 | 6 | import org.springframework.web.bind.annotation.RequestMapping; |
7 | 7 | import org.springframework.web.bind.annotation.RequestParam; |
... | ... | @@ -14,14 +14,14 @@ import javax.annotation.Resource; |
14 | 14 | */ |
15 | 15 | @RestController |
16 | 16 | @RequestMapping("/test") |
17 | -public class JeecgDemoProvider { | |
17 | +public class JcloudDemoProvider { | |
18 | 18 | |
19 | 19 | @Resource |
20 | - private JeecgDemoService jeecgDemoService; | |
20 | + private JcloudDemoService jcloudDemoService; | |
21 | 21 | |
22 | 22 | @GetMapping("/getMessage") |
23 | 23 | public Result<String> getMessage(@RequestParam String name) { |
24 | - return jeecgDemoService.getMessage(name); | |
24 | + return jcloudDemoService.getMessage(name); | |
25 | 25 | } |
26 | 26 | |
27 | 27 | } |
... | ... |
jeecg-boot/jeecg-cloud-module/jeecg-cloud-example/src/main/java/org/jeecg/cloud/demo/test/service/JeecgDemoService.java renamed to jeecg-boot/jeecg-boot-module-demo/src/main/java/org/jeecg/modules/demo/cloud/service/JcloudDemoService.java
jeecg-boot/jeecg-cloud-module/jeecg-cloud-example/src/main/java/org/jeecg/cloud/demo/test/service/impl/JeecgDemoServiceImpl.java renamed to jeecg-boot/jeecg-boot-module-demo/src/main/java/org/jeecg/modules/demo/cloud/service/impl/JcloudDemoServiceImpl.java
1 | -package org.jeecg.cloud.demo.test.service.impl; | |
1 | +package org.jeecg.modules.demo.cloud.service.impl; | |
2 | 2 | |
3 | -import org.jeecg.cloud.demo.test.service.JeecgDemoService; | |
4 | 3 | import org.jeecg.common.api.vo.Result; |
4 | +import org.jeecg.modules.demo.cloud.service.JcloudDemoService; | |
5 | 5 | import org.springframework.stereotype.Service; |
6 | 6 | |
7 | 7 | @Service |
8 | -public class JeecgDemoServiceImpl implements JeecgDemoService { | |
8 | +public class JcloudDemoServiceImpl implements JcloudDemoService { | |
9 | 9 | @Override |
10 | 10 | public Result<String> getMessage(String name) { |
11 | - return Result.OK("Hello" + name); | |
11 | + return Result.OK("Hello," + name); | |
12 | 12 | } |
13 | 13 | } |
... | ... |
jeecg-boot/jeecg-boot-module-demo/src/main/java/org/jeecg/modules/demo/handler/DemoJobHandler.java deleted
1 | -// | |
2 | -//package org.jeecg.modules.demo.handler; | |
3 | -// | |
4 | -// | |
5 | -//import com.xxl.job.core.biz.model.ReturnT; | |
6 | -//import com.xxl.job.core.handler.IJobHandler; | |
7 | -//import com.xxl.job.core.handler.annotation.XxlJob; | |
8 | -//import com.xxl.job.core.log.XxlJobLogger; | |
9 | -//import com.xxl.job.core.util.ShardingUtil; | |
10 | -//import lombok.extern.slf4j.Slf4j; | |
11 | -//import org.springframework.stereotype.Component; | |
12 | -// | |
13 | -//import java.io.BufferedInputStream; | |
14 | -//import java.io.BufferedReader; | |
15 | -//import java.io.DataOutputStream; | |
16 | -//import java.io.InputStreamReader; | |
17 | -//import java.net.HttpURLConnection; | |
18 | -//import java.net.URL; | |
19 | -//import java.util.Arrays; | |
20 | -// | |
21 | -// | |
22 | -///** | |
23 | -// * xxl-job定时任务测试 | |
24 | -// */ | |
25 | -//@Component | |
26 | -//@Slf4j | |
27 | -//public class DemoJobHandler { | |
28 | -// | |
29 | -// | |
30 | -// /** | |
31 | -// * 简单任务 | |
32 | -// * | |
33 | -// * @param params | |
34 | -// * @return | |
35 | -// */ | |
36 | -// | |
37 | -// @XxlJob(value = "demoJob") | |
38 | -// public ReturnT<String> demoJobHandler(String params) { | |
39 | -// log.info("我是定时任务,我执行了..............................."); | |
40 | -// return ReturnT.SUCCESS; | |
41 | -// } | |
42 | -// | |
43 | -// /** | |
44 | -// * 2、分片广播任务 | |
45 | -// */ | |
46 | -// | |
47 | -// @XxlJob("shardingJobHandler") | |
48 | -// public ReturnT<String> shardingJobHandler(String param) throws Exception { | |
49 | -// | |
50 | -// // 分片参数 | |
51 | -// ShardingUtil.ShardingVO shardingVO = ShardingUtil.getShardingVo(); | |
52 | -// XxlJobLogger.log("分片参数:当前分片序号 = {}, 总分片数 = {}", shardingVO.getIndex(), shardingVO.getTotal()); | |
53 | -// | |
54 | -// // 业务逻辑 | |
55 | -// for (int i = 0; i < shardingVO.getTotal(); i++) { | |
56 | -// if (i == shardingVO.getIndex()) { | |
57 | -// XxlJobLogger.log("第 {} 片, 命中分片开始处理", i); | |
58 | -// } else { | |
59 | -// XxlJobLogger.log("第 {} 片, 忽略", i); | |
60 | -// } | |
61 | -// } | |
62 | -// | |
63 | -// return ReturnT.SUCCESS; | |
64 | -// } | |
65 | -// | |
66 | -// | |
67 | -// /** | |
68 | -// * 3、命令行任务 | |
69 | -// */ | |
70 | -// | |
71 | -// @XxlJob("commandJobHandler") | |
72 | -// public ReturnT<String> commandJobHandler(String param) throws Exception { | |
73 | -// String command = param; | |
74 | -// int exitValue = -1; | |
75 | -// | |
76 | -// BufferedReader bufferedReader = null; | |
77 | -// try { | |
78 | -// // command process | |
79 | -// Process process = Runtime.getRuntime().exec(command); | |
80 | -// BufferedInputStream bufferedInputStream = new BufferedInputStream(process.getInputStream()); | |
81 | -// bufferedReader = new BufferedReader(new InputStreamReader(bufferedInputStream)); | |
82 | -// | |
83 | -// // command log | |
84 | -// String line; | |
85 | -// while ((line = bufferedReader.readLine()) != null) { | |
86 | -// XxlJobLogger.log(line); | |
87 | -// } | |
88 | -// | |
89 | -// // command exit | |
90 | -// process.waitFor(); | |
91 | -// exitValue = process.exitValue(); | |
92 | -// } catch (Exception e) { | |
93 | -// XxlJobLogger.log(e); | |
94 | -// } finally { | |
95 | -// if (bufferedReader != null) { | |
96 | -// bufferedReader.close(); | |
97 | -// } | |
98 | -// } | |
99 | -// | |
100 | -// if (exitValue == 0) { | |
101 | -// return IJobHandler.SUCCESS; | |
102 | -// } else { | |
103 | -// return new ReturnT<String>(IJobHandler.FAIL.getCode(), "command exit value(" + exitValue + ") is failed"); | |
104 | -// } | |
105 | -// } | |
106 | -// | |
107 | -// | |
108 | -// /** | |
109 | -// * 4、跨平台Http任务 | |
110 | -// * 参数示例: | |
111 | -// * "url: http://www.baidu.com\n" + | |
112 | -// * "method: get\n" + | |
113 | -// * "data: content\n"; | |
114 | -// */ | |
115 | -// | |
116 | -// @XxlJob("httpJobHandler") | |
117 | -// public ReturnT<String> httpJobHandler(String param) throws Exception { | |
118 | -// | |
119 | -// // param parse | |
120 | -// if (param == null || param.trim().length() == 0) { | |
121 | -// XxlJobLogger.log("param[" + param + "] invalid."); | |
122 | -// return ReturnT.FAIL; | |
123 | -// } | |
124 | -// String[] httpParams = param.split("\n"); | |
125 | -// String url = null; | |
126 | -// String method = null; | |
127 | -// String data = null; | |
128 | -// for (String httpParam : httpParams) { | |
129 | -// if (httpParam.startsWith("url:")) { | |
130 | -// url = httpParam.substring(httpParam.indexOf("url:") + 4).trim(); | |
131 | -// } | |
132 | -// if (httpParam.startsWith("method:")) { | |
133 | -// method = httpParam.substring(httpParam.indexOf("method:") + 7).trim().toUpperCase(); | |
134 | -// } | |
135 | -// if (httpParam.startsWith("data:")) { | |
136 | -// data = httpParam.substring(httpParam.indexOf("data:") + 5).trim(); | |
137 | -// } | |
138 | -// } | |
139 | -// | |
140 | -// // param valid | |
141 | -// if (url == null || url.trim().length() == 0) { | |
142 | -// XxlJobLogger.log("url[" + url + "] invalid."); | |
143 | -// return ReturnT.FAIL; | |
144 | -// } | |
145 | -// if (method == null || !Arrays.asList("GET", "POST").contains(method)) { | |
146 | -// XxlJobLogger.log("method[" + method + "] invalid."); | |
147 | -// return ReturnT.FAIL; | |
148 | -// } | |
149 | -// | |
150 | -// // request | |
151 | -// HttpURLConnection connection = null; | |
152 | -// BufferedReader bufferedReader = null; | |
153 | -// try { | |
154 | -// // connection | |
155 | -// URL realUrl = new URL(url); | |
156 | -// connection = (HttpURLConnection) realUrl.openConnection(); | |
157 | -// | |
158 | -// // connection setting | |
159 | -// connection.setRequestMethod(method); | |
160 | -// connection.setDoOutput(true); | |
161 | -// connection.setDoInput(true); | |
162 | -// connection.setUseCaches(false); | |
163 | -// connection.setReadTimeout(5 * 1000); | |
164 | -// connection.setConnectTimeout(3 * 1000); | |
165 | -// connection.setRequestProperty("connection", "Keep-Alive"); | |
166 | -// connection.setRequestProperty("Content-Type", "application/json;charset=UTF-8"); | |
167 | -// connection.setRequestProperty("Accept-Charset", "application/json;charset=UTF-8"); | |
168 | -// | |
169 | -// // do connection | |
170 | -// connection.connect(); | |
171 | -// | |
172 | -// // data | |
173 | -// if (data != null && data.trim().length() > 0) { | |
174 | -// DataOutputStream dataOutputStream = new DataOutputStream(connection.getOutputStream()); | |
175 | -// dataOutputStream.write(data.getBytes("UTF-8")); | |
176 | -// dataOutputStream.flush(); | |
177 | -// dataOutputStream.close(); | |
178 | -// } | |
179 | -// | |
180 | -// // valid StatusCode | |
181 | -// int statusCode = connection.getResponseCode(); | |
182 | -// if (statusCode != 200) { | |
183 | -// throw new RuntimeException("Http Request StatusCode(" + statusCode + ") Invalid."); | |
184 | -// } | |
185 | -// | |
186 | -// // result | |
187 | -// bufferedReader = new BufferedReader(new InputStreamReader(connection.getInputStream(), "UTF-8")); | |
188 | -// StringBuilder result = new StringBuilder(); | |
189 | -// String line; | |
190 | -// while ((line = bufferedReader.readLine()) != null) { | |
191 | -// result.append(line); | |
192 | -// } | |
193 | -// String responseMsg = result.toString(); | |
194 | -// | |
195 | -// XxlJobLogger.log(responseMsg); | |
196 | -// return ReturnT.SUCCESS; | |
197 | -// } catch (Exception e) { | |
198 | -// XxlJobLogger.log(e); | |
199 | -// return ReturnT.FAIL; | |
200 | -// } finally { | |
201 | -// try { | |
202 | -// if (bufferedReader != null) { | |
203 | -// bufferedReader.close(); | |
204 | -// } | |
205 | -// if (connection != null) { | |
206 | -// connection.disconnect(); | |
207 | -// } | |
208 | -// } catch (Exception e2) { | |
209 | -// XxlJobLogger.log(e2); | |
210 | -// } | |
211 | -// } | |
212 | -// | |
213 | -// } | |
214 | -// | |
215 | -// | |
216 | -// /** | |
217 | -// * 5、生命周期任务示例:任务初始化与销毁时,支持自定义相关逻辑; | |
218 | -// */ | |
219 | -// | |
220 | -// @XxlJob(value = "demoJobHandler2", init = "init", destroy = "destroy") | |
221 | -// public ReturnT<String> demoJobHandler2(String param) throws Exception { | |
222 | -// XxlJobLogger.log("XXL-JOB, Hello World."); | |
223 | -// return ReturnT.SUCCESS; | |
224 | -// } | |
225 | -// | |
226 | -// public void init() { | |
227 | -// log.info("init"); | |
228 | -// } | |
229 | -// | |
230 | -// public void destroy() { | |
231 | -// log.info("destory"); | |
232 | -// } | |
233 | -//} | |
234 | -// |
jeecg-boot/jeecg-cloud-module/jeecg-cloud-example/Dockerfile deleted
1 | -FROM anapsix/alpine-java:8_server-jre_unlimited | |
2 | - | |
3 | -MAINTAINER jeecgos@163.com | |
4 | - | |
5 | -RUN ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime | |
6 | - | |
7 | -RUN mkdir -p /jeecg-cloud-example | |
8 | - | |
9 | -WORKDIR /jeecg-cloud-example | |
10 | - | |
11 | -EXPOSE 7001 | |
12 | - | |
13 | -ADD ./target/jeecg-cloud-example-2.4.2.jar ./ | |
14 | - | |
15 | -CMD java -Dfile.encoding=utf-8 -Djava.security.egd=file:/dev/./urandom -jar jeecg-cloud-example-2.4.2.jar | |
16 | - |
jeecg-boot/jeecg-cloud-module/jeecg-cloud-example/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-cloud-module</artifactId> | |
7 | - <groupId>org.jeecgframework.boot</groupId> | |
8 | - <version>2.4.2</version> | |
9 | - </parent> | |
10 | - <modelVersion>4.0.0</modelVersion> | |
11 | - <artifactId>jeecg-cloud-example</artifactId> | |
12 | - <description>jeecg-cloud-example 微服务测试例子</description> | |
13 | - <dependencies> | |
14 | - <!-- 引入jeecg-boot-starter-cloud依赖--> | |
15 | - <dependency> | |
16 | - <groupId>org.jeecgframework.boot</groupId> | |
17 | - <artifactId>jeecg-boot-starter-cloud</artifactId> | |
18 | - </dependency> | |
19 | - <!-- 引入定时任务依赖 --> | |
20 | - <dependency> | |
21 | - <groupId>org.jeecgframework.boot</groupId> | |
22 | - <artifactId>jeecg-boot-starter-job</artifactId> | |
23 | - </dependency> | |
24 | - | |
25 | - <!-- 引入分布式锁依赖 --> | |
26 | - <dependency> | |
27 | - <groupId>org.jeecgframework.boot</groupId> | |
28 | - <artifactId>jeecg-boot-starter-lock</artifactId> | |
29 | - </dependency> | |
30 | - | |
31 | - <!--rabbitmq消息队列--> | |
32 | - <dependency> | |
33 | - <groupId>org.jeecgframework.boot</groupId> | |
34 | - <artifactId>jeecg-boot-starter-rabbitmq</artifactId> | |
35 | - </dependency> | |
36 | - | |
37 | - </dependencies> | |
38 | - <build> | |
39 | - <plugins> | |
40 | - <plugin> | |
41 | - <groupId>org.springframework.boot</groupId> | |
42 | - <artifactId>spring-boot-maven-plugin</artifactId> | |
43 | - </plugin> | |
44 | - </plugins> | |
45 | - <resources> | |
46 | - <resource> | |
47 | - <directory>src/main/resources</directory> | |
48 | - <filtering>true</filtering> | |
49 | - </resource> | |
50 | - </resources> | |
51 | - </build> | |
52 | - | |
53 | -</project> | |
54 | 0 | \ No newline at end of file |
jeecg-boot/jeecg-cloud-module/jeecg-cloud-example/src/main/java/org/jeecg/JeecgCloudExampleApplication.java deleted
1 | - | |
2 | -package org.jeecg; | |
3 | - | |
4 | -import org.springframework.boot.SpringApplication; | |
5 | -import org.springframework.boot.autoconfigure.SpringBootApplication; | |
6 | -import org.springframework.cloud.openfeign.EnableFeignClients; | |
7 | -import org.springframework.scheduling.annotation.EnableScheduling; | |
8 | - | |
9 | -@EnableScheduling | |
10 | -@EnableFeignClients(basePackages = {"org.jeecg"}) | |
11 | -@SpringBootApplication(scanBasePackages = "org.jeecg") | |
12 | -public class JeecgCloudExampleApplication { | |
13 | - | |
14 | - public static void main(String[] args) { | |
15 | - SpringApplication.run(JeecgCloudExampleApplication.class, args); | |
16 | - } | |
17 | -} |
jeecg-boot/jeecg-cloud-module/jeecg-cloud-example/src/main/java/org/jeecg/cloud/demo/rabbitmq/DemoRabbitMqListener2.java deleted
1 | -package org.jeecg.cloud.demo.rabbitmq; | |
2 | - | |
3 | -import com.rabbitmq.client.Channel; | |
4 | -import lombok.extern.slf4j.Slf4j; | |
5 | -import org.jeecg.boot.starter.rabbitmq.core.BaseRabbiMqHandler; | |
6 | -import org.jeecg.boot.starter.rabbitmq.listenter.MqListener; | |
7 | -import org.jeecg.common.annotation.RabbitComponent; | |
8 | -import org.jeecg.common.base.BaseMap; | |
9 | -import org.springframework.amqp.rabbit.annotation.RabbitListener; | |
10 | -import org.springframework.amqp.support.AmqpHeaders; | |
11 | -import org.springframework.messaging.handler.annotation.Header; | |
12 | - | |
13 | -@Slf4j | |
14 | -@RabbitComponent(value = "testListener2") | |
15 | -public class DemoRabbitMqListener2 extends BaseRabbiMqHandler<BaseMap> { | |
16 | - | |
17 | - @RabbitListener(queues = "test2") | |
18 | - public void onMessage(BaseMap baseMap, Channel channel, @Header(AmqpHeaders.DELIVERY_TAG) long deliveryTag) { | |
19 | - super.onMessage(baseMap, deliveryTag, channel, new MqListener<BaseMap>() { | |
20 | - @Override | |
21 | - public void handler(BaseMap map, Channel channel) { | |
22 | - String orderId = map.get("orderId"); | |
23 | - log.info("业务处理2:orderId:" + orderId); | |
24 | - } | |
25 | - }); | |
26 | - } | |
27 | - | |
28 | -} |
jeecg-boot/jeecg-cloud-module/jeecg-cloud-example/src/main/java/org/jeecg/cloud/demo/test/controller/JeecgDemoController.java deleted
1 | -package org.jeecg.cloud.demo.test.controller; | |
2 | - | |
3 | -import io.swagger.annotations.Api; | |
4 | -import io.swagger.annotations.ApiOperation; | |
5 | -import lombok.extern.slf4j.Slf4j; | |
6 | -import org.jeecg.common.api.vo.Result; | |
7 | -import org.jeecg.common.system.api.ISysBaseAPI; | |
8 | -import org.jeecg.common.system.vo.DictModel; | |
9 | -import org.springframework.web.bind.annotation.GetMapping; | |
10 | -import org.springframework.web.bind.annotation.RequestMapping; | |
11 | -import org.springframework.web.bind.annotation.RestController; | |
12 | - | |
13 | -import javax.annotation.Resource; | |
14 | -import java.util.List; | |
15 | - | |
16 | -/** | |
17 | - * | |
18 | - */ | |
19 | -@Slf4j | |
20 | -@Api(tags = "jeecg-demo") | |
21 | -@RestController | |
22 | -@RequestMapping("/test") | |
23 | -public class JeecgDemoController { | |
24 | - | |
25 | - | |
26 | - @Resource | |
27 | - private ISysBaseAPI sysBaseAPI; | |
28 | - | |
29 | - /** | |
30 | - * 测试 | |
31 | - * | |
32 | - * @return | |
33 | - */ | |
34 | - @GetMapping("/demo") | |
35 | - @ApiOperation(value = "测试方法", notes = "测试方法") | |
36 | - public Result mockChange2() { | |
37 | -// try{ | |
38 | -// //睡5秒,网关Hystrix3秒超时,会触发熔断降级操作 | |
39 | -// Thread.sleep(5000); | |
40 | -// }catch (Exception e){ | |
41 | -// e.printStackTrace(); | |
42 | -// } | |
43 | - List<DictModel> list = sysBaseAPI.queryAllDict(); | |
44 | - return Result.OK(list); | |
45 | - } | |
46 | - | |
47 | - | |
48 | -} |
jeecg-boot/jeecg-cloud-module/jeecg-cloud-example/src/main/resources/application.yml deleted
jeecg-boot/jeecg-cloud-module/jeecg-cloud-system-start/pom.xml
... | ... | @@ -9,14 +9,9 @@ |
9 | 9 | </parent> |
10 | 10 | <modelVersion>4.0.0</modelVersion> |
11 | 11 | <artifactId>jeecg-cloud-system-start</artifactId> |
12 | - <description>jeecg-cloud-system-start基础启动模块</description> | |
12 | + <description>System项目微服务启动</description> | |
13 | 13 | |
14 | 14 | <dependencies> |
15 | - <!-- 引入jeecg-boot-module-system依赖 --> | |
16 | - <dependency> | |
17 | - <groupId>org.jeecgframework.boot</groupId> | |
18 | - <artifactId>jeecg-boot-module-system</artifactId> | |
19 | - </dependency> | |
20 | 15 | <!-- 引入jeecg-boot-starter-cloud依赖 --> |
21 | 16 | <dependency> |
22 | 17 | <groupId>org.jeecgframework.boot</groupId> |
... | ... | @@ -29,6 +24,12 @@ |
29 | 24 | </exclusion> |
30 | 25 | </exclusions> |
31 | 26 | </dependency> |
27 | + <!-- 引入jeecg-boot-module-system依赖 --> | |
28 | + <dependency> | |
29 | + <groupId>org.jeecgframework.boot</groupId> | |
30 | + <artifactId>jeecg-boot-module-system</artifactId> | |
31 | + </dependency> | |
32 | + | |
32 | 33 | <!--rabbitmq消息队列--> |
33 | 34 | <dependency> |
34 | 35 | <groupId>org.jeecgframework.boot</groupId> |
... | ... | @@ -39,6 +40,12 @@ |
39 | 40 | <groupId>org.jeecgframework.boot</groupId> |
40 | 41 | <artifactId>jeecg-boot-starter-job</artifactId> |
41 | 42 | </dependency> |
43 | + <!-- 分布式锁依赖 --> | |
44 | + <dependency> | |
45 | + <groupId>org.jeecgframework.boot</groupId> | |
46 | + <artifactId>jeecg-boot-starter-lock</artifactId> | |
47 | + </dependency> | |
48 | + | |
42 | 49 | </dependencies> |
43 | 50 | |
44 | 51 | <build> |
... | ... |
jeecg-boot/jeecg-cloud-module/jeecg-cloud-system-start/src/main/java/org/jeecg/JeecgSystemCloudApplication.java
1 | 1 | package org.jeecg; |
2 | 2 | |
3 | 3 | import lombok.extern.slf4j.Slf4j; |
4 | -import org.apache.catalina.Context; | |
5 | -import org.apache.tomcat.util.scan.StandardJarScanner; | |
6 | 4 | import org.jeecg.common.util.oConvertUtils; |
7 | 5 | import org.springframework.boot.SpringApplication; |
8 | 6 | import org.springframework.boot.autoconfigure.SpringBootApplication; |
9 | 7 | import org.springframework.boot.builder.SpringApplicationBuilder; |
10 | -import org.springframework.boot.web.embedded.tomcat.TomcatServletWebServerFactory; | |
11 | 8 | import org.springframework.boot.web.servlet.support.SpringBootServletInitializer; |
12 | 9 | import org.springframework.cloud.openfeign.EnableFeignClients; |
13 | 10 | import org.springframework.context.ConfigurableApplicationContext; |
14 | -import org.springframework.context.annotation.Bean; | |
15 | 11 | import org.springframework.core.env.Environment; |
12 | +import org.springframework.scheduling.annotation.EnableScheduling; | |
16 | 13 | |
17 | 14 | import java.net.InetAddress; |
18 | 15 | import java.net.UnknownHostException; |
... | ... | @@ -24,6 +21,7 @@ import java.net.UnknownHostException; |
24 | 21 | @Slf4j |
25 | 22 | @SpringBootApplication |
26 | 23 | @EnableFeignClients(basePackages = {"org.jeecg"}) |
24 | +@EnableScheduling | |
27 | 25 | public class JeecgSystemCloudApplication extends SpringBootServletInitializer { |
28 | 26 | |
29 | 27 | @Override |
... | ... | @@ -45,4 +43,5 @@ public class JeecgSystemCloudApplication extends SpringBootServletInitializer { |
45 | 43 | "----------------------------------------------------------"); |
46 | 44 | |
47 | 45 | } |
46 | + | |
48 | 47 | } |
49 | 48 | \ No newline at end of file |
... | ... |
jeecg-boot/jeecg-cloud-module/jeecg-cloud-system-start/src/main/java/org/jeecg/modules/cloud/constant/CloudConstant.java
0 → 100644
1 | +package org.jeecg.modules.cloud.constant; | |
2 | + | |
3 | +/** | |
4 | + * 微服务单元测试常量定义 | |
5 | + */ | |
6 | +public interface CloudConstant { | |
7 | + | |
8 | + /** | |
9 | + * 微服务名【对应模块jeecg-boot-module-demo】 | |
10 | + */ | |
11 | + public final static String SERVER_NAME_JEECGDEMO = "jeecg-demo"; | |
12 | + | |
13 | + /** | |
14 | + * MQ测试队列名字 | |
15 | + */ | |
16 | + public final static String MQ_JEECG_PLACE_ORDER = "jeecg_place_order"; | |
17 | + public final static String MQ_JEECG_PLACE_ORDER_TIME = "jeecg_place_order_time"; | |
18 | + | |
19 | + /** | |
20 | + * MQ测试消息总线 | |
21 | + */ | |
22 | + public final static String MQ_DEMO_BUS_EVENT = "demoBusEvent"; | |
23 | + | |
24 | + /** | |
25 | + * 分布式锁lock key | |
26 | + */ | |
27 | + public final static String REDISSON_DEMO_LOCK_KEY1 = "demoLockKey1"; | |
28 | + public final static String REDISSON_DEMO_LOCK_KEY2 = "demoLockKey2"; | |
29 | + | |
30 | +} | |
... | ... |
jeecg-boot/jeecg-cloud-module/jeecg-cloud-example/src/main/java/org/jeecg/cloud/demo/bus/DemoBusEvent.java renamed to jeecg-boot/jeecg-cloud-module/jeecg-cloud-system-start/src/main/java/org/jeecg/modules/cloud/ebus/DemoBusEvent.java
1 | -package org.jeecg.cloud.demo.bus; | |
1 | +package org.jeecg.modules.cloud.ebus; | |
2 | 2 | |
3 | 3 | import cn.hutool.core.util.ObjectUtil; |
4 | 4 | import lombok.extern.slf4j.Slf4j; |
5 | 5 | import org.jeecg.boot.starter.rabbitmq.event.EventObj; |
6 | 6 | import org.jeecg.boot.starter.rabbitmq.event.JeecgBusEventHandler; |
7 | 7 | import org.jeecg.common.base.BaseMap; |
8 | +import org.jeecg.modules.cloud.constant.CloudConstant; | |
8 | 9 | import org.springframework.stereotype.Component; |
9 | 10 | |
10 | 11 | /** |
11 | 12 | * 消息处理器【发布订阅】 |
12 | 13 | */ |
13 | 14 | @Slf4j |
14 | -@Component("demoBusEvent") | |
15 | +@Component(CloudConstant.MQ_DEMO_BUS_EVENT) | |
15 | 16 | public class DemoBusEvent implements JeecgBusEventHandler { |
16 | 17 | |
17 | 18 | |
... | ... |
jeecg-boot/jeecg-cloud-module/jeecg-cloud-system-start/src/main/java/org/jeecg/modules/cloud/feign/controller/JeecgTestFeignTest.java renamed to jeecg-boot/jeecg-cloud-module/jeecg-cloud-system-start/src/main/java/org/jeecg/modules/cloud/feign/controller/JeecgTestFeignController.java
1 | 1 | package org.jeecg.modules.cloud.feign.controller; |
2 | 2 | |
3 | 3 | |
4 | +import cn.hutool.core.util.RandomUtil; | |
4 | 5 | import io.swagger.annotations.Api; |
5 | 6 | import io.swagger.annotations.ApiOperation; |
7 | +import org.jeecg.boot.starter.rabbitmq.client.RabbitMqClient; | |
6 | 8 | import org.jeecg.common.api.vo.Result; |
9 | +import org.jeecg.common.base.BaseMap; | |
10 | +import org.jeecg.modules.cloud.constant.CloudConstant; | |
7 | 11 | import org.jeecg.modules.cloud.feign.feign.JeecgTestClient; |
8 | -import org.jeecg.modules.cloud.feign.feign.JeecgTestClient2; | |
12 | +import org.jeecg.modules.cloud.feign.feign.JeecgTestClientDyn; | |
9 | 13 | import org.jeecg.starter.cloud.feign.impl.JeecgFeignService; |
10 | 14 | import org.springframework.beans.factory.annotation.Autowired; |
11 | 15 | import org.springframework.web.bind.annotation.GetMapping; |
12 | 16 | import org.springframework.web.bind.annotation.RequestMapping; |
13 | 17 | import org.springframework.web.bind.annotation.RestController; |
14 | 18 | |
19 | +import javax.servlet.http.HttpServletRequest; | |
20 | + | |
15 | 21 | @RestController |
16 | 22 | @RequestMapping("/sys/test") |
17 | -@Api(tags = "feign测试") | |
18 | -public class JeecgTestFeignTest { | |
23 | +@Api(tags = "【微服务】单元测试") | |
24 | +public class JeecgTestFeignController { | |
19 | 25 | |
20 | 26 | @Autowired |
21 | 27 | private JeecgFeignService jeecgFeignService; |
22 | - | |
23 | 28 | @Autowired |
24 | 29 | private JeecgTestClient jeecgTestClient; |
25 | - | |
30 | + @Autowired | |
31 | + private RabbitMqClient rabbitMqClient; | |
26 | 32 | |
27 | 33 | @GetMapping("getMessage") |
28 | 34 | @ApiOperation(value = "测试feign", notes = "测试feign") |
... | ... | @@ -33,7 +39,23 @@ public class JeecgTestFeignTest { |
33 | 39 | @GetMapping("getMessage2") |
34 | 40 | @ApiOperation(value = "测试动态feign", notes = "测试动态feign") |
35 | 41 | public Result<String> getMessage2() { |
36 | - JeecgTestClient2 jeecgTestClient = jeecgFeignService.newInstance(JeecgTestClient2.class, "jeecg-demo"); | |
37 | - return jeecgTestClient.getMessage("jeecg-boot2"); | |
42 | + JeecgTestClientDyn myClientDyn = jeecgFeignService.newInstance(JeecgTestClientDyn.class, CloudConstant.SERVER_NAME_JEECGDEMO); | |
43 | + return myClientDyn.getMessage("动态fegin——jeecg-boot2"); | |
44 | + } | |
45 | + | |
46 | + @GetMapping(value = "/rabbitmq") | |
47 | + @ApiOperation(value = "测试rabbitmq", notes = "测试rabbitmq") | |
48 | + public Result<?> rabbitMqClientTest(HttpServletRequest req) { | |
49 | + //rabbitmq消息队列测试 | |
50 | + BaseMap map = new BaseMap(); | |
51 | + map.put("orderId", RandomUtil.randomNumbers(10)); | |
52 | + rabbitMqClient.sendMessage(CloudConstant.MQ_JEECG_PLACE_ORDER, map); | |
53 | + rabbitMqClient.sendMessage(CloudConstant.MQ_JEECG_PLACE_ORDER_TIME, map,10); | |
54 | + | |
55 | + //rabbitmq消息总线测试 | |
56 | + BaseMap params = new BaseMap(); | |
57 | + params.put("orderId", "123456"); | |
58 | + rabbitMqClient.publishEvent(CloudConstant.MQ_DEMO_BUS_EVENT, params); | |
59 | + return Result.OK("MQ发送消息成功"); | |
38 | 60 | } |
39 | 61 | } |
... | ... |
jeecg-boot/jeecg-cloud-module/jeecg-cloud-system-start/src/main/java/org/jeecg/modules/cloud/feign/feign/JeecgTestClient.java
1 | 1 | package org.jeecg.modules.cloud.feign.feign; |
2 | 2 | |
3 | 3 | import org.jeecg.common.api.vo.Result; |
4 | +import org.jeecg.modules.cloud.constant.CloudConstant; | |
5 | +import org.jeecg.modules.cloud.feign.feign.fallback.JeecgTestClientFallback; | |
4 | 6 | import org.springframework.cloud.openfeign.FeignClient; |
5 | 7 | import org.springframework.stereotype.Component; |
6 | 8 | import org.springframework.web.bind.annotation.GetMapping; |
... | ... | @@ -9,7 +11,7 @@ import org.springframework.web.bind.annotation.RequestParam; |
9 | 11 | /** |
10 | 12 | * 常规feign接口定义 |
11 | 13 | */ |
12 | -@FeignClient(value = "jeecg-demo", fallbackFactory = DemoFallback.class) | |
14 | +@FeignClient(value = CloudConstant.SERVER_NAME_JEECGDEMO, fallbackFactory = JeecgTestClientFallback.class) | |
13 | 15 | @Component |
14 | 16 | public interface JeecgTestClient { |
15 | 17 | |
... | ... |
jeecg-boot/jeecg-cloud-module/jeecg-cloud-system-start/src/main/java/org/jeecg/modules/cloud/feign/feign/JeecgTestClient2.java renamed to jeecg-boot/jeecg-cloud-module/jeecg-cloud-system-start/src/main/java/org/jeecg/modules/cloud/feign/feign/JeecgTestClientDyn.java
... | ... | @@ -7,7 +7,7 @@ import org.springframework.web.bind.annotation.RequestParam; |
7 | 7 | /** |
8 | 8 | * 动态feign接口定义 |
9 | 9 | */ |
10 | -public interface JeecgTestClient2 { | |
10 | +public interface JeecgTestClientDyn { | |
11 | 11 | |
12 | 12 | @GetMapping(value = "/test/getMessage") |
13 | 13 | Result<String> getMessage(@RequestParam("name") String name); |
... | ... |
jeecg-boot/jeecg-cloud-module/jeecg-cloud-system-start/src/main/java/org/jeecg/modules/cloud/feign/feign/DemoFallback.java renamed to jeecg-boot/jeecg-cloud-module/jeecg-cloud-system-start/src/main/java/org/jeecg/modules/cloud/feign/feign/fallback/JeecgTestClientFallback.java
1 | -package org.jeecg.modules.cloud.feign.feign; | |
1 | +package org.jeecg.modules.cloud.feign.feign.fallback; | |
2 | 2 | |
3 | 3 | import feign.hystrix.FallbackFactory; |
4 | +import org.jeecg.modules.cloud.feign.feign.JeecgTestClient; | |
4 | 5 | import org.springframework.stereotype.Component; |
5 | 6 | |
6 | 7 | /** |
7 | 8 | * @author qinfeng |
8 | 9 | */ |
9 | 10 | @Component |
10 | -public class DemoFallback implements FallbackFactory<JeecgTestClient> { | |
11 | +public class JeecgTestClientFallback implements FallbackFactory<JeecgTestClient> { | |
11 | 12 | |
12 | 13 | @Override |
13 | 14 | public JeecgTestClient create(Throwable throwable) { |
... | ... |
jeecg-boot/jeecg-cloud-module/jeecg-cloud-example/src/main/java/org/jeecg/cloud/demo/lock/DemoLockTest.java renamed to jeecg-boot/jeecg-cloud-module/jeecg-cloud-system-start/src/main/java/org/jeecg/modules/cloud/lock/DemoLockTest.java
1 | -package org.jeecg.cloud.demo.lock; | |
1 | +package org.jeecg.modules.cloud.lock; | |
2 | 2 | |
3 | 3 | import lombok.extern.slf4j.Slf4j; |
4 | 4 | import org.jeecg.boot.starter.lock.annotation.DistributedLock; |
5 | 5 | import org.jeecg.boot.starter.lock.client.RedissonLockClient; |
6 | 6 | import org.jeecg.boot.starter.rabbitmq.client.RabbitMqClient; |
7 | +import org.jeecg.common.base.BaseMap; | |
8 | +import org.jeecg.modules.cloud.constant.CloudConstant; | |
7 | 9 | import org.springframework.beans.factory.annotation.Autowired; |
8 | 10 | import org.springframework.scheduling.annotation.Scheduled; |
9 | 11 | import org.springframework.stereotype.Component; |
... | ... | @@ -19,43 +21,45 @@ import java.util.Map; |
19 | 21 | public class DemoLockTest { |
20 | 22 | @Autowired |
21 | 23 | RedissonLockClient redissonLock; |
22 | - | |
23 | 24 | @Autowired |
24 | 25 | RabbitMqClient rabbitMqClient; |
25 | 26 | |
26 | 27 | /** |
27 | - * 注解方式测试分布式锁 | |
28 | + * 测试分布式锁【注解方式】 | |
28 | 29 | */ |
29 | - //@Scheduled(cron = "0/5 * * * * ?") | |
30 | - @DistributedLock(lockKey = "redis-lock", expireSeconds = 11) | |
30 | + @Scheduled(cron = "0/5 * * * * ?") | |
31 | + @DistributedLock(lockKey = CloudConstant.REDISSON_DEMO_LOCK_KEY1) | |
31 | 32 | public void execute() throws InterruptedException { |
32 | 33 | log.info("执行execute任务开始,休眠三秒"); |
33 | 34 | Thread.sleep(3000); |
34 | 35 | System.out.println("=======================业务逻辑1============================="); |
35 | - Map map = new HashMap(); | |
36 | - map.put("orderId", "12345"); | |
37 | - rabbitMqClient.sendMessage("test", map); | |
36 | + Map map = new BaseMap(); | |
37 | + map.put("orderId", "BJ0001"); | |
38 | + rabbitMqClient.sendMessage(CloudConstant.MQ_JEECG_PLACE_ORDER, map); | |
38 | 39 | //延迟10秒发送 |
39 | - map.put("orderId", "555555"); | |
40 | - rabbitMqClient.sendMessage("test", map, 10000); | |
40 | + map.put("orderId", "NJ0002"); | |
41 | + rabbitMqClient.sendMessage(CloudConstant.MQ_JEECG_PLACE_ORDER, map, 10000); | |
41 | 42 | log.info("execute任务结束,休眠三秒"); |
42 | 43 | } |
43 | 44 | |
45 | + public DemoLockTest() { | |
46 | + } | |
47 | + | |
44 | 48 | /** |
45 | - * 编码方式测试分布式锁 | |
49 | + * 测试分布式锁【编码方式】 | |
46 | 50 | */ |
47 | - //@Scheduled(cron = "0/10 * * * * ?") | |
51 | + //@Scheduled(cron = "0/5 * * * * ?") | |
48 | 52 | public void execute2() throws InterruptedException { |
49 | - if (redissonLock.tryLock("redisson", -1, 10)) { | |
50 | - log.info("执行任务execute2开始,休眠三秒"); | |
51 | - Thread.sleep(3000); | |
53 | + if (redissonLock.tryLock(CloudConstant.REDISSON_DEMO_LOCK_KEY2, -1, 6000)) { | |
54 | + log.info("执行任务execute2开始,休眠十秒"); | |
55 | + Thread.sleep(10000); | |
52 | 56 | System.out.println("=======================业务逻辑2============================="); |
53 | - log.info("定时execute2结束,休眠三秒"); | |
54 | - redissonLock.unlock("redisson"); | |
57 | + log.info("定时execute2结束,休眠十秒"); | |
58 | + | |
59 | + redissonLock.unlock(CloudConstant.REDISSON_DEMO_LOCK_KEY2); | |
55 | 60 | } else { |
56 | 61 | log.info("execute2获取锁失败"); |
57 | 62 | } |
58 | 63 | } |
59 | 64 | |
60 | - | |
61 | 65 | } |
... | ... |
jeecg-boot/jeecg-cloud-module/jeecg-cloud-system-start/src/main/java/org/jeecg/modules/cloud/rabbitmq/HelloReceiver1.java
1 | 1 | package org.jeecg.modules.cloud.rabbitmq; |
2 | 2 | |
3 | 3 | import com.rabbitmq.client.Channel; |
4 | +import lombok.extern.slf4j.Slf4j; | |
4 | 5 | import org.jeecg.boot.starter.rabbitmq.core.BaseRabbiMqHandler; |
5 | 6 | import org.jeecg.boot.starter.rabbitmq.listenter.MqListener; |
6 | 7 | import org.jeecg.common.annotation.RabbitComponent; |
7 | 8 | import org.jeecg.common.base.BaseMap; |
9 | +import org.jeecg.modules.cloud.constant.CloudConstant; | |
8 | 10 | import org.springframework.amqp.rabbit.annotation.RabbitHandler; |
9 | 11 | import org.springframework.amqp.rabbit.annotation.RabbitListener; |
10 | 12 | import org.springframework.amqp.support.AmqpHeaders; |
11 | 13 | import org.springframework.messaging.handler.annotation.Header; |
12 | 14 | |
13 | -@RabbitListener(queues = "jeecg_place_order") | |
15 | +/** | |
16 | + * RabbitMq接受者1 | |
17 | + * (@RabbitListener声明类上,一个类只能监听一个队列) | |
18 | + */ | |
19 | +@Slf4j | |
20 | +@RabbitListener(queues = CloudConstant.MQ_JEECG_PLACE_ORDER) | |
14 | 21 | @RabbitComponent(value = "helloReceiver1") |
15 | 22 | public class HelloReceiver1 extends BaseRabbiMqHandler<BaseMap> { |
16 | 23 | |
... | ... | @@ -21,7 +28,7 @@ public class HelloReceiver1 extends BaseRabbiMqHandler<BaseMap> { |
21 | 28 | public void handler(BaseMap map, Channel channel) { |
22 | 29 | //业务处理 |
23 | 30 | String orderId = map.get("orderId").toString(); |
24 | - System.out.println("Receiver1 : " + orderId); | |
31 | + log.info("MQ Receiver1,orderId : " + orderId); | |
25 | 32 | } |
26 | 33 | }); |
27 | 34 | } |
... | ... |
jeecg-boot/jeecg-cloud-module/jeecg-cloud-system-start/src/main/java/org/jeecg/modules/cloud/rabbitmq/HelloReceiver2.java
1 | 1 | package org.jeecg.modules.cloud.rabbitmq; |
2 | 2 | |
3 | 3 | import com.rabbitmq.client.Channel; |
4 | +import lombok.extern.slf4j.Slf4j; | |
4 | 5 | import org.jeecg.boot.starter.rabbitmq.core.BaseRabbiMqHandler; |
5 | 6 | import org.jeecg.boot.starter.rabbitmq.listenter.MqListener; |
6 | 7 | import org.jeecg.common.annotation.RabbitComponent; |
7 | 8 | import org.jeecg.common.base.BaseMap; |
9 | +import org.jeecg.modules.cloud.constant.CloudConstant; | |
8 | 10 | import org.springframework.amqp.rabbit.annotation.RabbitHandler; |
9 | 11 | import org.springframework.amqp.rabbit.annotation.RabbitListener; |
10 | 12 | import org.springframework.amqp.support.AmqpHeaders; |
11 | 13 | import org.springframework.messaging.handler.annotation.Header; |
12 | 14 | |
13 | -@RabbitListener(queues = "jeecg_place_order") | |
15 | +/** | |
16 | + * RabbitMq接受者2 | |
17 | + * (@RabbitListener声明类上,一个类只能监听一个队列) | |
18 | + */ | |
19 | +@Slf4j | |
20 | +@RabbitListener(queues = CloudConstant.MQ_JEECG_PLACE_ORDER) | |
14 | 21 | @RabbitComponent(value = "helloReceiver2") |
15 | 22 | public class HelloReceiver2 extends BaseRabbiMqHandler<BaseMap> { |
16 | 23 | |
... | ... | @@ -21,7 +28,7 @@ public class HelloReceiver2 extends BaseRabbiMqHandler<BaseMap> { |
21 | 28 | public void handler(BaseMap map, Channel channel) { |
22 | 29 | //业务处理 |
23 | 30 | String orderId = map.get("orderId").toString(); |
24 | - System.out.println("Receiver2 : " + orderId); | |
31 | + log.info("MQ Receiver2,orderId : " + orderId); | |
25 | 32 | } |
26 | 33 | }); |
27 | 34 | } |
... | ... |
jeecg-boot/jeecg-cloud-module/jeecg-cloud-example/src/main/java/org/jeecg/cloud/demo/rabbitmq/DemoRabbitMqListener3.java renamed to jeecg-boot/jeecg-cloud-module/jeecg-cloud-system-start/src/main/java/org/jeecg/modules/cloud/rabbitmq/HelloReceiver3.java
1 | -package org.jeecg.cloud.demo.rabbitmq; | |
1 | +package org.jeecg.modules.cloud.rabbitmq; | |
2 | 2 | |
3 | 3 | import com.rabbitmq.client.Channel; |
4 | 4 | import lombok.extern.slf4j.Slf4j; |
... | ... | @@ -6,24 +6,30 @@ import org.jeecg.boot.starter.rabbitmq.core.BaseRabbiMqHandler; |
6 | 6 | import org.jeecg.boot.starter.rabbitmq.listenter.MqListener; |
7 | 7 | import org.jeecg.common.annotation.RabbitComponent; |
8 | 8 | import org.jeecg.common.base.BaseMap; |
9 | +import org.jeecg.modules.cloud.constant.CloudConstant; | |
9 | 10 | import org.springframework.amqp.rabbit.annotation.RabbitHandler; |
10 | 11 | import org.springframework.amqp.rabbit.annotation.RabbitListener; |
11 | 12 | import org.springframework.amqp.support.AmqpHeaders; |
12 | 13 | import org.springframework.messaging.handler.annotation.Header; |
13 | 14 | |
15 | +/** | |
16 | + * RabbitMq接受者3 | |
17 | + * (@RabbitListener声明类方法上,一个类可以多监听多个队列) | |
18 | + */ | |
14 | 19 | @Slf4j |
15 | -@RabbitListener(queues = "test3") | |
16 | -@RabbitComponent(value = "testListener3") | |
17 | -public class DemoRabbitMqListener3 extends BaseRabbiMqHandler<BaseMap> { | |
20 | +@RabbitComponent(value = "helloReceiver3") | |
21 | +public class HelloReceiver3 extends BaseRabbiMqHandler<BaseMap> { | |
18 | 22 | |
19 | - @RabbitHandler | |
23 | + @RabbitListener(queues = CloudConstant.MQ_JEECG_PLACE_ORDER) | |
20 | 24 | public void onMessage(BaseMap baseMap, Channel channel, @Header(AmqpHeaders.DELIVERY_TAG) long deliveryTag) { |
21 | 25 | super.onMessage(baseMap, deliveryTag, channel, new MqListener<BaseMap>() { |
22 | 26 | @Override |
23 | 27 | public void handler(BaseMap map, Channel channel) { |
28 | + //业务处理 | |
24 | 29 | String orderId = map.get("orderId").toString(); |
25 | - log.info("业务处理3:orderId:" + orderId); | |
30 | + log.info("MQ Receiver3,orderId : " + orderId); | |
26 | 31 | } |
27 | 32 | }); |
28 | 33 | } |
29 | -} | |
34 | + | |
35 | +} | |
30 | 36 | \ No newline at end of file |
... | ... |
jeecg-boot/jeecg-cloud-module/jeecg-cloud-system-start/src/main/java/org/jeecg/modules/cloud/rabbitmq/HelloTimeReceiver.java
1 | 1 | package org.jeecg.modules.cloud.rabbitmq; |
2 | 2 | |
3 | 3 | import com.rabbitmq.client.Channel; |
4 | +import lombok.extern.slf4j.Slf4j; | |
4 | 5 | import org.jeecg.boot.starter.rabbitmq.core.BaseRabbiMqHandler; |
5 | 6 | import org.jeecg.boot.starter.rabbitmq.listenter.MqListener; |
6 | 7 | import org.jeecg.common.annotation.RabbitComponent; |
7 | 8 | import org.jeecg.common.base.BaseMap; |
9 | +import org.jeecg.modules.cloud.constant.CloudConstant; | |
8 | 10 | import org.springframework.amqp.rabbit.annotation.RabbitHandler; |
9 | 11 | import org.springframework.amqp.rabbit.annotation.RabbitListener; |
10 | 12 | import org.springframework.amqp.support.AmqpHeaders; |
11 | 13 | import org.springframework.messaging.handler.annotation.Header; |
12 | 14 | |
13 | -@RabbitListener(queues = "jeecg_place_order_time") | |
15 | +@Slf4j | |
16 | +@RabbitListener(queues = CloudConstant.MQ_JEECG_PLACE_ORDER_TIME) | |
14 | 17 | @RabbitComponent(value = "helloTimeReceiver") |
15 | 18 | public class HelloTimeReceiver extends BaseRabbiMqHandler<BaseMap> { |
16 | 19 | |
... | ... | @@ -21,7 +24,7 @@ public class HelloTimeReceiver extends BaseRabbiMqHandler<BaseMap> { |
21 | 24 | public void handler(BaseMap map, Channel channel) { |
22 | 25 | //业务处理 |
23 | 26 | String orderId = map.get("orderId").toString(); |
24 | - System.out.println("Receiver1 : " + orderId); | |
27 | + log.info("Time Receiver1,orderId : " + orderId); | |
25 | 28 | } |
26 | 29 | }); |
27 | 30 | } |
... | ... |
jeecg-boot/jeecg-cloud-module/jeecg-cloud-system-start/src/main/java/org/jeecg/modules/cloud/xxljob/Demo2JobHandler.java deleted
1 | - | |
2 | -package org.jeecg.modules.cloud.xxljob;; | |
3 | - | |
4 | - | |
5 | -import com.xxl.job.core.biz.model.ReturnT; | |
6 | -import com.xxl.job.core.handler.annotation.XxlJob; | |
7 | -import com.xxl.job.core.log.XxlJobLogger; | |
8 | -import com.xxl.job.core.util.ShardingUtil; | |
9 | -import lombok.extern.slf4j.Slf4j; | |
10 | -import org.springframework.stereotype.Component; | |
11 | - | |
12 | - | |
13 | -/** | |
14 | - * xxl-job定时任务测试 | |
15 | - */ | |
16 | -@Component | |
17 | -@Slf4j | |
18 | -public class Demo2JobHandler { | |
19 | - | |
20 | - | |
21 | - /** | |
22 | - * 简单任务 | |
23 | - * | |
24 | - * @param params | |
25 | - * @return | |
26 | - */ | |
27 | - | |
28 | - @XxlJob(value = "demoJob2") | |
29 | - public ReturnT<String> demoJobHandler(String params) { | |
30 | - log.info("我是定时任务,我执行了..............................."); | |
31 | - return ReturnT.SUCCESS; | |
32 | - } | |
33 | - | |
34 | - /** | |
35 | - * 2、分片广播任务 | |
36 | - */ | |
37 | - | |
38 | - @XxlJob("shardingJobHandler3") | |
39 | - public ReturnT<String> shardingJobHandler(String param) throws Exception { | |
40 | - | |
41 | - // 分片参数 | |
42 | - ShardingUtil.ShardingVO shardingVO = ShardingUtil.getShardingVo(); | |
43 | - XxlJobLogger.log("分片参数:当前分片序号 = {}, 总分片数 = {}", shardingVO.getIndex(), shardingVO.getTotal()); | |
44 | - | |
45 | - // 业务逻辑 | |
46 | - for (int i = 0; i < shardingVO.getTotal(); i++) { | |
47 | - if (i == shardingVO.getIndex()) { | |
48 | - XxlJobLogger.log("第 {} 片, 命中分片开始处理", i); | |
49 | - } else { | |
50 | - XxlJobLogger.log("第 {} 片, 忽略", i); | |
51 | - } | |
52 | - } | |
53 | - | |
54 | - return ReturnT.SUCCESS; | |
55 | - } | |
56 | -} | |
57 | - |
jeecg-boot/jeecg-cloud-module/jeecg-cloud-example/src/main/java/org/jeecg/cloud/demo/job/DemoJobHandler.java renamed to jeecg-boot/jeecg-cloud-module/jeecg-cloud-system-start/src/main/java/org/jeecg/modules/cloud/xxljob/DemoJobHandler.java
1 | 1 | |
2 | -package org.jeecg.cloud.demo.job; | |
2 | +package org.jeecg.modules.cloud.xxljob;; | |
3 | 3 | |
4 | 4 | |
5 | 5 | import com.xxl.job.core.biz.model.ReturnT; |
... | ... | @@ -230,5 +230,6 @@ public class DemoJobHandler { |
230 | 230 | public void destroy() { |
231 | 231 | log.info("destory"); |
232 | 232 | } |
233 | + | |
233 | 234 | } |
234 | 235 | |
... | ... |
jeecg-boot/jeecg-cloud-module/pom.xml