当侦听器使用时从 RabbitMQ 中删除消息。无法确定 ReplyTo 消息异常
Remove message from RabbitMQ when consumed by listener. Cannot determine ReplyTo message exception
使用 SpringBoot。
我创建了一个 TopicExchange,它接受消息并根据消息中存在的 routingKey 将它们定向到两个队列。
消息发送方式:
rabbitTemplate.convertAndSend('in-out-topic', 'inbound.queue.route.key', payload)
收到消息:
@RabbitListener(queues = "inbound-queue")
def onInboundMessage(def message) {
try {
log.debug("Received inbound message: ${message.messageId} on inbound queue listener", message)
} catch (Exception ex) {
log.error("Inbound message exception: ${ex.getMessage()}")
return;
}
return message.payload
}
但是当我的听众(消费者)收到一条消息时,我得到以下异常:
org.springframework.amqp.AmqpException: Cannot determine ReplyTo message property value: Request message does not contain reply-to property, and no default response Exchange was set.
- 我应该通过 RabbitMQ 仪表板创建虚拟响应交换吗?
- 硬编码不存在的回复属性?
- 以某种方式配置现有的 topicExchange 或队列?
我只希望消息在被我的消息侦听器使用时从相应的队列中删除。
你的问题出在方法的最后,在这里:
return message.payload
如果您真的不打算发送回复并且我们确实通过 convertAndSend()
看到了这一点,那么您不应该 return 来自 @RabbitListener
方法的任何内容。否则,正如您遇到的那样,来自这种方法的 return 被视为尝试发送回复。
在参考手册中查看更多信息:https://docs.spring.io/spring-amqp/docs/2.0.3.RELEASE/reference/html/_reference.html#async-annotation-driven。注意Reply Management
段。
使用 SpringBoot。
我创建了一个 TopicExchange,它接受消息并根据消息中存在的 routingKey 将它们定向到两个队列。
消息发送方式:
rabbitTemplate.convertAndSend('in-out-topic', 'inbound.queue.route.key', payload)
收到消息:
@RabbitListener(queues = "inbound-queue")
def onInboundMessage(def message) {
try {
log.debug("Received inbound message: ${message.messageId} on inbound queue listener", message)
} catch (Exception ex) {
log.error("Inbound message exception: ${ex.getMessage()}")
return;
}
return message.payload
}
但是当我的听众(消费者)收到一条消息时,我得到以下异常:
org.springframework.amqp.AmqpException: Cannot determine ReplyTo message property value: Request message does not contain reply-to property, and no default response Exchange was set.
- 我应该通过 RabbitMQ 仪表板创建虚拟响应交换吗?
- 硬编码不存在的回复属性?
- 以某种方式配置现有的 topicExchange 或队列?
我只希望消息在被我的消息侦听器使用时从相应的队列中删除。
你的问题出在方法的最后,在这里:
return message.payload
如果您真的不打算发送回复并且我们确实通过 convertAndSend()
看到了这一点,那么您不应该 return 来自 @RabbitListener
方法的任何内容。否则,正如您遇到的那样,来自这种方法的 return 被视为尝试发送回复。
在参考手册中查看更多信息:https://docs.spring.io/spring-amqp/docs/2.0.3.RELEASE/reference/html/_reference.html#async-annotation-driven。注意Reply Management
段。