DEV Community 👩‍💻👨‍💻

Chrysovalanto Kousetti
Chrysovalanto Kousetti

Posted on

Sending a RabbitMQ message with JSON payload using curl

If you are working with RabbitMQ in a deployed environment you will often not have access to the RabbitMQ web UI which allows you to send test messages to try things out. Here is an example curl you can use adapting it to your needs to send a JSON payload message via RabbitMQ.

Things to replace:

  • USERNAME: The RabbitMQ user's username
  • USERPASSWORD: The RabbitMQ user's password
  • QUEUE_NAME: The queue to publish to
  • ENCODED_JSON_PAYLOAD: The JSON payload. Make sure this is stringified (I just do a quick javascript console: JSON.stringify({"my_json": "payload"}) that does the trick)
curl -s -u USERNAME:USERPASSWORD -H "Accept: application/json" -H "Content-Type:application/json" -X POST -d'{
    "vhost": "/",
    "name": "amq.direct",
    "properties": {
        "delivery_mode": 2,
        "headers": {}
    },
    "routing_key": "QUEUE_NAME",
    "delivery_mode": "1",
    "payload":"ENCODED_JSON_PAYLOAD",
    "headers": {},
    "props": {},
    "payload_encoding": "string"
}' http://localhost:15672/api/exchanges/%2F/amq.direct/publish


Enter fullscreen mode Exit fullscreen mode

Top comments (0)

About Real-time

Join DEV and MongoDB to build a front-end application using MongoDB Atlas. Change streams to display live updates as your database changes for your entry in the DEV x MongoDB Atlas Hackathon 2022.

Join the Hackathon