1
votes

I am quite new to using RabbitMQ as message queuing protocol.I have written a code for sender and consumer work queue as given in RabbitMQ tutorials.

[Link : http://www.rabbitmq.com/tutorials/tutorial-two-java.html ]

The above thing works fine when we start the consumer before the sender. But there is an issue if we start the consumer after running the sender. None of the messages are consumed by those consumers which are started after running the sender. After looking into the architecture of RabbitMQ and the AMQP related things,it seems quite difficult.

1] Is it possible,that we start the consumer after sender and the consumer which are started after the sender receives the messages in Queue?

2] If yes.Then how this thing can be done.Is there some technique to do the same?

2

2 Answers

2
votes

Yes, it is possible. Make sure that your queue is declared with auto-delete set to false. Once the last consumer unsubscribes if auto-delete is set to true then the queue will be deleted and when your sender pushes messages to it they will be lost. If auto-delete is set to false then the queue will continue to exist after your consumer has unsubscribed and your sender will be able to push messages to the queue without them being lost.

Find more info about queues at http://www.rabbitmq.com/tutorials/amqp-concepts.html#queues

1
votes

I suppose in the first case(starting consumer first), the consumer properly creates/registers the queue it wants to listen on the RabbitMQ server. So when sender sends it's able to receive it.

In the second case probably what's happening is sender is trying to send to a queue which is not existent/not created and goes to default/dead-letter.

I suggest you can open the RabbitMQ Management console and see whether the queues are created properly.