当侦听器使用消息时,从 RabbitMQ 中删除消息。无法确定 ReplyTo 消息异常

Man*_*ark 2 rabbitmq spring-amqp

使用SpringBoot。

我创建了一个 TopicExchange,它接受消息并根据消息中存在的routingKey 将它们定向到两个队列。

消息通过以下方式发送:

rabbitTemplate.convertAndSend('in-out-topic', 'inbound.queue.route.key', payload)
Run Code Online (Sandbox Code Playgroud)

收到消息:

 @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
  }
Run Code Online (Sandbox Code Playgroud)

但是当我的侦听器(消费者)收到消息时,我收到以下异常:

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.
Run Code Online (Sandbox Code Playgroud)
  • 我应该通过 RabbitMQ 仪表板创建虚拟响应交换吗?
  • 对不存在的replyTo属性进行硬编码?
  • 以某种方式配置现有的 topicExchange 或 Queues?

我只是希望消息在被消息侦听器使用时从相应的队列中删除。

Art*_*lan 8

Your problem is in the end of method, here:

\n\n
return message.payload\n
Run Code Online (Sandbox Code Playgroud)\n\n

如果您确实不打算发送回复,并且我们确实通过预期看到了这一点convertAndSend(),那么您不应该\xe2\x80\x99t 从@RabbitListener。否则,正如您所经历的那样,此类方法的返回将被视为尝试发送回复。

\n\n

请参阅参考手册中的更多信息:https://docs.spring.io/spring-amqp/docs/2.0.3.RELEASE/reference/html/_reference.html#async-annotation-driven。注意Reply Management paragraph.

\n