RocketMQ principle and source code parsing

RocketMQ principle depth :

First, the definition:

RocketMQ is a distributed messaging middleware queue model has the following components:

1, NameServer: no information synchronization between a state of almost no node, the cluster can be deployed, the node

2, Broker: is RocketMQ core component through lightweight Topic to maintain the message store and queue mechanism, Broker supports message Push and Pull mode. Support one hundred billion level messages accumulation capacity

3, Producer: message producers, and NameServer communication obtaining topic route information, and NameServer maintaining long connections and all of the producers and associated broker to maintain a long connection

4, Consumer: consumer, and a single consumer nameserver holding a long connection, polling the topic configuration information, according to topic route and broker to maintain a long connection

Two, Broker cluster approach

1, single- master mode: in this way risk, once Broker restart or downtime will result in the entire service is not available, is not recommended to use online environment.

2, multi- master mode: a cluster without the Slave , all Master , for example : 3 th Master

   Advantages: simple configuration, a single Master down or restarting the application has no effect on the maintenance, configured as a disk RAID10 time, even if the machine downtime unrecoverable situation, by a RAID10 missing disk very reliable, the message is not lost (Asynchronous brush disc small number of messages, a brush plate does not lose synchronization). The highest performance.

   Disadvantages: During a single machine is down, the machine has not been consumed before the message can not subscribe to restore the machine, real-time messages will be affected.

3, multi- master multi- slave mode, asynchronous replication

Each Master arranged a the Slave , a plurality of the Master-the Slave , the HA asynchronous replication mode, a short message with the main delay in milliseconds.

   Advantages: even if the disk is damaged, the message is lost very little, and real-time messages will not be affected, because the Master after downtime, consumers are still available from Slave consumption, this process is transparent to the application. Without human intervention. Performance with multi- Master is almost the same pattern.

   Drawback: Master downtime, disk damage, lost a small amount of information.

4, multi- master multi- Slave , synchronous dual-write

Each Master arranged a the Slave , a plurality of the Master-the Slave , the HA synchronous dual-write mode, write standby successful, success returned to the application.

   Advantages: data services have no single point, Master lower down, the message without delay, service availability and data availability is very high

   Disadvantages: slightly lower performance than the asynchronous replication mode, about lower 10% or so, to send a single message to RT slightly higher. After the primary current goes down, the backup machine does not automatically switch to the host, will support subsequent automatic switching function.

 

Three, RocketMQ Chart:

Picture reference:

 

Four, RocketMQ source code analysis:

1, MQ modules:

 

 

Rocketmq-namesrv:对应NameServer服务实例,一些事时序图:

 

 

Guess you like

Origin www.cnblogs.com/junxing/p/10993993.html