How to push json file message to queue.

789 views
Skip to first unread message

victor fienkelstein

unread,
Apr 11, 2021, 6:05:25 AM4/11/21
to rabbitmq-users
I  have a JSON file that contains messages from the queue which I have generated by using the below command:

curl -u user:pass -H "content-type:application/json" -XPOST http://192.168.178.23:15672/api/queues/testvhost/testQueue/get -d'{"count":5,"ackmode":"ack_requeue_true","encoding":"auto","truncate":50000}' -o m1.json

I want  to know how to push this file to write messages in another queue using curl.


ThankYou.

Matthew Tice

unread,
Apr 11, 2021, 10:16:50 AM4/11/21
to rabbitm...@googlegroups.com
According to the API docs you'll need to take the contents of `m1.json` and provide it to the `payload` key:

{"properties":{},"routing_key":"my key","payload":"my body","payload_encoding":"string"}

If you want the entire contents of `m1.json` in that single message then maybe the best way is to base64 encode the contents and use that in the `payload`.

e.g.

$ cat /tmp/m1.json
{
 "foo": "bar"
}

$ base64 /tmp/m1.json
ewogImZvbyI6ICJiYXIiCn0K

$ curl -X POST -d '{"properties":{},"routing_key":"my key","payload":"ewogImZvbyI6ICJiYXIiCn0K","payload_encoding":"base64"}' http://rmq_host:5556/api/exchanges/vhost/name/publish


--
You received this message because you are subscribed to the Google Groups "rabbitmq-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rabbitmq-user...@googlegroups.com.
To view this discussion on the web, visit https://groups.google.com/d/msgid/rabbitmq-users/af83f249-74a5-4978-98f4-8bf17de0c2e3n%40googlegroups.com.

victor fienkelstein

unread,
Apr 12, 2021, 12:24:03 AM4/12/21
to rabbitm...@googlegroups.com
Hey Matthew, 
I am trying something like this,

Let's say I have two queues i.e. queue1 and queue2. I have messages in queue1 which I stored in a JSON file by using the following command.
curl -u user:pass -H "content-type:application/json" -XPOST http://192.168.178.23:15672/api/queues/testvhost/queue1/get -d'{"count":5,"ackmode":"ack_requeue_true","encoding":"auto","truncate":50000}' -o m1.json

with the help of this post:- RabbitMQ - Get messages from a queue using curl

My JSON file looks like this:- https://paste-me.net/fibed

I am trying to push this JSON file (messages) to another queue queue2 with the help of the following command:

 curl -i -u user:pass -H "Accept: application/json" -H "Content-Type:application/json" -X POST -d @m1.json http://192.168.178.23:15672/api/exchanges/testvhost/queue2/publish
HTTP/1.1 500 Internal Server Error
content-length: 0


Reply all
Reply to author
Forward
0 new messages