|
|
@ -29,34 +29,39 @@ import java.util.List;
|
|
|
|
@ConditionalOnProperty(name = "austin.mq.pipeline", havingValue = MessageQueuePipeline.RABBIT_MQ)
|
|
|
|
@ConditionalOnProperty(name = "austin.mq.pipeline", havingValue = MessageQueuePipeline.RABBIT_MQ)
|
|
|
|
public class RabbitMqReceiver implements MessageReceiver {
|
|
|
|
public class RabbitMqReceiver implements MessageReceiver {
|
|
|
|
|
|
|
|
|
|
|
|
private static final String MSG_TYPE_SEND = "send";
|
|
|
|
|
|
|
|
private static final String MSG_TYPE_RECALL = "recall";
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Autowired
|
|
|
|
@Autowired
|
|
|
|
private ConsumeService consumeService;
|
|
|
|
private ConsumeService consumeService;
|
|
|
|
|
|
|
|
|
|
|
|
@RabbitListener(bindings = @QueueBinding(
|
|
|
|
@RabbitListener(bindings = @QueueBinding(
|
|
|
|
value = @Queue(value = "${spring.rabbitmq.queues}", durable = "true"),
|
|
|
|
value = @Queue(value = "${spring.rabbitmq.queues.send}", durable = "true"),
|
|
|
|
exchange = @Exchange(value = "${austin.rabbitmq.exchange.name}", type = ExchangeTypes.TOPIC),
|
|
|
|
exchange = @Exchange(value = "${austin.rabbitmq.exchange.name}", type = ExchangeTypes.TOPIC),
|
|
|
|
key = "${austin.rabbitmq.routing.key}"
|
|
|
|
key = "${austin.rabbitmq.routing.send}"
|
|
|
|
))
|
|
|
|
))
|
|
|
|
public void onMessage(Message message) {
|
|
|
|
public void send(Message message) {
|
|
|
|
String messageType = message.getMessageProperties().getHeader("messageType");
|
|
|
|
|
|
|
|
byte[] body = message.getBody();
|
|
|
|
byte[] body = message.getBody();
|
|
|
|
String messageContent = new String(body, StandardCharsets.UTF_8);
|
|
|
|
String messageContent = new String(body, StandardCharsets.UTF_8);
|
|
|
|
if (StringUtils.isBlank(messageContent)) {
|
|
|
|
if (StringUtils.isBlank(messageContent)) {
|
|
|
|
return;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (MSG_TYPE_SEND.equals(messageType)) {
|
|
|
|
// 处理发送消息
|
|
|
|
// 处理发送消息
|
|
|
|
List<TaskInfo> taskInfoLists = JSON.parseArray(messageContent, TaskInfo.class);
|
|
|
|
List<TaskInfo> taskInfoLists = JSON.parseArray(messageContent, TaskInfo.class);
|
|
|
|
consumeService.consume2Send(taskInfoLists);
|
|
|
|
consumeService.consume2Send(taskInfoLists);
|
|
|
|
}
|
|
|
|
} else if (MSG_TYPE_RECALL.equals(messageType)) {
|
|
|
|
|
|
|
|
// 处理撤回消息
|
|
|
|
|
|
|
|
RecallTaskInfo recallTaskInfo = JSON.parseObject(messageContent, RecallTaskInfo.class);
|
|
|
|
|
|
|
|
consumeService.consume2recall(recallTaskInfo);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@RabbitListener(bindings = @QueueBinding(
|
|
|
|
|
|
|
|
value = @Queue(value = "${spring.rabbitmq.queues.recall}", durable = "true"),
|
|
|
|
|
|
|
|
exchange = @Exchange(value = "${austin.rabbitmq.exchange.name}", type = ExchangeTypes.TOPIC),
|
|
|
|
|
|
|
|
key = "${austin.rabbitmq.routing.recall}"
|
|
|
|
|
|
|
|
))
|
|
|
|
|
|
|
|
public void recall(Message message) {
|
|
|
|
|
|
|
|
byte[] body = message.getBody();
|
|
|
|
|
|
|
|
String messageContent = new String(body, StandardCharsets.UTF_8);
|
|
|
|
|
|
|
|
if (StringUtils.isBlank(messageContent)) {
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
// 处理撤回消息
|
|
|
|
|
|
|
|
RecallTaskInfo recallTaskInfo = JSON.parseObject(messageContent, RecallTaskInfo.class);
|
|
|
|
|
|
|
|
consumeService.consume2recall(recallTaskInfo);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|