views:

54

answers:

1

I have Created a RabbitMQ Producer and a RabbitMQ Consumer....

suppose my producer produces 10 messages. How can i get a particular message from those 10 messages.

I want to know how can i uniquely identify a message and read that or consume that message.

A: 

There are several ways to do this, but the one I use most is to use a routing key that is unique to the type of message. Consumers, then, bind to that exchange using a specific routing key, which causes messages to go only to those consumers.

If you can avoid it, you should never just dump messages into a single queue and let the consumers sort them out. The routing keys and exchanges are powerful tools made specifically for routing messages. You should leverage that.

J. Brisbin
Brisbin thanks for replying to the question. Well i m already aware of what you are saying. But i have got this wierd requirement. This is what i am trying to do : when a producer publishes a message (assume he has already published 5 messages) we should inform the publisher that how his each message can be identified uniquely. And when the publisher asks for a particular message he has published through the unique identifier which we had provided him..the message should be displayed to him so that if he want he can edit it and publish a new message.
Jigar Sheth
First we bind the exchange,queue and routing keyeg: ch.QueueBind("queue", "exch", "key2", false, null);When you publish a message you mention exchange, routing key,basicproperties,messagebody..for eg: ch.BasicPublish("exch", "key2", null, messagebody1);And while you consume the message you only mention the queue name.eg : BasicGetResult result = ch.BasicGet("queue", noAck);Now above statement will consume all message in the queue..my problem is what if i want to consume a particular message from the queue based on routing key.
Jigar Sheth