This commit is contained in:
张良(004796)
2024-04-12 10:52:00 +08:00
parent fe413d0c99
commit 4d10fe5611
34 changed files with 246 additions and 212 deletions

View File

@@ -0,0 +1,36 @@
package com.ruoyi.consumer;
import com.ruoyi.cai.mq.constant.CalculateSalesQueueHttpMqConstant;
import com.ruoyi.cai.service.ConsumeLogService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.rabbit.annotation.Exchange;
import org.springframework.amqp.rabbit.annotation.Queue;
import org.springframework.amqp.rabbit.annotation.QueueBinding;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
@Component
@Slf4j
public class CalculateSalesQueueConsumer {
@Autowired
private ConsumeLogService consumeLogService;
@RabbitListener(bindings = @QueueBinding(
value = @Queue(value = CalculateSalesQueueHttpMqConstant.CALCULATE_SALES_QUEUE, durable = "false", autoDelete = "false"),
exchange = @Exchange(value = CalculateSalesQueueHttpMqConstant.CALCULATE_SALES_EXCHANGE),
key = CalculateSalesQueueHttpMqConstant.CALCULATE_SALES_KEY)
,containerFactory = "customContainerFactory")
public void calculateSalesQueue(String message) {
log.info("接受到到分销处理请求: message=" + message);
try {
consumeLogService.dealFenxiao(Long.valueOf(message),true);
}catch (Exception e){
log.error("处理分销失败: message=" + message,e);
}
log.info("分销处理完成: message=" + message);
}
}

View File

@@ -0,0 +1,41 @@
package com.ruoyi.consumer;
import com.alibaba.fastjson2.JSON;
import com.alibaba.fastjson2.JSONObject;
import com.ruoyi.cai.mq.config.HandleConfig;
import com.ruoyi.cai.mq.constant.CommonHttpMqConstant;
import com.ruoyi.cai.mq.handle.IHandle;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.rabbit.annotation.Exchange;
import org.springframework.amqp.rabbit.annotation.Queue;
import org.springframework.amqp.rabbit.annotation.QueueBinding;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
@Component
@Slf4j
public class CommonConsumer {
@Autowired
private HandleConfig handleConfig;
@RabbitListener(bindings = @QueueBinding(
value = @Queue(value = CommonHttpMqConstant.COMMON_QUEUE, durable = "false", autoDelete = "false"),
exchange = @Exchange(value = CommonHttpMqConstant.COMMON_EXCHANGE),
key = CommonHttpMqConstant.COMMON_KEY)
,containerFactory = "customContainerFactory")
public void calculateSalesQueue(String message) {
log.info("队列消息处理-开始: message=" + message);
try {
JSONObject object = JSON.parseObject(message);
String type = object.getString("type");
IHandle handle = handleConfig.getHandle(type);
handle.run(message);
}catch (Exception e){
log.error("队列消息处理-失败: message=" + message,e);
}
log.info("队列消息处理-结束: message=" + message);
}
}

View File

@@ -0,0 +1,33 @@
package com.ruoyi.consumer;
import com.alibaba.fastjson2.JSON;
import com.alibaba.fastjson2.JSONObject;
import com.ruoyi.cai.mq.config.HandleDelayConfig;
import com.ruoyi.cai.mq.constant.CommonDelayHttpMqConstant;
import com.ruoyi.cai.mq.handleDelay.IHandleDelay;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
@Slf4j
@Component
public class CommonDelayMqConsumer {
@Autowired
private HandleDelayConfig handleDelayConfig;
@RabbitListener(queues = CommonDelayHttpMqConstant.QUEUE_NAME
,containerFactory = "customContainerFactory")
public void checkTimeOutMq(String message) {
log.info("公共延时队列消息处理-开始: message=" + message);
try {
JSONObject object = JSON.parseObject(message);
String type = object.getString("type");
IHandleDelay handle = handleDelayConfig.getHandle(type);
handle.run(message);
}catch (Exception e){
log.error("公共延时队列消息处理-失败: message=" + message,e);
}
log.info("公共延时队列消息处理-结束: message=" + message);
}
}

View File

@@ -0,0 +1,41 @@
package com.ruoyi.consumer;
import com.alibaba.fastjson2.JSON;
import com.alibaba.fastjson2.JSONObject;
import com.ruoyi.cai.mq.config.HandleConfig;
import com.ruoyi.cai.mq.constant.WindowHttpMqConstant;
import com.ruoyi.cai.mq.handle.IHandle;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.rabbit.annotation.Exchange;
import org.springframework.amqp.rabbit.annotation.Queue;
import org.springframework.amqp.rabbit.annotation.QueueBinding;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
@Component
@Slf4j
public class WindowConsumer {
@Autowired
private HandleConfig handleConfig;
// ,containerFactory = "customContainerFactory"
@RabbitListener(bindings = @QueueBinding(
value = @Queue(value = WindowHttpMqConstant.WINDOW_QUEUE, durable = "false", autoDelete = "false"),
exchange = @Exchange(value = WindowHttpMqConstant.WINDOW_EXCHANGE),
key = WindowHttpMqConstant.WINDOW_KEY))
public void calculateSalesQueue(String message) {
log.info("飘窗检测-开始: message=" + message);
try {
JSONObject object = JSON.parseObject(message);
String type = object.getString("type");
IHandle handle = handleConfig.getHandle(type);
handle.run(message);
}catch (Exception e){
log.error("飘窗检测-失败: message=" + message,e);
}
log.info("飘窗检测-结束: message=" + message);
}
}

View File

@@ -1,6 +1,6 @@
package com.ruoyi.web.controller.cai.admin.init;
import com.ruoyi.cai.mq.AmqpProducer;
import com.ruoyi.cai.mq.AmqpHttpProducer;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
@@ -15,15 +15,10 @@ import org.springframework.web.bind.annotation.RestController;
public class MqControllerTest {
@Autowired
private AmqpProducer amqpProducer;
@GetMapping("/send")
public void send(String message,Integer time){
amqpProducer.sendRoomSettleDelay(message,time);
}
private AmqpHttpProducer amqpHttpProducer;
@GetMapping("/send2")
public void send(String message){
amqpProducer.sendCalculateSales(message);
amqpHttpProducer.sendCalculateSales(message);
}
}