Search code examples
rabbitmqmessage-queuemessaging

Get messages by property or header in RabbitMQ


I'm new in to RabbitMQ and I've faced a problem. I'm trying to get messages from queue by API method. I've made that by now I want to get messages from queue by header or property if it is possible. I read the documentation about HTTP API. I have not found such an API for filtering messages by some headers or properties.

I use that kind of API to get messages from queue:

/api/queues/vhost/name/get

and in the body:

{"count":20,"ackmode":"ack_requeue_true","encoding":"auto"}

I was thinking, maybe it is possible to somehow pass some filter in the body so it could filter and return the message what I want.

This is how my message looks like : enter image description here

I have tried to pass in the body type = "myType" or header = "myHeader"


Solution

  • I've made that by now I want to get messages from queue by header or property if it is possible.

    RabbitMQ only delivers messages in order from a queue. There is no way to filter once a message is in a queue.

    You can filter messages as they are published to an exchange, however. Use a headers exchange and bind queues based on header values. Then, each queue will contain the messages you expect and you can then consume from them.

    The RabbitMQ tutorials have a section that use a "headers exchange". Use that as a guide.

    Finally, only use the HTTP API for testing. It is a very inefficient way to retrieve messages.