2

Using SpringBoot.

I have created an TopicExchange which accepts messages and directs them to two queues based on a routingKey present in the message.

Messages are sent via :

rabbitTemplate.convertAndSend('in-out-topic', 'inbound.queue.route.key', payload)

Messages are received:

 @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
  }

But when my listener (consumer) receives a message I get the following exception:

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.
  • Should I create a dummy response exchange via RabbitMQ dashboard?
  • Hardcode a non existent replyTo property?
  • Configure the existing topicExchange or Queues somehow?

I just want the message being removed from the corresponding queue when consumed by my message listener.

1 Answer 1

9

Your problem is in the end of method, here:

return message.payload

If you really are not going to send reply and we indeed see that by expectations via convertAndSend(), then you shouldn’t return anything from the @RabbitListener method. Otherwise, as you are experiencing, the return from such a method is treated as an attempt to send a reply.

See more info in the Reference Manual: https://docs.spring.io/spring-amqp/docs/2.0.3.RELEASE/reference/html/_reference.html#async-annotation-driven. Pay attention to the Reply Management paragraph.

Sign up to request clarification or add additional context in comments.

2 Comments

If exception occurs in my local listener then I still get the aforementioned error. So if I get an invalid message, upon exception it will be requeued by default and then again sent to my listener. Because I don't wont to loose messages, I should then manually remove the message from the queue causing the exceptions locally? Or configure some sort of queue for such messages? Then I would need the reply-to property set?
@RabbitListener annotation has two new attributes: errorHandler and returnExceptions that will do. Thanks!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.