后台目录结构大调整,让结构更清晰

This commit is contained in:
zhangdaiscott
2022-08-12 14:14:11 +08:00
parent 5f88b0e216
commit 4b19f25111
1486 changed files with 94 additions and 213 deletions

View File

@ -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.4.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>

View File

@ -0,0 +1,28 @@
package org.jeecg.modules.test.rabbitmq.constant;
/**
* 微服务单元测试常量定义
* @author: zyf
* @date: 2022/04/21
*/
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";
}

View File

@ -0,0 +1,62 @@
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;
/**
* RabbitMqClient发送消息
* @author: zyf
* @date: 2022/04/21
*/
@RestController
@RequestMapping("/sys/test")
@Api(tags = "【微服务】MQ单元测试")
public class JeecgMqTestController {
@Autowired
private RabbitMqClient rabbitMqClient;
/**
* 测试方法快速点击发送MQ消息
* 观察三个接受者如何分配处理消息HelloReceiver1、HelloReceiver2、HelloReceiver3会均衡分配
*
* @param req
* @return
*/
@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发送消息成功");
}
}

View File

@ -0,0 +1,30 @@
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;
/**
* 消息处理器【发布订阅】
* @author: zyf
* @date: 2022/04/21
*/
@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);
}
}
}

View File

@ -0,0 +1,62 @@
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;
/**
* 定义接收者可以定义N个接受者消息会均匀的发送到N个接收者中
*
* RabbitMq接受者1
* @RabbitListener声明类上一个类只能监听一个队列
* @author: zyf
* @date: 2022/04/21
*/
@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();
log.info("【我是处理人1】 MQ Receiver1orderId : " + 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();
}
}
});
}
}

View File

@ -0,0 +1,40 @@
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;
/**
* 定义接收者可以定义N个接受者消息会均匀的发送到N个接收者中
*
* RabbitMq接受者2
* @RabbitListener声明类上一个类只能监听一个队列
* @author: zyf
* @date: 2022/04/21
*/
@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("【我是处理人2】 MQ Receiver2orderId : " + orderId);
}
});
}
}

View File

@ -0,0 +1,38 @@
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;
/**
* 定义接收者可以定义N个接受者消息会均匀的发送到N个接收者中
*
* RabbitMq接受者3【我是处理人3】
* @RabbitListener声明类方法上一个类可以多监听多个队列
* @author: zyf
* @date: 2022/04/21
*/
@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("【我是处理人3】MQ Receiver3orderId : " + orderId);
}
});
}
}

View File

@ -0,0 +1,39 @@
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;
/**
* 定义接收者可以定义N个接受者消息会均匀的发送到N个接收者中
* @author: zyf
* @date: 2022/04/21
*/
@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 Receiver1orderId : " + orderId);
}
});
}
}