Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

RabbitMQ REST HTTP JSON payload

I am trying to use RabbitMQ HTTP REST client to publish messages into the queue. I am using the following url and request

http://xxxx/api/exchanges/xxxx/exc.notif/publish

{
 "routing_key":"routing.key",
  "payload":{

  },
 "payload_encoding":"string",
 "properties":{
   "headers":{
     "notif_d":"TEST",
     "notif_k": ["example1", "example2"],
     "userModTime":"timestamp"
   }
 }
}

And getting back from the rabbit the following response:

{"error":"bad_request","reason":"payload_not_string"}

I have just one header set:

Content-Type:application/json

I was trying to set the

"payload_encoding":"base64",

but it didn't help. I am new to rabbit any response is welcome.

like image 241
shippi Avatar asked Jul 04 '17 11:07

shippi


2 Answers

Working example. We need simple to escape doublequotes. It is important that the colon is outside of the quotes, as this causes inexplicable errors.

{
    "properties": {},
    "routing_key": "q_testing",
    "payload": "{
        \"message\": \"message from terminal\"
    }",
    "payload_encoding": "string"
}
like image 54
Druta Ruslan Avatar answered Sep 27 '22 19:09

Druta Ruslan


I managed to send content-type using underscore "_" instead of dash.

See here for list of valid properties. See RabbitMQ Management HTTP API for some examples.

To publish a json message using curl to rabbit exchange:

curl -i -u guest:guest -XPOST --data '{"properties":\
{"content_type":"application/json"}, \
"routing_key":"", \
"payload":"{\"foo\":\"bar\"}",\
"payload_encoding":"string"}' \
"http://localhost:15672/api/exchanges/%2f/exchange_name/publish"

content_type is written using underscore, routing_key is empty to send a message to exchange, not to particular queue.

like image 23
Evgeny Cheryomushkin Avatar answered Sep 27 '22 18:09

Evgeny Cheryomushkin