RabbbitMQ配置mandatory

2022/7/26 23:29:30

本文主要是介绍RabbbitMQ配置mandatory,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!

官网文档解释:

If a message is published with the "mandatory" flags set, but cannot be routed, the broker will return it to the sending client (via an AMQP.Basic.Return command).

To be notified of such returns, clients can implement the ReturnListener interface and call Channel.addReturnListener****. If the client has not configured a return listener for a particular channel, then the associated returned messages will be silently dropped.

A return listener will be called, for example, if the client publishes a message with the "mandatory" flag set to an exchange of "direct" type which is not bound to a queue

大意为:开启强制消息投递(mandatory为设置为true),但消息未被路由至任何一个queue,则回退一条消息到生产者,通过配置ReturnListener监听未被路由的消息,如果mandatory为设置为false,那么未被路由选消息将会被丢弃。

channel.addReturnListener(new ReturnListener() {
    @Override
    public void handleReturn(int replyCode, String replyText, String exchange, String routingKey, AMQP.BasicProperties properties, byte[] body) throws IOException {

    }
});

RabbitMQ Java Client



这篇关于RabbbitMQ配置mandatory的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!


扫一扫关注最新编程教程