赞
踩
org.springframework.amqp.rabbit.listener.adapter.AbstractAdaptableMessageListener#doHandleResult
org.springframework.amqp.rabbit.listener.adapter.AbstractAdaptableMessageListener#getReplyToAddress
@Override
@RabbitListener(queues="queue_n")
public void topicManyReceive(Message msg, Channel channel) throws IOException {
try {
logger.info("接收成功--Topic交换机queue_n: {}", msg);
channel.basicAck(msg.getMessageProperties().getDeliveryTag(), false);
} catch(Exception e) {
channel.basicNack(msg.getMessageProperties().getDeliveryTag(), false, true);
logger.info("接收失败: {}", e);
}
}
rabbitmq:
host: 192.168.1.5
port: 5672
username: xindaqi
password: 123456
publisher-returns: true
listener:
direct:
acknowledge-mode: auto
simple:
acknowledge-mode: auto
concurrency: 1 # 当前监听容器数
max-concurrency: 1 # 最大监听数
#retry:
# enabled: true # 支持重试
@Override
@RabbitListener(queues="queue_n")
public void topicManyReceive(Message msg, Channel channel) throws IOException {
try {
logger.info("接收成功--Topic交换机queue_n: {}", msg);
} catch(Exception e) {
logger.info("接收失败: {}", e);
}
}
(2)手动确认
配置信息:
rabbitmq:
host: 192.168.1.5
port: 5672
username: xindaqi
password: 123456
publisher-returns: true
listener:
direct:
acknowledge-mode: manual
simple:
acknowledge-mode: manual
concurrency: 1 # 当前监听容器数
max-concurrency: 1 # 最大监听数
#retry:
# enabled: true # 支持重试
监听消息:
@Override
@RabbitListener(queues="queue_n")
public void topicManyReceive(Message msg, Channel channel) throws IOException {
try {
logger.info("接收成功--Topic交换机queue_n: {}", msg);
channel.basicAck(msg.getMessageProperties().getDeliveryTag(), false);
} catch(Exception e) {
channel.basicNack(msg.getMessageProperties().getDeliveryTag(), false, true);
logger.info("接收失败: {}", e);
}
}
【参考文献】
[1]https://blog.csdn.net/qq_15071263/article/details/99976534
[2]https://blog.csdn.net/chenzt8812/article/details/100630565/
[3]https://blog.csdn.net/wxb880114/article/details/105854584
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。