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
Top comments (0)