-1

I am using java client of

https://www.rabbitmq.com/tutorials/tutorial-six-java.html

. My setup is RPC. My server is creating queue and client is also creating same queue and sending the message. After receiving message server is performing some operation and sending result back to client.

Now if server created the queue and connect with it while queue get's deleted for some reason. The server is not throwing any exception and when the client is creating the same queue and putting messages server is not getting those messages either as it's not connected.

How do server knows that the queue get deleted?

Thanks so much

Asad
  • 2,782
  • 2
  • 16
  • 17
  • I have no idea what you are asking with this question. If the queue gets deleted, you re-declare it the same way you did originally. Beyond that, the relevance of the question text compared to the title is dubious. – theMayer Jan 31 '18 at 17:32
  • Thanks for your reply. I updated it. How do server knows that the queue get deleted? – Asad Jan 31 '18 at 17:54
  • The message server? Or the consumer of the queue? – theMayer Jan 31 '18 at 18:05
  • The consumer of Queue. Ideally if the queue get deleted the consumer should exit but in RPC after queue get deleted the consumer is not exiting – Asad Jan 31 '18 at 18:08
  • 1
    If you're wondering what happens if you delete a queue with an active consumer, I honestly don't know, because that usually would be considered to be a bad thing to do. But I would imagine that the consumer would get a cancellation notice and be disconnected. – theMayer Jan 31 '18 at 18:08
  • I agree with you but for RPC that's not happening. The consumer is still waiting. – Asad Jan 31 '18 at 18:10

1 Answers1

1

It sounds like the following situation is happening:

  1. Queue A is created.
  2. Consumer 1 subscribes to Queue A
  3. Queue A is deleted while Consumer 1 is still active
  4. Queue A is re-created (call it A')

Now, you're wondering why Consumer 1 is not getting any messages? You would have to re-subscribe your consumer. I don't usually delete queues, because there is no need to do so under any reasonable scenario (instead, use the queue.expires property to handle auto-deletion of queues).

According to the AMQP 0-9-1 Specification,

When a queue is deleted any pending messages are sent to a dead-letter queue if this is defined in the server configuration, and all consumers on the queue are cancelled.

So, based on the description of the behavior, this is a bug with the consumer. It should throw an exception or otherwise exit the consuming loop in this case. In any case, you'll have to re-subscribe to A' before you'll get any more messages.

theMayer
  • 15,456
  • 7
  • 58
  • 90
  • Nicely explained but I figure out there is a way to handle this kind of situation in Java. Explained here https://www.rabbitmq.com/consumer-cancel.html – Asad Jan 31 '18 at 18:34
  • 1
    Well, you linked to the article that explains what it means to cancel a consumer. My answer tells you that is what is happening, it's up to you to understand what the implications of that are :) – theMayer Jan 31 '18 at 19:37