Rabbitmq - Get Messages from a Queue Using Curl

RabbitMQ - Get messages from a queue using curl

I managed to solve the problem. The key:

I have no vhost configured.

RabbitMQ uses the "/" notation for the default VHOST.

Sample Image

"/" is translated to %2F in HTTP...

So the correct call is:

curl -u guest:guest -i -H "content-type:application/json" -X POST http://127.0.0.1:15672/api/queues/%2F/foo/get -d'{"count":5,"requeue":true,"encoding":"auto","truncate":50000}' 

Curl to get Rabbitmq queue size

Finally I did the trick with the following:

curl -s -i -u guest:guest http://host:port/api/queues/vhost/queue_name | sed 's/,/\n/g' | grep '"messages"' | sed 's/"messages"://g'

Sending a persistent message in RabbitMQ via HTTP API

delivery_mode is a properties, so you have to put it inside the "properties" as:

curl -u guest:guest -H "content-type:application/json" -X POST -d'{"properties":{"delivery_mode":2},"routing_key":"QueueName","payload":"HI","payload_encoding":"string"}' http://localhost:15672/api/exchanges/%2f/amq.default/publish

RabbitMQ: How to delete/move messages in queue from curl

The answer for my question is found at

https://groups.google.com/d/msg/rabbitmq-users/IS-3v4qNduw/oPseA7VxEgAJ

curl send JSON payload

The RabbitMQ team monitors this mailing list and only sometimes answers questions on StackOverflow.


The error you see is correct, your payload is not a string. I had to reproduce this and re-visit the HTTP API docs for this to become clear.

The value you are passing to the payload key in your JSON is more JSON - in order for it to be a string, you must escape it correctly and pass it like this:

$ curl -4vvv -u guest:guest -H 'Content-Type: application/json' localhost:15672/api/exchanges/%2f/amq.topic/publish --data-binary '{
"properties": {
"delivery_mode": 2,
"content_type": "application/json"
},
"routing_key": "git",
"payload":"{\"action\":\"created\",\"comment\":{\"url\":\"https://api.github.com/repos/baxterthehacker/public-repo/comments/11056394\",\"id\":11056394}}",
"payload_encoding": "string"
}'

The other alternative is to base-64 encode the JSON from GitHub and pass that as the payload - you won't have to escape anything if you do that.



Related Topics



Leave a reply



Submit