Symfony 4 and RabbitMQ

Mert Sevinc
5 min readApr 2, 2018

Many high performance websites often require a queuing mechanism to perform time-consuming tasks. These tasks can be anything from sending bunch of emails to splitting big files or aggregating some data from the database. A great software for handling big queues is RabbitMQ, which is a message broker. It gives your applications a common platform to send and receive messages, and your messages a safe place to live until received.

In this article, I am going to talk about how you can use RabbitMQ with Symfony 4. I am not be going into details of how RabbitMQ works. I strongly suggest you to read the documentation in order to understand exchanges, queues and etc.

Ok here we go…In this tutorial, we will post a JSON data from a controller class to RabbitMQ and then we will run a console command which will fetch the queue in order to process it.

Assuming that you have already installed RabbitMQ on your server, let’s first create a virtual host and assign its permissions by issuing the following commands:

rabbitmqctl add_vhost my_project
rabbitmqctl set_permissions -p my_project my_username ".*" ".*" ".*"

Cool! Now if you go to your RabbitMQ Management interface, under the admin section you should be able to see this virtual host and your user has permission to it.

Now, it’s time to make some configurations on Symfony 4, so that we can talk to RabbitMQ.

--

--