How to publish Json using rabbitmqadmin command

6.1k views Asked by At

I want to publish Json message using rabbitmqadmin command line. How can we do that as i was reading we can send only string message in payload like below rabbitmqadmin publish exchange=default routing_key=test payload="hello, world".

But I wanted to send something like this: rabbitmqadmin publish exchange=default routing_key=test payload=file.json

How can we do this in command line?

2

There are 2 answers

1
Gabriele Santomaggio On

There is not an "API" but you can do it in this way:

python rabbitmqadmin publish \
       exchange=amq.default routing_key=test \
       payload="$(cat myjson.json)"

I tried it:

➜  bash python rabbitmqadmin publish \ 
        exchange=amq.default routing_key=test \
        payload="$(cat myjson.json)"

   Message published
0
grahamrhay On

this may depend on the library you're using at the other end, but to get the msg processed correctly (it was a string otherwise), I needed more:

./rabbitmqadmin publish exchange=foo routing_key=foo.bar.baz \
    properties='{"content_type":"application/json"}' \
    payload='{}' payload_encoding='string'

Note content_type with an underscore.