RabbitMQ未确认消息处理

  • Post author:
  • Post category:其他


需要注意的是,两个回调处理的均为当前该回调的处理范围,成功的处理成功的,失败的处理失败的。实际如何用,可参考尚硅谷P37

尚硅谷2021新版RabbitMQ教程丨快速掌握MQ消息中间件_哔哩哔哩_bilibili

SortedSet<Long> confirmSet = Collections.synchronizedSortedSet(new TreeSet<Long>());

channel.confirmSelect();

channel.addConfirmListener(new ConfirmListener() {


public void handleAck(long deliveryTag, boolean multiple) throws IOException {


if (multiple) {


confirmSet.headSet(deliveryTag + 1).clear();

} else {


confirmSet.remove(deliveryTag);

}

}

public void handleNack(long deliveryTag, boolean multiple) throws IOException {


System.out.println(“Nack, SeqNo: ” + deliveryTag + “, multiple: ” + multiple);

if (multiple) {


confirmSet.headSet(deliveryTag + 1).clear();

} else {


confirmSet.remove(deliveryTag);

}

}

});

while (true) {


long nextSeqNo = channel.getNextPublishSeqNo();

channel.basicPublish(ConfirmConfig.exchangeName, ConfirmConfig.routingKey, MessageProperties.PERSISTENT_TEXT_PLAIN, ConfirmConfig.msg_10B.getBytes());

confirmSet.add(nextSeqNo);

}

相关说明可参考 https://blog.csdn.net/u013256816/article/details/55515234



版权声明:本文为u013182960原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。