Message Middleware--Advantages, Disadvantages and Use

The role of the introduction of message middleware:

  • Decoupling of complex systems
  • Asynchronous call of complex link
  • Peak cut processing for
    Decoupling of complex systems
    Asynchronous call
    instantaneous peaks During instantaneous peaks, a large number of requests flooded in at once, which can be backlogged in MQ, and then processed and consumed slowly.

Disadvantages after the introduction of message middleware:

  • Reduced system availability (MQ hangs [dependency])
  • Decreased system stability (network failure-message loss; message duplication-generation of dirty data; downtime, unable to consume messages-message backlog)
  • Distributed consistency problem

System C has successfully processed its own local database, and then sent a message to MQ, and system D has indeed consumed it. But system D failed to operate its own local database. System C succeeded and D failed, resulting in inconsistent overall system data.

The landing of message middleware in the project

[Java Advanced Interview Series 3] How did the message middleware land in your project?

E-commerce business scenarios
Use message middleware to make asynchronous calls (Warehouse scheduling and delivery takes tens of seconds)

RabbitMQ use

Insert picture description here
Insert picture description here
Insert picture description here
Insert picture description here

Communication between two services:

Multiple order services can be started, and different order services can push messages to a RabbitMQ queue. ( Producer produces messages and delivers them to MQ)
Multiple warehousing services can also be started. Multiple warehousing services will use the round-robin polling algorithm , and each service instance can consume a part of the message from the RabbitMQ queue. ( Consumer consumes messages from MQ)

[Java Advanced Interview Series 4] How to ensure that data is not lost when online services are down

Basic technical issues in the use of MQ middleware

Insert picture description here

Unexpected downtime, the problem is prominent

Insert picture description here
The default behavior of RabbitMQ middleware is that as long as the warehousing service receives an order message, RabbitMQ will immediately mark the order message as deleted . This behavior is called automatic ack , that is, when a message is delivered , it will automatically confirm that the message is processed. .
If the warehousing service receives an order message, but has not had time to complete the dispatch and delivery of the goods to the warehouse system, the result is directly down. The order message is lost.
(The user paid 8,999 yuan and placed an order for an iphone8. As a result, he waited for several days, but the website showed that his iphone8 was shipping.)

channel.basicConsume(QUEUE_NAME,true,deliverCallback,consumerTag->{});

The parameter true (default configuration) means that RabbitMQ will immediately mark the message as deleted as long as it delivers a message to the warehousing service.
If you want not to lose an order message due to the sudden downtime of the warehousing service, you need to change that parameter from true to false. (Turn off autoAck, the message is not processed successfully by default)

Transform the code that processes the order message.
After the order is dispatched and shipped, the ack operation is manually executed in the finally code block .
Insert picture description here
The entire architecture operation process

Resend push

Guess you like

Origin blog.csdn.net/eluanshi12/article/details/85275044