Publish multiple messages to RabbitMQ from a file

summerbulb picture summerbulb · Nov 2, 2015 · Viewed 21.6k times · Source

Publishing single messages to a RabbitMQ queue can be easily done with the UI, by simply putting the message in the UI and clicking the "Publish Message" button.

How do you publish a batch of messages?

I have a file with messages to be sent to RabbitMQ. Each line has one message.

How can I publish all the messages from the file to my RabbitMQ server?

Is there a way to do it from command line?

Answer

looseend picture looseend · Sep 15, 2016

Using rabbitmqadmin

while read -r line; do 
  echo $line | rabbitmqadmin publish exchange=amq.default routing_key=my_queue ; 
done < messages

Not specifying the payload parameter to rabbitmqadmin publish means it reads the payload from stdin.