How to use curl for a RabbitMQ connection

24 September,2019 by

Question : How can I use curl to test a remote  connection to RabbitMQ? The goal is to use Apache Kafka as the end-goal for data streaming from RabbitMQ , but I just want to use a simple curl command line method to establish whether the credentials , host & port are valid. Note this is a remote connection

Answer: If you have the RabbitMQ queue name and want to return the messages in a queue this method will get the messages. Before attempting the connection ensure the host , username,password, port are all valid. Including making sure is open at the firewall

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}'

A common error message is –  there is no valid vhost

RabbitMQ uses the “/” notation for the default VHOST.

“/” is translated to %2F in HTTP. So you’ll notice in the url above %2F

There is lots of other information you can gather using curl and RabbitMQ, such as the queue size , list of virtual hosts, exchange information

If you’re planning on configuring RabbitMQ as a producer in Apache Kafka , you’ll need to plan on how you will read the JSON format and depending on  the downward consumer to translate the JSON into a Kafka topic for consumption.

Let me know if you use any other scripting methods for test connections to remote RabbitMQ queues

Author: Jack Vamvas

Leave a Reply

Discover more from ciquery

Subscribe now to keep reading and get access to the full archive.

Continue reading