Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

AMQP - Does the consumer have acess to the routing key?

Tags:

c

rabbitmq

amqp

I've set up a topic exchange such that the consumer queue is bound with "#.topic". I'd like to use different acknowledgement strategies based on the prefix. Is the full routing key sent to the consumer? If so, how do I access it? An answer in terms of AMQP concepts would probably be sufficient, but an answer involving rabbitmq-c would be ideal.

like image 406
Dan Hook Avatar asked Nov 19 '12 14:11

Dan Hook


1 Answers

Even when you do a binding like you have given in your example the message received contains the full routing key. This means you can extract that in order to help you process the message. Unfortunately I only know how to do this in Java so try to extrapolate from there.

QueueingConsumer.Delivery delivery = consumer.nextDelivery();
String routingKey = delivery.getEnvelope().getRoutingKey();

The delivery object contains a body which is the payload and can be retrieve with delivery.getBody() and an Envelope object which contains other information like the full routing key.

like image 197
robthewolf Avatar answered Sep 20 '22 15:09

robthewolf