7

I am writing to a RabbitMQ queue with spring amqp using the RabbitTemplate class. I use the convertAndSend method to send messages to the queue. This works well under normal situations, but it seems to fail silently if the queue doesn't exist. No exception is thrown and no error/debug message is logged to the logger.

What is the best way for me to make sure the message was delivered?

Here is an example of what the code is doing currently.

RabbitTemplate template = new RabbitTemplate(factory);
template.setQueue(queueName);
template.setRoutingKey(queueName);
template.convertAndSend(message);
Eric Milas
  • 1,807
  • 2
  • 18
  • 29
  • are you absolutely sure no message is logged? Have you tried a unit test with the broker deliberately down? – artbristol Dec 12 '11 at 16:16
  • I was incorrect about the silent failure if the broker is down, I do indeed receive an UnknownHostException if the broker is down. I have updated the question. That said, I still don't receive any exception or error message if the queue doesn't exist. – Eric Milas Dec 12 '11 at 17:20
  • could you post the snippet of code where you send the message? – artbristol Dec 12 '11 at 17:23
  • I added a code example. I am guessing that I have to register some sort of listener to find out what exactly happened to the message, but I can't find any information supporting that. – Eric Milas Dec 12 '11 at 17:37
  • The problem is probably the definition on RabbitMQ. Are you sure the exchange, the routing key and the queue have the correct binding? How are you doing this setup? by hand? You can do it with Spring, if it exits it won't override the definition. My guess is that the definition is wrong. – Alejandro Diaz Dec 12 '11 at 17:49
  • Well, in my tests, the queue specifically doesn't exist. I need to make sure that if something is wrong, that I don't drop messages. – Eric Milas Dec 13 '11 at 00:58

2 Answers2

4

It's not an error for a RabbitMQ client to send a message to a broker which has no queues bound within it to accept the message. RabbitMQ will silently drop it and the client will be none the wiser. If you've no queues interested in your messages, the broker has not got many other options available to it.

That said, you can make RabbitMQ complain if the message will end up silently dropped by setting the mandatory flag. I don't know if the Spring AMQP interfaces support it, but it's certainly available in the RabbitMQ Java client library.

Brian Kelly
  • 19,067
  • 4
  • 53
  • 55
  • Thanks, I'll look into it. I'll try to get to it tomorrow, we are pretty busy right now. – Eric Milas Dec 13 '11 at 00:59
  • I don't see any way to set a mandatory flag. None of the spring-amqp objects I am using seems to have that setting. – Eric Milas Dec 16 '11 at 16:04
  • I think that my problem is that the message is considered delivered because it does arrive at the exchange. The message is just never routed to the queue because it doesn't exist. There is probably some configuration in rabbit that needs to be set up to make sure the message isn't lost. – Eric Milas Dec 16 '11 at 16:12
  • There's no configuration like that, AFAIK (other than the mandatory flag). If you haven't got a queue bound in Rabbit (or in any AMQP broker) that cares about the message, you're implicitly telling the broker that you simply don't care about the message, and it will disappear forever. – Brian Kelly Dec 16 '11 at 21:01
  • Ok, I just learned that the mandatory and immediate flags are deprecated in spring amqp and spring integration. That is why I couldn't find them. – Eric Milas Dec 16 '11 at 21:17
  • 1
    No; only the immediate flag is deprecated because it was removed from the rabbit client. – Gary Russell Apr 26 '14 at 19:52
1

You can use mandatory and also enable publisher returns (for undeliverable messages).

Gary Russell
  • 166,535
  • 14
  • 146
  • 179