This commit is contained in:
dute7liang
2024-01-26 22:44:14 +08:00
parent 97ba46f6e4
commit 35638b8664
29 changed files with 457 additions and 59 deletions

View File

@@ -0,0 +1,44 @@
package com.ruoyi.cai.mq.consumer;
import com.alibaba.fastjson2.JSON;
import com.alibaba.fastjson2.JSONObject;
import com.ruoyi.cai.mq.handle.HandleConfig;
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 {
public final static String WINDOW_QUEUE = "caiWindowQueue";
public final static String WINDOW_EXCHANGE = "caiWindowExchange";
public final static String WINDOW_KEY = "caiWindowKey";
@Autowired
private HandleConfig handleConfig;
// ,containerFactory = "customContainerFactory"
@RabbitListener(bindings = @QueueBinding(
value = @Queue(value = WINDOW_QUEUE, durable = "false", autoDelete = "false"),
exchange = @Exchange(value = WINDOW_EXCHANGE),
key = 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);
}
}