Publish message with headers in rabbit MQ from command prompt

7,012 views
Skip to first unread message

swetha kolalmath

unread,
Aug 4, 2016, 5:50:19 AM8/4/16
to rabbitmq-users
Hi ,

I am new to rabbit mq and I am using the below command to publish the payload into rabbit MQ queue. I am using the function publish in rabbitmqadmin.txt file

C:\Python27>python.exe D:\dev\AUTOMATION\SAT\Rabbitmq\rabbitmqadmin.txt -H localhost -u <user> -p <pass> publish exchange=<exchange> routing_key=<queuename> payload="hello, world"
Message published


The  message is getting published successfully in my queue configured.

Now i also want to add the header values(properties.header)  to the payload. How can i achieve it using the above command. ( i am aware that we can do it from rabbit mq UI but i want to do it from command line ).

Thanks 
Swetha


Gabriele Santomaggio

unread,
Aug 4, 2016, 7:01:22 AM8/4/16
to rabbitmq-users
Hi

python rabbitmqadmin publish  routing_key=my_queue payload="hello, world" properties={\"headers\":{\"myKey\":\"MyValue\"}}

Message published


-
Gabriele

swetha kolalmath

unread,
Aug 5, 2016, 2:19:50 AM8/5/16
to rabbitmq-users
Thanks Gabriele.

I am getting the below error when i am trying to publish with properties.

ERROR: Argument "properties" not recognized

rabbitmqadmin.txt --help for help

Any idea what i am missing ?

swetha kolalmath

unread,
Aug 5, 2016, 2:30:56 AM8/5/16
to rabbitmq-users
properties ={"headers":{"myKey":"MyValue"}}

Gave a space after properties and got the error 

ERROR: Argument "properties" not in format name=value

Gabriele Santomaggio

unread,
Aug 5, 2016, 3:07:42 AM8/5/16
to rabbitmq-users
Hi,
What version ?

I tried also using windows ( version 3.6.x )


C
:\Python27>python.exe c:\Users\gabriele\Downloads\rabbitmqadmin.txt publish  routing_key=my_queue payload="hello, world" properties={\"headers\":{\"myKey\":\"MyValue\"}}

Message published

it works

swetha kolalmath

unread,
Aug 5, 2016, 3:28:25 AM8/5/16
to rabbitmq-users
Ok , that could be the culprit. I am using python 2.7 and will not be able to upgrade as the entire project uses the 2.7 still.

Gabriele Santomaggio

unread,
Aug 5, 2016, 3:44:52 AM8/5/16
to rabbitmq-users

Sorry,
I meant which RabbitMQ version are you using ?


I also used Python 2.7 for my tests.
The command works with python 2.7.

swetha kolalmath

unread,
Aug 7, 2016, 1:02:15 PM8/7/16
to rabbitmq-users
Hi ,

I am using rabbit MQ 3.5.4

Gabriele Santomaggio

unread,
Aug 8, 2016, 8:55:44 AM8/8/16
to rabbitmq-users
Hi,

It it the same with 3.5.4:


python rabbitmqadmin publish  routing_key=my_queue payload="hello, world" properties={\"headers\":{\"myKey\":\"MyValue\"}}
Message published


Check:
  1. you downloaded  the correct rabbitmqadmin from the management UI (http://localhost:15672/cli/rabbitmqadmin
  2 the backslash \
  3. don't use spaces after and before =

swetha kolalmath

unread,
Aug 9, 2016, 3:26:12 AM8/9/16
to rabbitmq-users
Hi Thanks a lot. My rabbitmq admin file was not updated one.

Thanks a ton again.

Another favor  please.. Is there a similar method to fetch the headers from rabbit MQ and put it in a file or something ?

Thanks
Swetha

Gabriele Santomaggio

unread,
Aug 9, 2016, 12:42:07 PM8/9/16
to rabbitmq-users
Hi,
This a basic RabbitMQ behavior read here:
https://www.rabbitmq.com/tutorials/tutorial-one-python.html

if you want to consume message using HTTP you can use the admin:
rabbitmqadmin get queue=<QueueName>

or the API
/api/queues/vhost/name/get
See here for the documentation:
https://raw.githack.com/rabbitmq/rabbitmq-management/rabbitmq_v3_6_5/priv/www/api/index.html

-
Gabriele

swetha kolalmath

unread,
Aug 9, 2016, 1:46:54 PM8/9/16
to rabbitmq-users
Thanks ! I will read through some basic information.

Thanks for your time
:)
Reply all
Reply to author
Forward
0 new messages