Rabbit MQ #codehacks
What is RabbitMQ?
RabbitMQ is an open source message queuing system that allows us to execute the code of our applications asynchronously.
Benefits of RabbitMQ
– Delivery and order guarantee: The messages have been sent to a consumer in the same order in which they were created.
- Redundancy: The queues persist the messages until they are processed completely.
– Decoupling: Any third party system can consume the messages and interact with them, so you want the messages to be processed by someone who is not the actor who created the message, without any problems. This generates us a benefit, which is that it can be reused for many projects.
- Scalability: we can have an application server dedicated to the processes and the other servers for browsing the web.
How it works?
On the one hand we see, that there is a ‘Publisher’ that is responsible for creating the messages and send them to an Exchange with a ‘routing_key’ to RabbitMQ, It is itself responsible for storing that message in a queue through its’ routing_key ‘
On the other hand we see that the consumer (it does not have to be the same one that created the message) is in charge of calling and receiving the messages stored inside the queues and processing them.
Case of use
For one of the projects we are working on, we had the challenge of downloading the orders to the ERP and to make sure that this process ends correctly, we decided to use it.
What we did was use the event ‘checkout_onepage_controller_success_action’ to capture the order once finished and send a message with the ‘entity_id’ of the order to RabbitMQ, in this way our consumers are responsible for reading the queues of RabbitMQ and are responsible for executing the code that downloads the order to the ERP.
Subscribe to our newsletter
You may also like