JeecgBoot3.2.0 版本发布 [优化微服务模块]

This commit is contained in:
zhangdaiscott
2022-04-24 15:51:09 +08:00
parent 490f5696cf
commit 5dcb991dde
35 changed files with 103 additions and 41 deletions

View File

@ -2,6 +2,8 @@ package org.jeecg.modules.test.constant;
/**
* 微服务单元测试常量定义
* @author: zyf
* @date: 2022/04/21
*/
public interface CloudConstant {

View File

@ -9,17 +9,22 @@ 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.GetMapping;
import org.springframework.web.bind.annotation.Mapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam;
/**
* 常规feign接口定义
* @author: zyf
* @date: 2022/04/21
*/
@FeignClient(value = ServiceNameConstants.SERVICE_DEMO, configuration = FeignConfig.class,fallbackFactory = JeecgTestClientFactory.class)
@Component
public interface JeecgTestClient {
/**
* feign测试方法
* @param name
* @return
*/
@GetMapping(value = "/test/getMessage")
String getMessage(@RequestParam(value = "name",required = false) String name);
}

View File

@ -12,7 +12,11 @@ import com.alibaba.csp.sentinel.annotation.SentinelResource;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
/**
* 微服务单元测试
* @author: zyf
* @date: 2022/04/21
*/
@Slf4j
@RestController
@RequestMapping("/sys/test")

View File

@ -14,6 +14,8 @@ import java.util.Map;
/**
* 分布式锁测试demo
* @author: zyf
* @date: 2022/04/21
*/
@Slf4j
@Component
@ -50,10 +52,11 @@ public class DemoLockTest {
/**
* 测试分布式锁【编码方式】
* @Scheduled(cron = "0/5 * * * * ?")
*/
//@Scheduled(cron = "0/5 * * * * ?")
public void execute2() throws InterruptedException {
if (redissonLock.tryLock(CloudConstant.REDISSON_DEMO_LOCK_KEY2, -1, 6000)) {
int expireSeconds=6000;
if (redissonLock.tryLock(CloudConstant.REDISSON_DEMO_LOCK_KEY2, -1, expireSeconds)) {
log.info("执行任务execute2开始休眠十秒");
Thread.sleep(10000);
log.info("=============业务逻辑2===================");

View File

@ -20,6 +20,8 @@ import java.util.Arrays;
/**
* xxl-job定时任务测试
* @author: zyf
* @date: 2022/04/21
*/
@Component
@Slf4j
@ -113,7 +115,8 @@ public class DemoJobHandler {
*/
@XxlJob("httpJobHandler")
public ReturnT<String> httpJobHandler(String param) throws Exception {
String[] methodArray=new String[]{"GET","POST"};
int okState=200;
// param parse
if (param == null || param.trim().length() == 0) {
log.info("param[" + param + "] invalid.");
@ -140,7 +143,7 @@ public class DemoJobHandler {
log.info("url[" + url + "] invalid.");
return ReturnT.FAIL;
}
if (method == null || !Arrays.asList("GET", "POST").contains(method)) {
if (method == null || !Arrays.asList(methodArray).contains(method)) {
log.info("method[" + method + "] invalid.");
return ReturnT.FAIL;
}
@ -177,7 +180,7 @@ public class DemoJobHandler {
// valid StatusCode
int statusCode = connection.getResponseCode();
if (statusCode != 200) {
if (statusCode != okState) {
throw new RuntimeException("Http Request StatusCode(" + statusCode + ") Invalid.");
}

View File

@ -6,9 +6,10 @@ import com.xxl.job.core.handler.annotation.XxlJob;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
/**
* xxl-job定时任务测试
* xxl-job定时任务测试
* @author: zyf
* @date: 2022/04/21
*/
@Component
@Slf4j

View File

@ -2,6 +2,8 @@ package org.jeecg.modules.test.rabbitmq.constant;
/**
* 微服务单元测试常量定义
* @author: zyf
* @date: 2022/04/21
*/
public interface CloudConstant {

View File

@ -19,6 +19,8 @@ import io.swagger.annotations.ApiOperation;
/**
* RabbitMqClient发送消息
* @author: zyf
* @date: 2022/04/21
*/
@RestController
@RequestMapping("/sys/test")

View File

@ -11,6 +11,8 @@ import lombok.extern.slf4j.Slf4j;
/**
* 消息处理器【发布订阅】
* @author: zyf
* @date: 2022/04/21
*/
@Slf4j
@Component(CloudConstant.MQ_DEMO_BUS_EVENT)

View File

@ -21,6 +21,8 @@ import lombok.extern.slf4j.Slf4j;
*
* RabbitMq接受者1
* @RabbitListener声明类上一个类只能监听一个队列
* @author: zyf
* @date: 2022/04/21
*/
@Slf4j
@RabbitListener(queues = CloudConstant.MQ_JEECG_PLACE_ORDER)

View File

@ -17,6 +17,8 @@ import org.springframework.messaging.handler.annotation.Header;
*
* RabbitMq接受者2
* @RabbitListener声明类上一个类只能监听一个队列
* @author: zyf
* @date: 2022/04/21
*/
@Slf4j
@RabbitListener(queues = CloudConstant.MQ_JEECG_PLACE_ORDER)

View File

@ -16,6 +16,8 @@ import org.springframework.messaging.handler.annotation.Header;
*
* RabbitMq接受者3【我是处理人3】
* @RabbitListener声明类方法上一个类可以多监听多个队列
* @author: zyf
* @date: 2022/04/21
*/
@Slf4j
@RabbitComponent(value = "helloReceiver3")

View File

@ -14,6 +14,11 @@ import com.rabbitmq.client.Channel;
import lombok.extern.slf4j.Slf4j;
/**
* 定义接收者可以定义N个接受者消息会均匀的发送到N个接收者中
* @author: zyf
* @date: 2022/04/21
*/
@Slf4j
@RabbitListener(queues = CloudConstant.MQ_JEECG_PLACE_ORDER_TIME)
@RabbitComponent(value = "helloTimeReceiver")

View File

@ -10,6 +10,7 @@ import java.math.BigDecimal;
*/
public interface SeataAccountService {
/**
* 扣减金额
* @param userId 用户 ID
* @param amount 扣减金额
*/

View File

@ -32,7 +32,7 @@ public class SeataAccountServiceImpl implements SeataAccountService {
*/
@DS("account")
@Override
@Transactional(propagation = Propagation.REQUIRES_NEW)
@Transactional(propagation = Propagation.REQUIRES_NEW,rollbackFor = Exception.class)
public void reduceBalance(Long userId, BigDecimal amount) {
log.info("=============ACCOUNT START=================");
SeataAccount account = accountMapper.selectById(userId);

View File

@ -6,6 +6,11 @@ import org.springframework.web.bind.annotation.RequestParam;
import java.math.BigDecimal;
/**
* 分布式事务产品feign客户端
* @author: zyf
* @date: 2022/04/21
*/
@FeignClient(value ="seata-product")
public interface ProductClient {
/**

View File

@ -36,7 +36,7 @@ public class SeataOrderServiceImpl implements SeataOrderService {
@DS("order")
@Override
@Transactional
@Transactional(rollbackFor = Exception.class)
@GlobalTransactional
public void placeOrder(PlaceOrderRequest request) {
log.info("=============ORDER START=================");

View File

@ -32,7 +32,7 @@ public class SeataProductServiceImpl implements SeataProductService {
* 事务传播特性设置为 REQUIRES_NEW 开启新的事务
*/
@DS("product")
@Transactional(propagation = Propagation.REQUIRES_NEW)
@Transactional(propagation = Propagation.REQUIRES_NEW,rollbackFor = Exception.class)
@Override
public BigDecimal reduceStock(Long productId, Integer count) {
log.info("=============PRODUCT START=================");

View File

@ -35,7 +35,8 @@ public class JeecgShardingDemoController extends JeecgController<ShardingSysLog,
@PostMapping(value = "/test1")
@ApiOperation(value = "单库分表插入", notes = "单库分表")
public Result<?> add() {
for (int i = 0; i < 10; i++) {
int size=10;
for (int i = 0; i < size; i++) {
ShardingSysLog shardingSysLog = new ShardingSysLog();
shardingSysLog.setLogContent("jeecg");
shardingSysLog.setLogType(i);
@ -62,7 +63,9 @@ public class JeecgShardingDemoController extends JeecgController<ShardingSysLog,
@PostMapping(value = "/test2")
@ApiOperation(value = "双库分表插入", notes = "双库分表")
public Result<?> test2() {
for (int i = 20; i <= 30; i++) {
int start=20;
int size=30;
for (int i = start; i <= size; i++) {
ShardingSysLog shardingSysLog = new ShardingSysLog();
shardingSysLog.setLogContent("双库分表测试");
shardingSysLog.setLogType(i);

View File

@ -14,9 +14,9 @@ import java.io.Serializable;
import java.util.Date;
/**
* <p>
* 系统日志表
* </p>
* @author: zyf
* @date: 2022/04/21
*/
@Data
@TableName("sys_log")

View File

@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="org.jeecg.modules.demo.sharding.mapper.ShardingSysLogMapper">
<mapper namespace="org.jeecg.modules.test.sharding.mapper.ShardingSysLogMapper">
</mapper>

View File

@ -8,9 +8,9 @@ import org.jeecg.modules.test.sharding.service.IShardingSysLogService;
import org.springframework.stereotype.Service;
/**
* <p>
* 系统日志表 服务实现类
* </p>
* @author: zyf
* @date: 2022/04/21
*/
@Service
@DS("sharding")