Commit ab5c1dc6d66439de6fad0b06e95cf484089d6a8c
1 parent
03d742d9
拆分独立微服务测试模块jeecg-cloud-test,提供更多测试示例: 分布式事务、分库分表、mq、xxljob等
Showing
30 changed files
with
629 additions
and
278 deletions
jeecg-boot/jeecg-cloud-module/jeecg-cloud-system-start/pom.xml
@@ -30,21 +30,32 @@ | @@ -30,21 +30,32 @@ | ||
30 | <artifactId>jeecg-boot-module-system</artifactId> | 30 | <artifactId>jeecg-boot-module-system</artifactId> |
31 | </dependency> | 31 | </dependency> |
32 | 32 | ||
33 | + <!-- 测试模块依赖 --> | ||
33 | <!--rabbitmq消息队列 | 34 | <!--rabbitmq消息队列 |
34 | <dependency> | 35 | <dependency> |
35 | <groupId>org.jeecgframework.boot</groupId> | 36 | <groupId>org.jeecgframework.boot</groupId> |
36 | - <artifactId>jeecg-boot-starter-rabbitmq</artifactId> | 37 | + <artifactId>jeecg-cloud-test-rabbitmq</artifactId> |
38 | + <version>3.1.0</version> | ||
37 | </dependency>--> | 39 | </dependency>--> |
38 | - <!--xxl-job定时任务--> | 40 | + <!--XxlJob、分布式锁 |
39 | <dependency> | 41 | <dependency> |
40 | <groupId>org.jeecgframework.boot</groupId> | 42 | <groupId>org.jeecgframework.boot</groupId> |
41 | - <artifactId>jeecg-boot-starter-job</artifactId> | ||
42 | - </dependency> | ||
43 | - <!-- 分布式锁依赖 --> | 43 | + <artifactId>jeecg-cloud-test-more</artifactId> |
44 | + <version>3.1.0</version> | ||
45 | + </dependency>--> | ||
46 | + <!-- 分布式事务 | ||
44 | <dependency> | 47 | <dependency> |
45 | <groupId>org.jeecgframework.boot</groupId> | 48 | <groupId>org.jeecgframework.boot</groupId> |
46 | - <artifactId>jeecg-boot-starter-lock</artifactId> | ||
47 | - </dependency> | 49 | + <artifactId>jeecg-cloud-test-seata</artifactId> |
50 | + <version>3.1.0</version> | ||
51 | + </dependency>--> | ||
52 | + <!-- 分库分表 | ||
53 | + <dependency> | ||
54 | + <groupId>org.jeecgframework.boot</groupId> | ||
55 | + <artifactId>jeecg-cloud-test-shardingsphere</artifactId> | ||
56 | + <version>3.1.0</version> | ||
57 | + </dependency> --> | ||
58 | + <!-- 测试模块依赖 --> | ||
48 | 59 | ||
49 | </dependencies> | 60 | </dependencies> |
50 | 61 |
jeecg-boot/jeecg-cloud-module/jeecg-cloud-system-start/src/main/java/org/jeecg/JeecgSystemCloudApplication.java
@@ -22,7 +22,7 @@ import java.net.UnknownHostException; | @@ -22,7 +22,7 @@ import java.net.UnknownHostException; | ||
22 | @SpringBootApplication | 22 | @SpringBootApplication |
23 | @EnableFeignClients(basePackages = {"org.jeecg"}) | 23 | @EnableFeignClients(basePackages = {"org.jeecg"}) |
24 | @EnableScheduling | 24 | @EnableScheduling |
25 | -public class JeecgSystemCloudApplication extends SpringBootServletInitializer { | 25 | +public class JeecgSystemCloudApplication extends SpringBootServletInitializer{ |
26 | 26 | ||
27 | @Override | 27 | @Override |
28 | protected SpringApplicationBuilder configure(SpringApplicationBuilder application) { | 28 | protected SpringApplicationBuilder configure(SpringApplicationBuilder application) { |
jeecg-boot/jeecg-cloud-module/jeecg-cloud-system-start/src/main/java/org/jeecg/modules/cloud/ebus/DemoBusEvent.java deleted
1 | -//package org.jeecg.modules.cloud.ebus; | ||
2 | -// | ||
3 | -//import cn.hutool.core.util.ObjectUtil; | ||
4 | -//import lombok.extern.slf4j.Slf4j; | ||
5 | -//import org.jeecg.boot.starter.rabbitmq.event.EventObj; | ||
6 | -//import org.jeecg.boot.starter.rabbitmq.event.JeecgBusEventHandler; | ||
7 | -//import org.jeecg.common.base.BaseMap; | ||
8 | -//import org.jeecg.modules.cloud.constant.CloudConstant; | ||
9 | -//import org.springframework.stereotype.Component; | ||
10 | -// | ||
11 | -///** | ||
12 | -// * 消息处理器【发布订阅】 | ||
13 | -// */ | ||
14 | -//@Slf4j | ||
15 | -//@Component(CloudConstant.MQ_DEMO_BUS_EVENT) | ||
16 | -//public class DemoBusEvent implements JeecgBusEventHandler { | ||
17 | -// | ||
18 | -// | ||
19 | -// @Override | ||
20 | -// public void onMessage(EventObj obj) { | ||
21 | -// if (ObjectUtil.isNotEmpty(obj)) { | ||
22 | -// BaseMap baseMap = obj.getBaseMap(); | ||
23 | -// String orderId = baseMap.get("orderId"); | ||
24 | -// log.info("业务处理----订单ID:" + orderId); | ||
25 | -// } | ||
26 | -// } | ||
27 | -//} |
jeecg-boot/jeecg-cloud-module/jeecg-cloud-system-start/src/main/java/org/jeecg/modules/cloud/feign/controller/JeecgTestFeignController.java deleted
1 | -package org.jeecg.modules.cloud.feign.controller; | ||
2 | - | ||
3 | - | ||
4 | -import io.swagger.annotations.Api; | ||
5 | -import io.swagger.annotations.ApiOperation; | ||
6 | -import org.jeecg.common.api.vo.Result; | ||
7 | -import org.jeecg.modules.cloud.constant.CloudConstant; | ||
8 | -import org.jeecg.modules.cloud.feign.feign.JeecgTestClient; | ||
9 | -import org.jeecg.modules.cloud.feign.feign.JeecgTestClientDyn; | ||
10 | -import org.jeecg.starter.cloud.feign.impl.JeecgFeignService; | ||
11 | -import org.springframework.beans.factory.annotation.Autowired; | ||
12 | -import org.springframework.web.bind.annotation.GetMapping; | ||
13 | -import org.springframework.web.bind.annotation.RequestMapping; | ||
14 | -import org.springframework.web.bind.annotation.RestController; | ||
15 | - | ||
16 | -@RestController | ||
17 | -@RequestMapping("/sys/test") | ||
18 | -@Api(tags = "【微服务】单元测试") | ||
19 | -public class JeecgTestFeignController { | ||
20 | - | ||
21 | - @Autowired | ||
22 | - private JeecgFeignService jeecgFeignService; | ||
23 | - @Autowired | ||
24 | - private JeecgTestClient jeecgTestClient; | ||
25 | -// @Autowired | ||
26 | -// private RabbitMqClient rabbitMqClient; | ||
27 | - | ||
28 | - @GetMapping("getMessage") | ||
29 | - @ApiOperation(value = "测试feign", notes = "测试feign") | ||
30 | - public Result<String> getMessage() { | ||
31 | - return jeecgTestClient.getMessage("jeecg-boot"); | ||
32 | - } | ||
33 | - | ||
34 | - @GetMapping("getMessage2") | ||
35 | - @ApiOperation(value = "测试动态feign", notes = "测试动态feign") | ||
36 | - public Result<String> getMessage2() { | ||
37 | - JeecgTestClientDyn myClientDyn = jeecgFeignService.newInstance(JeecgTestClientDyn.class, CloudConstant.SERVER_NAME_JEECGDEMO); | ||
38 | - return myClientDyn.getMessage("动态fegin——jeecg-boot2"); | ||
39 | - } | ||
40 | - | ||
41 | -// @GetMapping(value = "/rabbitmq") | ||
42 | -// @ApiOperation(value = "测试rabbitmq", notes = "测试rabbitmq") | ||
43 | -// public Result<?> rabbitMqClientTest(HttpServletRequest req) { | ||
44 | -// //rabbitmq消息队列测试 | ||
45 | -// BaseMap map = new BaseMap(); | ||
46 | -// map.put("orderId", RandomUtil.randomNumbers(10)); | ||
47 | -// rabbitMqClient.sendMessage(CloudConstant.MQ_JEECG_PLACE_ORDER, map); | ||
48 | -// rabbitMqClient.sendMessage(CloudConstant.MQ_JEECG_PLACE_ORDER_TIME, map,10); | ||
49 | -// | ||
50 | -// //rabbitmq消息总线测试 | ||
51 | -// BaseMap params = new BaseMap(); | ||
52 | -// params.put("orderId", "123456"); | ||
53 | -// rabbitMqClient.publishEvent(CloudConstant.MQ_DEMO_BUS_EVENT, params); | ||
54 | -// return Result.OK("MQ发送消息成功"); | ||
55 | -// } | ||
56 | -} |
jeecg-boot/jeecg-cloud-module/jeecg-cloud-system-start/src/main/java/org/jeecg/modules/cloud/rabbitmq/HelloReceiver1.java deleted
1 | -//package org.jeecg.modules.cloud.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.jeecg.modules.cloud.constant.CloudConstant; | ||
10 | -//import org.springframework.amqp.rabbit.annotation.RabbitHandler; | ||
11 | -//import org.springframework.amqp.rabbit.annotation.RabbitListener; | ||
12 | -//import org.springframework.amqp.support.AmqpHeaders; | ||
13 | -//import org.springframework.messaging.handler.annotation.Header; | ||
14 | -// | ||
15 | -///** | ||
16 | -// * RabbitMq接受者1 | ||
17 | -// * (@RabbitListener声明类上,一个类只能监听一个队列) | ||
18 | -// */ | ||
19 | -//@Slf4j | ||
20 | -//@RabbitListener(queues = CloudConstant.MQ_JEECG_PLACE_ORDER) | ||
21 | -//@RabbitComponent(value = "helloReceiver1") | ||
22 | -//public class HelloReceiver1 extends BaseRabbiMqHandler<BaseMap> { | ||
23 | -// | ||
24 | -// @RabbitHandler | ||
25 | -// public void onMessage(BaseMap baseMap, Channel channel, @Header(AmqpHeaders.DELIVERY_TAG) long deliveryTag) { | ||
26 | -// super.onMessage(baseMap, deliveryTag, channel, new MqListener<BaseMap>() { | ||
27 | -// @Override | ||
28 | -// public void handler(BaseMap map, Channel channel) { | ||
29 | -// //业务处理 | ||
30 | -// String orderId = map.get("orderId").toString(); | ||
31 | -// log.info("MQ Receiver1,orderId : " + orderId); | ||
32 | -// } | ||
33 | -// }); | ||
34 | -// } | ||
35 | -// | ||
36 | -//} | ||
37 | \ No newline at end of file | 0 | \ No newline at end of file |
jeecg-boot/jeecg-cloud-module/jeecg-cloud-system-start/src/main/java/org/jeecg/modules/cloud/rabbitmq/HelloReceiver2.java deleted
1 | -//package org.jeecg.modules.cloud.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.jeecg.modules.cloud.constant.CloudConstant; | ||
10 | -//import org.springframework.amqp.rabbit.annotation.RabbitHandler; | ||
11 | -//import org.springframework.amqp.rabbit.annotation.RabbitListener; | ||
12 | -//import org.springframework.amqp.support.AmqpHeaders; | ||
13 | -//import org.springframework.messaging.handler.annotation.Header; | ||
14 | -// | ||
15 | -///** | ||
16 | -// * RabbitMq接受者2 | ||
17 | -// * (@RabbitListener声明类上,一个类只能监听一个队列) | ||
18 | -// */ | ||
19 | -//@Slf4j | ||
20 | -//@RabbitListener(queues = CloudConstant.MQ_JEECG_PLACE_ORDER) | ||
21 | -//@RabbitComponent(value = "helloReceiver2") | ||
22 | -//public class HelloReceiver2 extends BaseRabbiMqHandler<BaseMap> { | ||
23 | -// | ||
24 | -// @RabbitHandler | ||
25 | -// public void onMessage(BaseMap baseMap, Channel channel, @Header(AmqpHeaders.DELIVERY_TAG) long deliveryTag) { | ||
26 | -// super.onMessage(baseMap, deliveryTag, channel, new MqListener<BaseMap>() { | ||
27 | -// @Override | ||
28 | -// public void handler(BaseMap map, Channel channel) { | ||
29 | -// //业务处理 | ||
30 | -// String orderId = map.get("orderId").toString(); | ||
31 | -// log.info("MQ Receiver2,orderId : " + orderId); | ||
32 | -// } | ||
33 | -// }); | ||
34 | -// } | ||
35 | -// | ||
36 | -//} | ||
37 | \ No newline at end of file | 0 | \ No newline at end of file |
jeecg-boot/jeecg-cloud-module/jeecg-cloud-system-start/src/main/java/org/jeecg/modules/cloud/rabbitmq/HelloReceiver3.java deleted
1 | -//package org.jeecg.modules.cloud.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.jeecg.modules.cloud.constant.CloudConstant; | ||
10 | -//import org.springframework.amqp.rabbit.annotation.RabbitHandler; | ||
11 | -//import org.springframework.amqp.rabbit.annotation.RabbitListener; | ||
12 | -//import org.springframework.amqp.support.AmqpHeaders; | ||
13 | -//import org.springframework.messaging.handler.annotation.Header; | ||
14 | -// | ||
15 | -///** | ||
16 | -// * RabbitMq接受者3 | ||
17 | -// * (@RabbitListener声明类方法上,一个类可以多监听多个队列) | ||
18 | -// */ | ||
19 | -//@Slf4j | ||
20 | -//@RabbitComponent(value = "helloReceiver3") | ||
21 | -//public class HelloReceiver3 extends BaseRabbiMqHandler<BaseMap> { | ||
22 | -// | ||
23 | -// @RabbitListener(queues = CloudConstant.MQ_JEECG_PLACE_ORDER) | ||
24 | -// public void onMessage(BaseMap baseMap, Channel channel, @Header(AmqpHeaders.DELIVERY_TAG) long deliveryTag) { | ||
25 | -// super.onMessage(baseMap, deliveryTag, channel, new MqListener<BaseMap>() { | ||
26 | -// @Override | ||
27 | -// public void handler(BaseMap map, Channel channel) { | ||
28 | -// //业务处理 | ||
29 | -// String orderId = map.get("orderId").toString(); | ||
30 | -// log.info("MQ Receiver3,orderId : " + orderId); | ||
31 | -// } | ||
32 | -// }); | ||
33 | -// } | ||
34 | -// | ||
35 | -//} | ||
36 | \ No newline at end of file | 0 | \ 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 deleted
1 | -//package org.jeecg.modules.cloud.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.jeecg.modules.cloud.constant.CloudConstant; | ||
10 | -//import org.springframework.amqp.rabbit.annotation.RabbitHandler; | ||
11 | -//import org.springframework.amqp.rabbit.annotation.RabbitListener; | ||
12 | -//import org.springframework.amqp.support.AmqpHeaders; | ||
13 | -//import org.springframework.messaging.handler.annotation.Header; | ||
14 | -// | ||
15 | -//@Slf4j | ||
16 | -//@RabbitListener(queues = CloudConstant.MQ_JEECG_PLACE_ORDER_TIME) | ||
17 | -//@RabbitComponent(value = "helloTimeReceiver") | ||
18 | -//public class HelloTimeReceiver extends BaseRabbiMqHandler<BaseMap> { | ||
19 | -// | ||
20 | -// @RabbitHandler | ||
21 | -// public void onMessage(BaseMap baseMap, Channel channel, @Header(AmqpHeaders.DELIVERY_TAG) long deliveryTag) { | ||
22 | -// super.onMessage(baseMap, deliveryTag, channel, new MqListener<BaseMap>() { | ||
23 | -// @Override | ||
24 | -// public void handler(BaseMap map, Channel channel) { | ||
25 | -// //业务处理 | ||
26 | -// String orderId = map.get("orderId").toString(); | ||
27 | -// log.info("Time Receiver1,orderId : " + orderId); | ||
28 | -// } | ||
29 | -// }); | ||
30 | -// } | ||
31 | -// | ||
32 | -//} | ||
33 | \ No newline at end of file | 0 | \ No newline at end of file |
jeecg-boot/jeecg-cloud-module/jeecg-cloud-test/jeecg-cloud-test-more/pom.xml
0 → 100644
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-test</artifactId> | ||
7 | + <groupId>org.jeecgframework.boot</groupId> | ||
8 | + <version>3.1.0</version> | ||
9 | + </parent> | ||
10 | + <modelVersion>4.0.0</modelVersion> | ||
11 | + <description>公共测试模块</description> | ||
12 | + <artifactId>jeecg-cloud-test-more</artifactId> | ||
13 | + | ||
14 | + <dependencies> | ||
15 | + <!-- 引入jeecg-boot-starter-cloud依赖 --> | ||
16 | + <dependency> | ||
17 | + <groupId>org.jeecgframework.boot</groupId> | ||
18 | + <artifactId>jeecg-boot-starter-cloud</artifactId> | ||
19 | + <!--system模块需要排除jeecg-system-cloud-api--> | ||
20 | + <exclusions> | ||
21 | + <exclusion> | ||
22 | + <groupId>org.jeecgframework.boot</groupId> | ||
23 | + <artifactId>jeecg-system-cloud-api</artifactId> | ||
24 | + </exclusion> | ||
25 | + </exclusions> | ||
26 | + </dependency> | ||
27 | + <!--定时任务--> | ||
28 | + <dependency> | ||
29 | + <groupId>org.jeecgframework.boot</groupId> | ||
30 | + <artifactId>jeecg-boot-starter-job</artifactId> | ||
31 | + </dependency> | ||
32 | + <!--rabbitmq消息队列--> | ||
33 | + <dependency> | ||
34 | + <groupId>org.jeecgframework.boot</groupId> | ||
35 | + <artifactId>jeecg-boot-starter-rabbitmq</artifactId> | ||
36 | + </dependency> | ||
37 | + <!-- 分布式锁依赖 --> | ||
38 | + <dependency> | ||
39 | + <groupId>org.jeecgframework.boot</groupId> | ||
40 | + <artifactId>jeecg-boot-starter-lock</artifactId> | ||
41 | + </dependency> | ||
42 | + </dependencies> | ||
43 | + | ||
44 | +</project> | ||
0 | \ No newline at end of file | 45 | \ 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 renamed to jeecg-boot/jeecg-cloud-module/jeecg-cloud-test/jeecg-cloud-test-more/src/main/java/org/jeecg/modules/test/constant/CloudConstant.java
1 | -package org.jeecg.modules.cloud.constant; | 1 | +package org.jeecg.modules.test.constant; |
2 | 2 | ||
3 | /** | 3 | /** |
4 | * 微服务单元测试常量定义 | 4 | * 微服务单元测试常量定义 |
@@ -14,7 +14,6 @@ public interface CloudConstant { | @@ -14,7 +14,6 @@ public interface CloudConstant { | ||
14 | * MQ测试队列名字 | 14 | * MQ测试队列名字 |
15 | */ | 15 | */ |
16 | public final static String MQ_JEECG_PLACE_ORDER = "jeecg_place_order"; | 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 | 17 | ||
19 | /** | 18 | /** |
20 | * MQ测试消息总线 | 19 | * MQ测试消息总线 |
jeecg-boot/jeecg-cloud-module/jeecg-cloud-system-start/src/main/java/org/jeecg/modules/cloud/feign/feign/JeecgTestClient.java renamed to jeecg-boot/jeecg-cloud-module/jeecg-cloud-test/jeecg-cloud-test-more/src/main/java/org/jeecg/modules/test/feign/client/JeecgTestClient.java
1 | -package org.jeecg.modules.cloud.feign.feign; | 1 | +package org.jeecg.modules.test.feign.client; |
2 | 2 | ||
3 | import org.jeecg.common.api.vo.Result; | 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 | + |
5 | +import org.jeecg.config.FeignConfig; | ||
6 | +import org.jeecg.modules.test.constant.CloudConstant; | ||
7 | +import org.jeecg.modules.test.feign.factory.JeecgTestClientFactory; | ||
6 | import org.springframework.cloud.openfeign.FeignClient; | 8 | import org.springframework.cloud.openfeign.FeignClient; |
7 | import org.springframework.stereotype.Component; | 9 | import org.springframework.stereotype.Component; |
8 | -import org.springframework.web.bind.annotation.GetMapping; | 10 | +import org.springframework.web.bind.annotation.PostMapping; |
9 | import org.springframework.web.bind.annotation.RequestParam; | 11 | import org.springframework.web.bind.annotation.RequestParam; |
10 | 12 | ||
11 | /** | 13 | /** |
12 | * 常规feign接口定义 | 14 | * 常规feign接口定义 |
13 | */ | 15 | */ |
14 | -@FeignClient(value = CloudConstant.SERVER_NAME_JEECGDEMO, fallbackFactory = JeecgTestClientFallback.class) | 16 | +@FeignClient(value = CloudConstant.SERVER_NAME_JEECGDEMO, configuration = FeignConfig.class,fallbackFactory = JeecgTestClientFactory.class) |
15 | @Component | 17 | @Component |
16 | public interface JeecgTestClient { | 18 | public interface JeecgTestClient { |
17 | 19 | ||
18 | - @GetMapping(value = "/test/getMessage") | ||
19 | - Result<String> getMessage(@RequestParam("name") String name); | 20 | + @PostMapping(value = "/test/getMessage") |
21 | + Result<Object> getMessage(@RequestParam(value = "name",required = false) String name); | ||
20 | } | 22 | } |
jeecg-boot/jeecg-cloud-module/jeecg-cloud-system-start/src/main/java/org/jeecg/modules/cloud/feign/feign/JeecgTestClientDyn.java renamed to jeecg-boot/jeecg-cloud-module/jeecg-cloud-test/jeecg-cloud-test-more/src/main/java/org/jeecg/modules/test/feign/client/JeecgTestClientDyn.java
1 | -package org.jeecg.modules.cloud.feign.feign; | 1 | +package org.jeecg.modules.test.feign.client; |
2 | 2 | ||
3 | import org.jeecg.common.api.vo.Result; | 3 | import org.jeecg.common.api.vo.Result; |
4 | -import org.springframework.web.bind.annotation.GetMapping; | 4 | +import org.springframework.web.bind.annotation.PostMapping; |
5 | import org.springframework.web.bind.annotation.RequestParam; | 5 | import org.springframework.web.bind.annotation.RequestParam; |
6 | 6 | ||
7 | /** | 7 | /** |
@@ -9,6 +9,6 @@ import org.springframework.web.bind.annotation.RequestParam; | @@ -9,6 +9,6 @@ import org.springframework.web.bind.annotation.RequestParam; | ||
9 | */ | 9 | */ |
10 | public interface JeecgTestClientDyn { | 10 | public interface JeecgTestClientDyn { |
11 | 11 | ||
12 | - @GetMapping(value = "/test/getMessage") | ||
13 | - Result<String> getMessage(@RequestParam("name") String name); | 12 | + @PostMapping(value = "/test/getMessage") |
13 | + Result<String> getMessage(@RequestParam(value = "name",required = false) String name); | ||
14 | } | 14 | } |
jeecg-boot/jeecg-cloud-module/jeecg-cloud-test/jeecg-cloud-test-more/src/main/java/org/jeecg/modules/test/feign/controller/JeecgTestFeignController.java
0 → 100644
1 | +package org.jeecg.modules.test.feign.controller; | ||
2 | + | ||
3 | + | ||
4 | +import org.apache.commons.lang3.StringUtils; | ||
5 | +import org.jeecg.boot.starter.rabbitmq.client.RabbitMqClient; | ||
6 | +import org.jeecg.common.api.vo.Result; | ||
7 | +import org.jeecg.modules.test.feign.client.JeecgTestClient; | ||
8 | +import org.springframework.beans.factory.annotation.Autowired; | ||
9 | +import org.springframework.web.bind.annotation.PostMapping; | ||
10 | +import org.springframework.web.bind.annotation.RequestMapping; | ||
11 | +import org.springframework.web.bind.annotation.RequestParam; | ||
12 | +import org.springframework.web.bind.annotation.RestController; | ||
13 | + | ||
14 | +import com.alibaba.csp.sentinel.annotation.SentinelResource; | ||
15 | + | ||
16 | +import io.swagger.annotations.Api; | ||
17 | +import io.swagger.annotations.ApiOperation; | ||
18 | + | ||
19 | + | ||
20 | +@RestController | ||
21 | +@RequestMapping("/sys/test") | ||
22 | +@Api(tags = "【微服务】单元测试") | ||
23 | +public class JeecgTestFeignController { | ||
24 | + | ||
25 | + // @Autowired | ||
26 | + //private JeecgFeignService jeecgFeignService; | ||
27 | + | ||
28 | + @Autowired | ||
29 | + private JeecgTestClient jeecgTestClient; | ||
30 | + | ||
31 | + @Autowired | ||
32 | + private RabbitMqClient rabbitMqClient; | ||
33 | + | ||
34 | + @PostMapping("getMessage") | ||
35 | + @ApiOperation(value = "测试feign", notes = "测试feign") | ||
36 | + @SentinelResource(value = "fallback",fallback = "getDefaultUser") | ||
37 | + public Result<Object> getMessage(@RequestParam(value = "name",required = false) String name) { | ||
38 | + return jeecgTestClient.getMessage("fegin——jeecg-boot2"); | ||
39 | + } | ||
40 | + | ||
41 | + | ||
42 | +// @GetMapping("getMessage2") | ||
43 | +// @ApiOperation(value = "测试动态feign", notes = "测试动态feign") | ||
44 | +// public Result<String> getMessage2() { | ||
45 | +// JeecgTestClientDyn myClientDyn = jeecgFeignService.newInstance(JeecgTestClientDyn.class, CloudConstant.SERVER_NAME_JEECGDEMO); | ||
46 | +// return myClientDyn.getMessage("动态fegin——jeecg-boot2"); | ||
47 | +// } | ||
48 | + | ||
49 | + @PostMapping("test") | ||
50 | + @ApiOperation(value = "测试熔断", notes = "测试熔断") | ||
51 | + @SentinelResource(value = "fallback",fallback = "getDefaultUser") | ||
52 | + public Result<Object> test(@RequestParam(value = "name",required = false) String name) { | ||
53 | + if(StringUtils.isEmpty(name)){ | ||
54 | + throw new IllegalArgumentException("name param is empty"); | ||
55 | + } | ||
56 | + | ||
57 | + return Result.OK(); | ||
58 | + } | ||
59 | + public Result<Object> getDefaultUser(String name) { | ||
60 | + System.out.println("熔断,默认回调函数"); | ||
61 | + return Result.OK("访问超时"); | ||
62 | + } | ||
63 | +} |
jeecg-boot/jeecg-cloud-module/jeecg-cloud-system-start/src/main/java/org/jeecg/modules/cloud/feign/feign/fallback/JeecgTestClientFallback.java renamed to jeecg-boot/jeecg-cloud-module/jeecg-cloud-test/jeecg-cloud-test-more/src/main/java/org/jeecg/modules/test/feign/factory/JeecgTestClientFactory.java
1 | -package org.jeecg.modules.cloud.feign.feign.fallback; | 1 | +package org.jeecg.modules.test.feign.factory; |
2 | + | ||
3 | + | ||
4 | + | ||
2 | 5 | ||
3 | import feign.hystrix.FallbackFactory; | 6 | import feign.hystrix.FallbackFactory; |
4 | -import org.jeecg.modules.cloud.feign.feign.JeecgTestClient; | 7 | +import org.jeecg.modules.test.feign.client.JeecgTestClient; |
8 | +import org.jeecg.modules.test.feign.fallback.JeecgTestFallback; | ||
5 | import org.springframework.stereotype.Component; | 9 | import org.springframework.stereotype.Component; |
6 | 10 | ||
7 | /** | 11 | /** |
8 | * @author qinfeng | 12 | * @author qinfeng |
9 | */ | 13 | */ |
10 | @Component | 14 | @Component |
11 | -public class JeecgTestClientFallback implements FallbackFactory<JeecgTestClient> { | 15 | +public class JeecgTestClientFactory implements FallbackFactory<JeecgTestClient> { |
12 | 16 | ||
13 | @Override | 17 | @Override |
14 | public JeecgTestClient create(Throwable throwable) { | 18 | public JeecgTestClient create(Throwable throwable) { |
15 | - return null; | 19 | + JeecgTestFallback fallback = new JeecgTestFallback(); |
20 | + fallback.setCause(throwable); | ||
21 | + return fallback; | ||
16 | } | 22 | } |
17 | } | 23 | } |
jeecg-boot/jeecg-cloud-module/jeecg-cloud-test/jeecg-cloud-test-more/src/main/java/org/jeecg/modules/test/feign/fallback/JeecgTestFallback.java
0 → 100644
1 | +package org.jeecg.modules.test.feign.fallback; | ||
2 | + | ||
3 | +import org.jeecg.common.api.vo.Result; | ||
4 | + | ||
5 | +import lombok.Setter; | ||
6 | +import org.jeecg.modules.test.feign.client.JeecgTestClient; | ||
7 | + | ||
8 | + | ||
9 | +/** | ||
10 | + * | ||
11 | + */ | ||
12 | +public class JeecgTestFallback implements JeecgTestClient { | ||
13 | + | ||
14 | + @Setter | ||
15 | + private Throwable cause; | ||
16 | + | ||
17 | + | ||
18 | + @Override | ||
19 | + public Result<Object> getMessage(String name) { | ||
20 | + return Result.OK("访问超时"); | ||
21 | + } | ||
22 | +} |
jeecg-boot/jeecg-cloud-module/jeecg-cloud-system-start/src/main/java/org/jeecg/modules/cloud/lock/DemoLockTest.java renamed to jeecg-boot/jeecg-cloud-module/jeecg-cloud-test/jeecg-cloud-test-more/src/main/java/org/jeecg/modules/test/lock/DemoLockTest.java
1 | -package org.jeecg.modules.cloud.lock; | 1 | +package org.jeecg.modules.test.lock; |
2 | 2 | ||
3 | import lombok.extern.slf4j.Slf4j; | 3 | import lombok.extern.slf4j.Slf4j; |
4 | +import org.jeecg.boot.starter.lock.annotation.JLock; | ||
4 | import org.jeecg.boot.starter.lock.client.RedissonLockClient; | 5 | import org.jeecg.boot.starter.lock.client.RedissonLockClient; |
5 | -import org.jeecg.modules.cloud.constant.CloudConstant; | 6 | +import org.jeecg.boot.starter.rabbitmq.client.RabbitMqClient; |
7 | +import org.jeecg.common.base.BaseMap; | ||
8 | +import org.jeecg.modules.test.constant.CloudConstant; | ||
6 | import org.springframework.beans.factory.annotation.Autowired; | 9 | import org.springframework.beans.factory.annotation.Autowired; |
7 | import org.springframework.stereotype.Component; | 10 | import org.springframework.stereotype.Component; |
8 | 11 | ||
12 | +import java.util.Map; | ||
13 | + | ||
9 | /** | 14 | /** |
10 | * 分布式锁测试demo | 15 | * 分布式锁测试demo |
11 | */ | 16 | */ |
@@ -14,26 +19,26 @@ import org.springframework.stereotype.Component; | @@ -14,26 +19,26 @@ import org.springframework.stereotype.Component; | ||
14 | public class DemoLockTest { | 19 | public class DemoLockTest { |
15 | @Autowired | 20 | @Autowired |
16 | RedissonLockClient redissonLock; | 21 | RedissonLockClient redissonLock; |
17 | -// @Autowired | ||
18 | -// RabbitMqClient rabbitMqClient; | ||
19 | - | ||
20 | -// /** | ||
21 | -// * 测试分布式锁【注解方式】 | ||
22 | -// */ | ||
23 | -// @Scheduled(cron = "0/5 * * * * ?") | ||
24 | -// @JLock(lockKey = CloudConstant.REDISSON_DEMO_LOCK_KEY1) | ||
25 | -// public void execute() throws InterruptedException { | ||
26 | -// log.info("执行execute任务开始,休眠三秒"); | ||
27 | -// Thread.sleep(3000); | ||
28 | -// System.out.println("=======================业务逻辑1============================="); | ||
29 | -// Map map = new BaseMap(); | ||
30 | -// map.put("orderId", "BJ0001"); | ||
31 | -// rabbitMqClient.sendMessage(CloudConstant.MQ_JEECG_PLACE_ORDER, map); | ||
32 | -// //延迟10秒发送 | ||
33 | -// map.put("orderId", "NJ0002"); | ||
34 | -// rabbitMqClient.sendMessage(CloudConstant.MQ_JEECG_PLACE_ORDER, map, 10000); | ||
35 | -// log.info("execute任务结束,休眠三秒"); | ||
36 | -// } | 22 | + @Autowired |
23 | + RabbitMqClient rabbitMqClient; | ||
24 | + | ||
25 | + /** | ||
26 | + * 测试分布式锁【注解方式】 | ||
27 | + */ | ||
28 | + //@Scheduled(cron = "0/5 * * * * ?") | ||
29 | + @JLock(lockKey = CloudConstant.REDISSON_DEMO_LOCK_KEY1) | ||
30 | + public void execute() throws InterruptedException { | ||
31 | + log.info("执行execute任务开始,休眠三秒"); | ||
32 | + Thread.sleep(3000); | ||
33 | + System.out.println("=======================业务逻辑1============================="); | ||
34 | + Map map = new BaseMap(); | ||
35 | + map.put("orderId", "BJ0001"); | ||
36 | + rabbitMqClient.sendMessage(CloudConstant.MQ_JEECG_PLACE_ORDER, map); | ||
37 | + //延迟10秒发送 | ||
38 | + map.put("orderId", "NJ0002"); | ||
39 | + rabbitMqClient.sendMessage(CloudConstant.MQ_JEECG_PLACE_ORDER, map, 10000); | ||
40 | + log.info("execute任务结束,休眠三秒"); | ||
41 | + } | ||
37 | 42 | ||
38 | public DemoLockTest() { | 43 | public DemoLockTest() { |
39 | } | 44 | } |
jeecg-boot/jeecg-cloud-module/jeecg-cloud-system-start/src/main/java/org/jeecg/modules/cloud/xxljob/DemoJobHandler.java renamed to jeecg-boot/jeecg-cloud-module/jeecg-cloud-test/jeecg-cloud-test-more/src/main/java/org/jeecg/modules/test/xxljob/DemoJobHandler.java
1 | 1 | ||
2 | -package org.jeecg.modules.cloud.xxljob;; | 2 | +package org.jeecg.modules.test.xxljob; |
3 | 3 | ||
4 | 4 | ||
5 | import com.xxl.job.core.biz.model.ReturnT; | 5 | import com.xxl.job.core.biz.model.ReturnT; |
@@ -9,7 +9,6 @@ import com.xxl.job.core.log.XxlJobLogger; | @@ -9,7 +9,6 @@ import com.xxl.job.core.log.XxlJobLogger; | ||
9 | import com.xxl.job.core.util.ShardingUtil; | 9 | import com.xxl.job.core.util.ShardingUtil; |
10 | import lombok.extern.slf4j.Slf4j; | 10 | import lombok.extern.slf4j.Slf4j; |
11 | import org.springframework.stereotype.Component; | 11 | import org.springframework.stereotype.Component; |
12 | - | ||
13 | import java.io.BufferedInputStream; | 12 | import java.io.BufferedInputStream; |
14 | import java.io.BufferedReader; | 13 | import java.io.BufferedReader; |
15 | import java.io.DataOutputStream; | 14 | import java.io.DataOutputStream; |
jeecg-boot/jeecg-cloud-module/jeecg-cloud-test/jeecg-cloud-test-more/src/main/java/org/jeecg/modules/test/xxljob/XxclJobTest.java
0 → 100644
1 | + | ||
2 | +package org.jeecg.modules.test.xxljob; | ||
3 | + | ||
4 | +import com.xxl.job.core.biz.model.ReturnT; | ||
5 | +import com.xxl.job.core.handler.annotation.XxlJob; | ||
6 | +import lombok.extern.slf4j.Slf4j; | ||
7 | +import org.springframework.stereotype.Component; | ||
8 | + | ||
9 | + | ||
10 | +/** | ||
11 | + * xxl-job定时任务测试 | ||
12 | + */ | ||
13 | +@Component | ||
14 | +@Slf4j | ||
15 | +public class XxclJobTest { | ||
16 | + | ||
17 | + | ||
18 | + /** | ||
19 | + * 简单任务 | ||
20 | + * | ||
21 | + * @param params | ||
22 | + * @return | ||
23 | + */ | ||
24 | + | ||
25 | + @XxlJob(value = "testJob") | ||
26 | + public ReturnT<String> demoJobHandler(String params) { | ||
27 | + log.info("我是demo服务里的定时任务testJob,我执行了..............................."); | ||
28 | + return ReturnT.SUCCESS; | ||
29 | + } | ||
30 | + | ||
31 | + public void init() { | ||
32 | + log.info("init"); | ||
33 | + } | ||
34 | + | ||
35 | + public void destroy() { | ||
36 | + log.info("destory"); | ||
37 | + } | ||
38 | + | ||
39 | +} | ||
40 | + |
jeecg-boot/jeecg-cloud-module/jeecg-cloud-test/jeecg-cloud-test-rabbitmq/pom.xml
0 → 100644
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-test</artifactId> | ||
7 | + <groupId>org.jeecgframework.boot</groupId> | ||
8 | + <version>3.1.0</version> | ||
9 | + </parent> | ||
10 | + <modelVersion>4.0.0</modelVersion> | ||
11 | + <description>消息队列测试模块</description> | ||
12 | + <artifactId>jeecg-cloud-test-rabbitmq</artifactId> | ||
13 | + | ||
14 | + <dependencies> | ||
15 | + <!--rabbitmq消息队列--> | ||
16 | + <dependency> | ||
17 | + <groupId>org.jeecgframework.boot</groupId> | ||
18 | + <artifactId>jeecg-boot-starter-rabbitmq</artifactId> | ||
19 | + </dependency> | ||
20 | + </dependencies> | ||
21 | + | ||
22 | +</project> | ||
0 | \ No newline at end of file | 23 | \ No newline at end of file |
jeecg-boot/jeecg-cloud-module/jeecg-cloud-test/jeecg-cloud-test-rabbitmq/src/main/java/org/jeecg/modules/test/rabbitmq/constant/CloudConstant.java
0 → 100644
1 | +package org.jeecg.modules.test.rabbitmq.constant; | ||
2 | + | ||
3 | +/** | ||
4 | + * 微服务单元测试常量定义 | ||
5 | + */ | ||
6 | +public interface CloudConstant { | ||
7 | + | ||
8 | + | ||
9 | + /** | ||
10 | + * MQ测试队列名字 | ||
11 | + */ | ||
12 | + public final static String MQ_JEECG_PLACE_ORDER = "jeecg_place_order"; | ||
13 | + public final static String MQ_JEECG_PLACE_ORDER_TIME = "jeecg_place_order_time"; | ||
14 | + | ||
15 | + /** | ||
16 | + * MQ测试消息总线 | ||
17 | + */ | ||
18 | + public final static String MQ_DEMO_BUS_EVENT = "demoBusEvent"; | ||
19 | + | ||
20 | + /** | ||
21 | + * 分布式锁lock key | ||
22 | + */ | ||
23 | + public final static String REDISSON_DEMO_LOCK_KEY1 = "demoLockKey1"; | ||
24 | + public final static String REDISSON_DEMO_LOCK_KEY2 = "demoLockKey2"; | ||
25 | + | ||
26 | +} |
jeecg-boot/jeecg-cloud-module/jeecg-cloud-test/jeecg-cloud-test-rabbitmq/src/main/java/org/jeecg/modules/test/rabbitmq/controller/JeecgMqTestController.java
0 → 100644
1 | +package org.jeecg.modules.test.rabbitmq.controller; | ||
2 | + | ||
3 | + | ||
4 | +import javax.servlet.http.HttpServletRequest; | ||
5 | + | ||
6 | +import org.jeecg.boot.starter.rabbitmq.client.RabbitMqClient; | ||
7 | +import org.jeecg.common.api.vo.Result; | ||
8 | +import org.jeecg.common.base.BaseMap; | ||
9 | +import org.jeecg.modules.test.rabbitmq.constant.CloudConstant; | ||
10 | +import org.springframework.beans.factory.annotation.Autowired; | ||
11 | +import org.springframework.web.bind.annotation.GetMapping; | ||
12 | +import org.springframework.web.bind.annotation.RequestMapping; | ||
13 | +import org.springframework.web.bind.annotation.RestController; | ||
14 | + | ||
15 | +import cn.hutool.core.util.RandomUtil; | ||
16 | +import io.swagger.annotations.Api; | ||
17 | +import io.swagger.annotations.ApiOperation; | ||
18 | + | ||
19 | + | ||
20 | + | ||
21 | +@RestController | ||
22 | +@RequestMapping("/sys/test") | ||
23 | +@Api(tags = "【微服务】单元测试") | ||
24 | +public class JeecgMqTestController { | ||
25 | + | ||
26 | + @Autowired | ||
27 | + private RabbitMqClient rabbitMqClient; | ||
28 | + | ||
29 | + | ||
30 | + @GetMapping(value = "/rabbitmq") | ||
31 | + @ApiOperation(value = "测试rabbitmq", notes = "测试rabbitmq") | ||
32 | + public Result<?> rabbitMqClientTest(HttpServletRequest req) { | ||
33 | + //rabbitmq消息队列测试 | ||
34 | + BaseMap map = new BaseMap(); | ||
35 | + map.put("orderId", RandomUtil.randomNumbers(10)); | ||
36 | + rabbitMqClient.sendMessage(CloudConstant.MQ_JEECG_PLACE_ORDER, map); | ||
37 | + rabbitMqClient.sendMessage(CloudConstant.MQ_JEECG_PLACE_ORDER_TIME, map,10); | ||
38 | + return Result.OK("MQ发送消息成功"); | ||
39 | + } | ||
40 | + | ||
41 | + @GetMapping(value = "/rabbitmq2") | ||
42 | + @ApiOperation(value = "rabbitmq消息总线测试", notes = "rabbitmq消息总线测试") | ||
43 | + public Result<?> rabbitmq2(HttpServletRequest req) { | ||
44 | + | ||
45 | + //rabbitmq消息总线测试 | ||
46 | + BaseMap params = new BaseMap(); | ||
47 | + params.put("orderId", "123456"); | ||
48 | + rabbitMqClient.publishEvent(CloudConstant.MQ_DEMO_BUS_EVENT, params); | ||
49 | + return Result.OK("MQ发送消息成功"); | ||
50 | + } | ||
51 | +} |
jeecg-boot/jeecg-cloud-module/jeecg-cloud-test/jeecg-cloud-test-rabbitmq/src/main/java/org/jeecg/modules/test/rabbitmq/event/DemoBusEvent.java
0 → 100644
1 | +package org.jeecg.modules.test.rabbitmq.event; | ||
2 | + | ||
3 | +import org.jeecg.boot.starter.rabbitmq.event.EventObj; | ||
4 | +import org.jeecg.boot.starter.rabbitmq.event.JeecgBusEventHandler; | ||
5 | +import org.jeecg.common.base.BaseMap; | ||
6 | +import org.jeecg.modules.test.rabbitmq.constant.CloudConstant; | ||
7 | +import org.springframework.stereotype.Component; | ||
8 | + | ||
9 | +import cn.hutool.core.util.ObjectUtil; | ||
10 | +import lombok.extern.slf4j.Slf4j; | ||
11 | + | ||
12 | +/** | ||
13 | + * 消息处理器【发布订阅】 | ||
14 | + */ | ||
15 | +@Slf4j | ||
16 | +@Component(CloudConstant.MQ_DEMO_BUS_EVENT) | ||
17 | +public class DemoBusEvent implements JeecgBusEventHandler { | ||
18 | + | ||
19 | + | ||
20 | + @Override | ||
21 | + public void onMessage(EventObj obj) { | ||
22 | + if (ObjectUtil.isNotEmpty(obj)) { | ||
23 | + BaseMap baseMap = obj.getBaseMap(); | ||
24 | + String orderId = baseMap.get("orderId"); | ||
25 | + log.info("业务处理----订单ID:" + orderId); | ||
26 | + } | ||
27 | + } | ||
28 | +} |
jeecg-boot/jeecg-cloud-module/jeecg-cloud-test/jeecg-cloud-test-rabbitmq/src/main/java/org/jeecg/modules/test/rabbitmq/listener/HelloReceiver1.java
0 → 100644
1 | +package org.jeecg.modules.test.rabbitmq.listener; | ||
2 | + | ||
3 | +import org.jeecg.boot.starter.rabbitmq.core.BaseRabbiMqHandler; | ||
4 | +import org.jeecg.boot.starter.rabbitmq.listenter.MqListener; | ||
5 | +import org.jeecg.common.annotation.RabbitComponent; | ||
6 | +import org.jeecg.common.base.BaseMap; | ||
7 | +import org.jeecg.modules.test.rabbitmq.constant.CloudConstant; | ||
8 | +import org.springframework.amqp.rabbit.annotation.RabbitHandler; | ||
9 | +import org.springframework.amqp.rabbit.annotation.RabbitListener; | ||
10 | +import org.springframework.amqp.support.AmqpHeaders; | ||
11 | +import org.springframework.beans.factory.annotation.Autowired; | ||
12 | +import org.springframework.messaging.handler.annotation.Header; | ||
13 | +import org.springframework.web.client.RestTemplate; | ||
14 | + | ||
15 | +import com.rabbitmq.client.Channel; | ||
16 | + | ||
17 | +import lombok.extern.slf4j.Slf4j; | ||
18 | + | ||
19 | +/** | ||
20 | + * RabbitMq接受者1 | ||
21 | + * (@RabbitListener声明类上,一个类只能监听一个队列) | ||
22 | + */ | ||
23 | +@Slf4j | ||
24 | +@RabbitListener(queues = CloudConstant.MQ_JEECG_PLACE_ORDER) | ||
25 | +@RabbitComponent(value = "helloReceiver1") | ||
26 | +public class HelloReceiver1 extends BaseRabbiMqHandler<BaseMap> { | ||
27 | + | ||
28 | + @Autowired | ||
29 | + private RestTemplate restTemplate; | ||
30 | + | ||
31 | + @RabbitHandler | ||
32 | + public void onMessage(BaseMap baseMap, Channel channel, @Header(AmqpHeaders.DELIVERY_TAG) long deliveryTag) { | ||
33 | + super.onMessage(baseMap, deliveryTag, channel, new MqListener<BaseMap>() { | ||
34 | + @Override | ||
35 | + public void handler(BaseMap map, Channel channel) { | ||
36 | + //业务处理 | ||
37 | + String orderId = map.get("orderId").toString(); | ||
38 | + System.out.println("MQ Receiver1,orderId : " + orderId); | ||
39 | + // jeecgTestClient.getMessage("JEECG"); | ||
40 | + try{ | ||
41 | +// HttpHeaders requestHeaders = new HttpHeaders(); | ||
42 | +// requestHeaders.add("X-Access-Token", "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJleHAiOjE2MzExOTcyOTEsInVzZXJuYW1lIjoiYWRtaW4ifQ.N8mJvwzb4G0i3vYF9A2Bmf5cDKb1LDnOp1RwtpYEu1E"); | ||
43 | +// requestHeaders.add("content-type", MediaType.APPLICATION_JSON_UTF8.toString()); | ||
44 | +// MultiValueMap<String, String> requestBody = new LinkedMultiValueMap<>(); | ||
45 | +// requestBody.add("name", "test"); | ||
46 | +// HttpEntity< MultiValueMap<String, String> > requestEntity = new HttpEntity(requestBody, requestHeaders); | ||
47 | +// //post | ||
48 | +// ResponseEntity<String> responseEntity = restTemplate.postForEntity("http://localhost:7002/test/getMessage", requestEntity, String.class); | ||
49 | +// System.out.println(" responseEntity :"+responseEntity.getBody()); | ||
50 | + }catch (Exception e){ | ||
51 | + e.printStackTrace(); | ||
52 | + } | ||
53 | + | ||
54 | + } | ||
55 | + }); | ||
56 | + } | ||
57 | + | ||
58 | +} | ||
0 | \ No newline at end of file | 59 | \ No newline at end of file |
jeecg-boot/jeecg-cloud-module/jeecg-cloud-test/jeecg-cloud-test-rabbitmq/src/main/java/org/jeecg/modules/test/rabbitmq/listener/HelloReceiver2.java
0 → 100644
1 | +package org.jeecg.modules.test.rabbitmq.listener;//package org.jeecg.modules.cloud.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.jeecg.modules.test.rabbitmq.constant.CloudConstant; | ||
10 | +import org.springframework.amqp.rabbit.annotation.RabbitHandler; | ||
11 | +import org.springframework.amqp.rabbit.annotation.RabbitListener; | ||
12 | +import org.springframework.amqp.support.AmqpHeaders; | ||
13 | +import org.springframework.messaging.handler.annotation.Header; | ||
14 | + | ||
15 | +/** | ||
16 | + * RabbitMq接受者2 | ||
17 | + * (@RabbitListener声明类上,一个类只能监听一个队列) | ||
18 | + */ | ||
19 | +@Slf4j | ||
20 | +@RabbitListener(queues = CloudConstant.MQ_JEECG_PLACE_ORDER) | ||
21 | +@RabbitComponent(value = "helloReceiver2") | ||
22 | +public class HelloReceiver2 extends BaseRabbiMqHandler<BaseMap> { | ||
23 | + | ||
24 | + @RabbitHandler | ||
25 | + public void onMessage(BaseMap baseMap, Channel channel, @Header(AmqpHeaders.DELIVERY_TAG) long deliveryTag) { | ||
26 | + super.onMessage(baseMap, deliveryTag, channel, new MqListener<BaseMap>() { | ||
27 | + @Override | ||
28 | + public void handler(BaseMap map, Channel channel) { | ||
29 | + //业务处理 | ||
30 | + String orderId = map.get("orderId").toString(); | ||
31 | + log.info("MQ Receiver2,orderId : " + orderId); | ||
32 | + } | ||
33 | + }); | ||
34 | + } | ||
35 | + | ||
36 | +} | ||
0 | \ No newline at end of file | 37 | \ No newline at end of file |
jeecg-boot/jeecg-cloud-module/jeecg-cloud-test/jeecg-cloud-test-rabbitmq/src/main/java/org/jeecg/modules/test/rabbitmq/listener/HelloReceiver3.java
0 → 100644
1 | +package org.jeecg.modules.test.rabbitmq.listener;//package org.jeecg.modules.cloud.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.jeecg.modules.test.rabbitmq.constant.CloudConstant; | ||
10 | +import org.springframework.amqp.rabbit.annotation.RabbitListener; | ||
11 | +import org.springframework.amqp.support.AmqpHeaders; | ||
12 | +import org.springframework.messaging.handler.annotation.Header; | ||
13 | + | ||
14 | +/** | ||
15 | + * RabbitMq接受者3 | ||
16 | + * (@RabbitListener声明类方法上,一个类可以多监听多个队列) | ||
17 | + */ | ||
18 | +@Slf4j | ||
19 | +@RabbitComponent(value = "helloReceiver3") | ||
20 | +public class HelloReceiver3 extends BaseRabbiMqHandler<BaseMap> { | ||
21 | + | ||
22 | + @RabbitListener(queues = CloudConstant.MQ_JEECG_PLACE_ORDER) | ||
23 | + public void onMessage(BaseMap baseMap, Channel channel, @Header(AmqpHeaders.DELIVERY_TAG) long deliveryTag) { | ||
24 | + super.onMessage(baseMap, deliveryTag, channel, new MqListener<BaseMap>() { | ||
25 | + @Override | ||
26 | + public void handler(BaseMap map, Channel channel) { | ||
27 | + //业务处理 | ||
28 | + String orderId = map.get("orderId").toString(); | ||
29 | + log.info("MQ Receiver3,orderId : " + orderId); | ||
30 | + } | ||
31 | + }); | ||
32 | + } | ||
33 | + | ||
34 | +} | ||
0 | \ No newline at end of file | 35 | \ No newline at end of file |
jeecg-boot/jeecg-cloud-module/jeecg-cloud-test/jeecg-cloud-test-rabbitmq/src/main/java/org/jeecg/modules/test/rabbitmq/listener/HelloTimeReceiver.java
0 → 100644
1 | +package org.jeecg.modules.test.rabbitmq.listener; | ||
2 | + | ||
3 | +import org.jeecg.boot.starter.rabbitmq.core.BaseRabbiMqHandler; | ||
4 | +import org.jeecg.boot.starter.rabbitmq.listenter.MqListener; | ||
5 | +import org.jeecg.common.annotation.RabbitComponent; | ||
6 | +import org.jeecg.common.base.BaseMap; | ||
7 | +import org.jeecg.modules.test.rabbitmq.constant.CloudConstant; | ||
8 | +import org.springframework.amqp.rabbit.annotation.RabbitHandler; | ||
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 | +import com.rabbitmq.client.Channel; | ||
14 | + | ||
15 | +import lombok.extern.slf4j.Slf4j; | ||
16 | + | ||
17 | +@Slf4j | ||
18 | +@RabbitListener(queues = CloudConstant.MQ_JEECG_PLACE_ORDER_TIME) | ||
19 | +@RabbitComponent(value = "helloTimeReceiver") | ||
20 | +public class HelloTimeReceiver extends BaseRabbiMqHandler<BaseMap> { | ||
21 | + | ||
22 | + @RabbitHandler | ||
23 | + public void onMessage(BaseMap baseMap, Channel channel, @Header(AmqpHeaders.DELIVERY_TAG) long deliveryTag) { | ||
24 | + super.onMessage(baseMap, deliveryTag, channel, new MqListener<BaseMap>() { | ||
25 | + @Override | ||
26 | + public void handler(BaseMap map, Channel channel) { | ||
27 | + //业务处理 | ||
28 | + String orderId = map.get("orderId").toString(); | ||
29 | + log.info("Time Receiver1,orderId : " + orderId); | ||
30 | + } | ||
31 | + }); | ||
32 | + } | ||
33 | + | ||
34 | +} | ||
0 | \ No newline at end of file | 35 | \ No newline at end of file |
jeecg-boot/jeecg-cloud-module/jeecg-cloud-test/jeecg-cloud-test-shardingsphere/src/main/java/org/jeecg/modules/test/sharding/controller/JeecgShardingDemoController.java
@@ -29,12 +29,12 @@ public class JeecgShardingDemoController extends JeecgController<ShardingSysLog, | @@ -29,12 +29,12 @@ public class JeecgShardingDemoController extends JeecgController<ShardingSysLog, | ||
29 | private IShardingSysLogService shardingSysLogService; | 29 | private IShardingSysLogService shardingSysLogService; |
30 | 30 | ||
31 | /** | 31 | /** |
32 | - * 添加 | 32 | + * 单库分表 |
33 | * @return | 33 | * @return |
34 | */ | 34 | */ |
35 | - @PostMapping(value = "/add") | ||
36 | - @AutoLog(value = "分库分表添加") | ||
37 | - @ApiOperation(value = "分库分表添加", notes = "分库分表添加") | 35 | + @PostMapping(value = "/test1") |
36 | + @AutoLog(value = "单库分表") | ||
37 | + @ApiOperation(value = "单库分表", notes = "分库分表添加") | ||
38 | public Result<?> add() { | 38 | public Result<?> add() { |
39 | for (int i = 0; i < 10; i++) { | 39 | for (int i = 0; i < 10; i++) { |
40 | ShardingSysLog shardingSysLog = new ShardingSysLog(); | 40 | ShardingSysLog shardingSysLog = new ShardingSysLog(); |
@@ -45,5 +45,22 @@ public class JeecgShardingDemoController extends JeecgController<ShardingSysLog, | @@ -45,5 +45,22 @@ public class JeecgShardingDemoController extends JeecgController<ShardingSysLog, | ||
45 | } | 45 | } |
46 | return Result.OK(); | 46 | return Result.OK(); |
47 | } | 47 | } |
48 | + /** | ||
49 | + * 双库分表 | ||
50 | + * @return | ||
51 | + */ | ||
52 | + @PostMapping(value = "/test2") | ||
53 | + @AutoLog(value = "双库分表") | ||
54 | + @ApiOperation(value = "双库分表", notes = "双库分表") | ||
55 | + public Result<?> test2() { | ||
56 | + for (int i = 20; i <= 30; i++) { | ||
57 | + ShardingSysLog shardingSysLog = new ShardingSysLog(); | ||
58 | + shardingSysLog.setLogContent("双库分表测试"); | ||
59 | + shardingSysLog.setLogType(i); | ||
60 | + shardingSysLog.setOperateType(i); | ||
61 | + shardingSysLogService.save(shardingSysLog); | ||
62 | + } | ||
63 | + return Result.OK(); | ||
64 | + } | ||
48 | 65 | ||
49 | } | 66 | } |
jeecg-boot/jeecg-cloud-module/jeecg-cloud-test/jeecg-cloud-test-shardingsphere/src/main/resources/application-sharding.yml
@@ -3,9 +3,10 @@ spring: | @@ -3,9 +3,10 @@ spring: | ||
3 | props: | 3 | props: |
4 | sql-show: true | 4 | sql-show: true |
5 | datasource: | 5 | datasource: |
6 | + #添加分库数据源 | ||
6 | ds0: | 7 | ds0: |
7 | driverClassName: com.mysql.cj.jdbc.Driver | 8 | driverClassName: com.mysql.cj.jdbc.Driver |
8 | - url: jdbc:mysql://localhost:3306/jeecg-boot?useSSL=false&useUnicode=true&characterEncoding=utf-8&serverTimezone=Asia/Shanghai | 9 | + url: jdbc:mysql://localhost:3300/jeecg-boot?useSSL=false&useUnicode=true&characterEncoding=utf-8&serverTimezone=Asia/Shanghai |
9 | username: root | 10 | username: root |
10 | type: com.alibaba.druid.pool.DruidDataSource | 11 | type: com.alibaba.druid.pool.DruidDataSource |
11 | password: root | 12 | password: root |
@@ -26,7 +27,8 @@ spring: | @@ -26,7 +27,8 @@ spring: | ||
26 | table-classbased: | 27 | table-classbased: |
27 | props: | 28 | props: |
28 | strategy: standard | 29 | strategy: standard |
29 | - algorithmClassName: org.jeecg.modules.test.sharding.algorithm.StandardModTableShardAlgorithm | 30 | + # 自定义标准分配算法 |
31 | + algorithmClassName: org.jeecg.modules.demo.sharding.algorithm.StandardModTableShardAlgorithm | ||
30 | type: CLASS_BASED | 32 | type: CLASS_BASED |
31 | tables: | 33 | tables: |
32 | # 逻辑表名称 | 34 | # 逻辑表名称 |
@@ -38,5 +40,5 @@ spring: | @@ -38,5 +40,5 @@ spring: | ||
38 | standard: | 40 | standard: |
39 | # 分片算法名称 | 41 | # 分片算法名称 |
40 | sharding-algorithm-name: table-classbased | 42 | sharding-algorithm-name: table-classbased |
41 | - # 分片列名称 | 43 | + # 分片列名称(对应数据库字段) |
42 | sharding-column: log_type | 44 | sharding-column: log_type |
43 | \ No newline at end of file | 45 | \ No newline at end of file |
jeecg-boot/jeecg-cloud-module/jeecg-cloud-test/jeecg-cloud-test-shardingsphere/src/main/resources/application-sharding2.yml
0 → 100644
1 | +# 双库分表配置 | ||
2 | +spring: | ||
3 | + shardingsphere: | ||
4 | + props: | ||
5 | + sql-show: true | ||
6 | + datasource: | ||
7 | + ds0: | ||
8 | + driverClassName: com.mysql.cj.jdbc.Driver | ||
9 | + url: jdbc:mysql://localhost:3306/jeecg-boot?useSSL=false&useUnicode=true&characterEncoding=utf-8&serverTimezone=Asia/Shanghai | ||
10 | + type: com.alibaba.druid.pool.DruidDataSource | ||
11 | + username: root | ||
12 | + password: root | ||
13 | + ds1: | ||
14 | + driverClassName: com.mysql.cj.jdbc.Driver | ||
15 | + url: jdbc:mysql://localhost:3306/jeecg-boot2?useSSL=false&useUnicode=true&characterEncoding=utf-8&serverTimezone=Asia/Shanghai | ||
16 | + type: com.alibaba.druid.pool.DruidDataSource | ||
17 | + username: root | ||
18 | + password: root | ||
19 | + names: ds0,ds1 | ||
20 | + # 规则配置 | ||
21 | + rules: | ||
22 | + replica-query: | ||
23 | + # 负载均衡算法 | ||
24 | + load-balancers: | ||
25 | + round-robin: | ||
26 | + type: ROUND_ROBIN | ||
27 | + props: | ||
28 | + default: 0 | ||
29 | + data-sources: | ||
30 | + prds: | ||
31 | + primary-data-source-name: ds0 | ||
32 | + replica-data-source-names: ds1 | ||
33 | + load-balancer-name: round_robin | ||
34 | + sharding: | ||
35 | + # 配置绑定表,每一行为一组,绑定表会提高查询效率 | ||
36 | + binding-tables: | ||
37 | + - sys_log | ||
38 | + # 分布式序列算法配置 | ||
39 | + key-generators: | ||
40 | + snowflake: | ||
41 | + type: SNOWFLAKE | ||
42 | + props: | ||
43 | + worker-id: 123 | ||
44 | + # 分片算法配置 | ||
45 | + sharding-algorithms: | ||
46 | + table-classbased: | ||
47 | + props: | ||
48 | + strategy: standard | ||
49 | + algorithmClassName: org.jeecg.modules.test.sharding.algorithm.StandardModTableShardAlgorithm | ||
50 | + type: CLASS_BASED | ||
51 | + # 通过operate_type取模的方式确定数据落在哪个库 | ||
52 | + database-inline: | ||
53 | + type: INLINE | ||
54 | + props: | ||
55 | + algorithm-expression: ds$->{operate_type % 2} | ||
56 | + tables: | ||
57 | + # 逻辑表名称 | ||
58 | + sys_log: | ||
59 | + #配置具体表的数据节点 | ||
60 | + actual-data-nodes: ds$->{0..1}.sys_log$->{0..1} | ||
61 | + # 分库策略 | ||
62 | + database-strategy: | ||
63 | + standard: | ||
64 | + sharding-column: operate_type | ||
65 | + sharding-algorithm-name: database-inline | ||
66 | + # 分表策略 | ||
67 | + table-strategy: | ||
68 | + standard: | ||
69 | + # 分片算法名称 | ||
70 | + sharding-algorithm-name: table-classbased | ||
71 | + # 分片列名称 | ||
72 | + sharding-column: log_type | ||
0 | \ No newline at end of file | 73 | \ No newline at end of file |
jeecg-boot/jeecg-cloud-module/jeecg-cloud-test/pom.xml
@@ -22,5 +22,7 @@ | @@ -22,5 +22,7 @@ | ||
22 | <modules> | 22 | <modules> |
23 | <module>jeecg-cloud-test-seata</module> | 23 | <module>jeecg-cloud-test-seata</module> |
24 | <module>jeecg-cloud-test-shardingsphere</module> | 24 | <module>jeecg-cloud-test-shardingsphere</module> |
25 | + <module>jeecg-cloud-test-more</module> | ||
26 | + <module>jeecg-cloud-test-rabbitmq</module> | ||
25 | </modules> | 27 | </modules> |
26 | </project> | 28 | </project> |
27 | \ No newline at end of file | 29 | \ No newline at end of file |