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