【问题标题】:Spring-rabbit - ReturnCallback not triggeredSpring-rabbit - ReturnCallback 未触发
【发布时间】:2015-03-26 16:27:54
【问题描述】:

当我在交易所发布时收到 Nack 时,我在配置 ReturnCallback 时遇到问题。这是我的工作:

CachingConnectionFactory connectionFactory = new CachingConnectionFactory();
connectionFactory.setPublisherConfirms(true);
connectionFactory.setPublisherReturns(true);
...
RabbitTemplate rabbitTemplate = new RabbitTemplate(connectionFactory());
rabbitTemplate.setMandatory(true);
rabbitTemplate.setConfirmCallback(new MyMessageConfirmCallback());
rabbitTemplate.setReturnCallback(new MyMessageReturnCallback());

然后当我发布消息时,我会向不存在的交换器发送消息

notificationProducerJmsTemplate.send("idontexist.exchange",
                                     "idontexist.key",
                                      messageToSend, 
                                      correlationData);

奇怪的是,我到达了MyMessageConfirmCallback 中定义的代码,而不是MyMessageReturnCallback 中定义的代码,即使在第一个代码中ack 的值是false

我正在使用 RabbitMQ 3.4.2,这是我的 maven 依赖项:

<dependency>
    <groupId>org.springframework.amqp</groupId>
    <artifactId>spring-rabbit</artifactId>
    <version>1.4.3.RELEASE</version>
</dependency>

最后但并非最不重要的一点是,我可以在日志中看到以下错误消息:

2015-03-26 16:29:24,094 GMT [pool-21-thread-1] (CachingConnectionFactory.java:281) ERROR connection.CachingConnectionFactory: Channel shutdown: channel error; protocol method: #method<channel.close>(reply-code=404, reply-text=NOT_FOUND - no exchange 'idontexist.exchange' in vhost '/', class-id=60, method-id=40)

有人发现有问题吗?关于检查什么以找出可能阻止调用 ReturnCallback 的任何提示?

【问题讨论】:

    标签: rabbitmq spring-amqp


    【解决方案1】:

    这就是它在 Rabbit 客户端中的工作方式:AMQImpl.Close 从 Broker 启动以关闭当前的 Channel。那是因为NOT_FOUND - no exchange 'idontexist.exchange' in vhost '/' 被视为严重错误(ChannelN#processAsync):

    if (method instanceof Channel.Close) {
           asyncShutdown(command);
           return true;
    }
    

    因此我们无法从那里到达} else if (method instanceof Basic.Return) {

    PublisherCallbackChannelImpl 在这种情况下调用 handleNack,因此 - ConfirmCallback

    【讨论】:

    • 谢谢!我有点想象有类似的事情。现在的问题是“我能做些什么来测试 ReturnCallback ?”
    • 有效exchange,无效routingKey。这意味着“这个routingKey没有绑定”
    猜你喜欢
    • 2020-04-15
    • 2013-01-29
    • 2014-04-25
    • 1970-01-01
    • 1970-01-01
    • 2015-07-28
    • 2018-12-15
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多