RabbitMQ - Publish Message using the rabbitmqadmin command
                
            
            
            
             
            
            
                           
                
            
            
            
                
    
    
     
            
                
                    by
                    Jeremy Canfield  |  
                    Updated: January 12 2021
                    
                          |  RabbitMQ articles
                    
                    
                    
                
            
            A message can be published to a queue or an exchange.
- Exchange - This is where the producer sends (publishes) the message
- Queue - This is where the message resides until it is consumed by the consumer
- Binding - The connection between an exchange and queue, so that a message can be routed from the exchange to the queue

This assumes you have downloaded and setup the rabbitmqadmin command line tool.
Here is how to publish "Hello World" to exchange001 using routing key key001.
rabbitmqadmin publish exchange="exchange001" routing_key="key001" payload="Hello World"
The properties option can be used to specify the delivery mode, non-persistent or persisent. You would use 1 for non-persistent or 2 for persistent.
rabbitmqadmin publish exchange="exchange001" routing_key="key001" payload="Hello World" properties="{\"delivery_mode\":1}"
Additionally, any of these keys can be used as a property.
- headers
- content_type
- content_encoding
- priority
- correlation_id
- reply_to
- expiration
- message_id
- timestamp
- type
- user_id
- app_id
- cluster_id
For example.
rabbitmqadmin publish exchange="exchange001" routing_key="key001" payload="Hello World" properties="{\"headers\":"foo"}"
If the message is successfully published, the following should be displayed.
Message published
Did you find this article helpful?
If so, consider buying me a coffee over at 