DEV Community

Chrysovalanto Kousetti
Chrysovalanto Kousetti

Posted on

10 1

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

Hostinger image

Get n8n VPS hosting 3x cheaper than a cloud solution

Get fast, easy, secure n8n VPS hosting from $4.99/mo at Hostinger. Automate any workflow using a pre-installed n8n application and no-code customization.

Start now

Top comments (0)

Heroku

This site is powered by Heroku

Heroku was created by developers, for developers. Get started today and find out why Heroku has been the platform of choice for brands like DEV for over a decade.

Sign Up

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay