Last active
March 28, 2024 05:27
-
-
Save mieky/fd8d9cc1973a075358526581d1d4a998 to your computer and use it in GitHub Desktop.
Publish a JSON payload into a local RabbitMQ HTTP API
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Publish JSON payloads into a RabbitMQ HTTP API with curl and jq. | |
# Usage: rabbit_publish.sh exchange_name '{ "data": "my json payload" }' | |
# | |
# To install prequisites on macOS: | |
# brew install rabbitmq jq | |
# rabbitmq-plugins enable rabbitmq_management | |
if [ $# -ne 2 ]; then | |
echo "Usage: $0 <exchange> <payload>" | |
exit 1 | |
fi | |
EXCHANGE=$1 | |
API_URL="http://localhost:15672/api/exchanges/%2f/$EXCHANGE/publish" | |
PAYLOAD=$(echo $2 | jq -R) | |
curl -u guest:guest -X POST -H 'Content-Type: application/json' -d "$(cat << EOF | |
{ | |
"properties": { | |
"content_type": "application/json", | |
"headers": {} | |
}, | |
"routing_key": "", | |
"payload": $PAYLOAD, | |
"payload_encoding": "string" | |
} | |
EOF | |
)" $API_URL |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment