Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Publish multiple messages to RabbitMQ from a file

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?

like image 223
summerbulb Avatar asked Nov 02 '15 09:11

summerbulb


People also ask

How do I manually publish in RabbitMQ?

It is possible to manually publish a message to the queue from "publish message". The message will be published to the default exchange with the queue name as given routing key - meaning that the message will be sent to the queue. It is also possible to publish a message to an exchange from the exchange view.

How many messages can a RabbitMQ queue hold?

Queues are single-threaded in RabbitMQ, and one queue can handle up to about 50 thousand messages. You will achieve better throughput on a multi-core system if you have multiple queues and consumers and if you have as many queues as cores on the underlying node(s).


1 Answers

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.

like image 184
looseend Avatar answered Sep 19 '22 11:09

looseend