Image following situation one application A in moment communication application B using REST, and application B no running cause one error in moment application A communicate application B. At this moment the messaging queue is to form correct communication between applications.
It’s one form of communication between applications, commonly used in microservice architecture and event driven architecture. I think a messaging queue is good for scenarios when i need communication between applications and necessary guarantee action be executed and need decoupling between applications.
When speak about messaging queue exist three components is necessary understand:
- Producer: application responsable publish messages. Messages are many data used per another component that talk about more later.
- Message broker(Queue): component responsable store messages published to the producer and distributive messages between consumers. Ex: SQS, RabbitMQ, Kafka and more.
- Consumer: application responsable consume messages stored in the queue.
Image explained components mentioned above:
Another aspect about the messaging queue that is asynchronous. Process asynchronous is one process that can occur after another moment, no in the same moment. Example: purchase product in e-commerce, no need generate fiscal note in moment, sends per email time after.
Some sceneries to apply messaging queue:
- When needed, one action that delay a lot, must send a message to another application(consumer) execute. This prevents problem performance in principal application. Example: generate reports and send per email.
- Communication between applications due guarantee action be executed same one application no running in moment and prevent coupling between applications.
- When executed one action that part process is delayed, heavy and not necessary in the moment is suitable to use the messaging queue. Example: purchase product in e-commerce, no need generate fiscal note in moment, sends per email time after.
Image explain one scenery using messaging queue to generate reports:
Explain step by step this scenery:
- People request api to generate reports.
- Api code publishes messages to the queue.
- Consumer consume data and query data in database replica to prevent generate heavy process in master database
- After generated reports send to s3 and send email with link file s3.
Until moment messaging queue is great, but exist challenges in use it:
- Flow application is more complex
- Scale out applications that use messaging queues are different applications using http protocol.
- Eventual consistency means that in a moment data will be consistent. The moments are needed to execute action to update datas, but using a messaging queue this does not occur in the same moment.
- Logging actions in application. How to log actions and connect between producer and consumer applications.
- No write log in file, because it is hard to analyze problems.
In summary messaging queue is good form communication between applications due to declouples applications and the same if one application is not working exactly at the moment, more later is application consume message in queue due data stored in queue. But knowing any technology is not a silver bullet, so it is necessary to understand the use and challenges in adopting it.
Top comments (0)