package com.kidgrow.rabbitmq.recieve;
|
|
import com.rabbitmq.client.Channel;
|
import org.springframework.amqp.core.Message;
|
import org.springframework.amqp.rabbit.annotation.RabbitHandler;
|
import org.springframework.amqp.rabbit.annotation.RabbitListener;
|
import org.springframework.stereotype.Component;
|
|
/**
|
* 石家庄喜高科技有限责任公司 版权所有 © Copyright 2020<br>
|
*
|
* @Description: <br>
|
* @Project: <br>
|
* @CreateDate: Created in 2020/3/23 18:49 <br>
|
* @Author: <a href="4345453@kidgrow.com">liuke</a>
|
*/
|
@Component
|
@RabbitListener(queues = "AdvancedEvaluation")
|
public class TopicReceive {
|
@RabbitHandler
|
public void process(String messages, Message message, Channel channel) {
|
// 如果手动ACK,消息会被监听消费,但是消息在队列中依旧存在,如果 未配置 acknowledge-mode 默认是会在消费完毕后自动ACK掉
|
final long deliveryTag = message.getMessageProperties().getDeliveryTag();
|
try {
|
System.out.println("Topic Receiver : " + messages);
|
// 通知 MQ 消息已被成功消费,可以ACK了
|
channel.basicAck(deliveryTag, false);
|
}
|
catch (Exception e) {
|
try {
|
// 处理失败,重新压入MQ
|
channel.basicRecover();
|
} catch (Exception e1) {
|
e1.printStackTrace();
|
}
|
}
|
}
|
}
|