3

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?

vikash kumar
  • 89
  • 3
  • 9

2 Answers2

3

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.

Roger Lipscombe
  • 89,048
  • 55
  • 235
  • 380
grahamrhay
  • 2,046
  • 4
  • 19
  • 29
1

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
Behrang
  • 46,888
  • 25
  • 118
  • 160
Gabriele Santomaggio
  • 21,656
  • 4
  • 52
  • 52
  • It's strange that reading payload from file isn't supported. I noticed that if payload json is large the command reports the error: /usr/bin/rabbitmqadmin: Argument list too long – ka3ak Oct 11 '22 at 05:38