1. Application scenarios

Decoupling, asynchronous, flow peak clipping.

2. Disadvantages after introduction

The system availability decreases.

Once MQ is down it’s not just down. (So do high availability, high availability is nothing more than using a cluster or a standby machine, dual-master dual-slave, mirroring cluster, etc.)

System complexity enhancement

What if the most important message is lost? How about messages being consumed repeatedly? How to ensure the order of consumption?

Consistency problem

Producer and consumer each have their own local transaction execution. How to ensure consistency?

3. Ensure high availability

RocketMQ uses a dual-master dual-slave architecture

The node that holds the data is called the broker (master and slave respectively), and it also has the Name Server as the manager of the broker. Brokers synchronize their state to the Name Server periodically via a heartbeat mechanism. The Name Server is a manager of the broker. When sending a message, the Producer asks the Name Server. The Nameserver then gives a broker address. The Producer then sends the message to the broker.Copy the code

Note that slave nodes of the broker cannot accept messages.

1. Producer discovers Broker through Name Server 2. Producer sends queue message to 2 Broker master nodes 3. Consumers subscribe to messages from master or slave nodesCopy the code

RabbitMQ mainly uses mirrored clusters for high availability

4. Ensure that messages are not lost

4.1 Analysis of missing links

Case 1: The message producer fails to send the message to the MQ Broker. Case 2: After the message is sent to the MQ Broker, the Broker breaks down and the message data in memory is lost. Case 3: The consumer gets the message, but before the consumer has time to process the outage, the message has been deleted from MQ and the consumer can no longer consume the previous message after restartingCopy the code

4.2 Resolving The Loss

1. After the sender sends the message to the MQ Broker, the MQ Broker confirms receipt of the message to the producer. 2. After the consumer receives the ack message, manually ack it. 4. After receiving the ACK message, MQ deletes the persistent messageCopy the code