History of RocketMQ
RocketMQ is an open-source messaging middleware created by Alibaba. It was opened in 2012 and became an Apache top-level project in 2017. RocketMQ is widely used within Alibaba. Thousands of applications run on RocketMQ. During Singles’ Day, hundreds of thousands of messages need to be processed, and TPS can reach hundreds of thousands. Currently, Java, C/C++, Python, and Go are supported.
RocketMQ is currently available in two versions, a community open source version and a commercial cloud service version (AliwareMQ). Latest version: 4.8.0 (demo version for this article).
Its core design borrowed from Kafka, so when we study RocketMQ, we will find many of the same features as Kafka, but there are some major differences. It has the following features:
- Supports cluster modeling, load balancing, and horizontal scaling
- Hundred-billion-level message stacking capability
- Using the principle of zero copy, sequential write disk, random read
- The underlying communication framework is Netty NIO
- NameServer replaces Zookeeper to realize service addressing and service coordination
- Message failure retry mechanism, messages can be queried
- It emphasizes that the cluster has no single point and is scalable. Any point is highly available and horizontally scalable
- After many tests of Double eleven
High availability architecture
RocketMQ has excellent clustering support by nature and has the following patterns:
A single Master
- Advantages: No advantages other than simple configuration
- Disadvantages: unreliable, the machine restarts or goes down, the entire service will be unavailable
More than the Master
- Advantages: Simple configuration and the highest performance
- Disadvantages: A small number of messages may be lost (configuration related), during the restart or outage of a single machine, messages that are not consumed under that machine may not be subscribed until the machine is restored, affecting message real-time
The Master and Slave much
Each Master is configured with a Slave, and there are multiple master-slave pairs. The cluster adopts the asynchronous replication mode, and the Master has a short message delay of milliseconds
- Advantages: The performance is almost the same as that of multiple masters, high real-time performance, transparent switchover between primary and standby applications, and no manual intervention is required
- Cons: A small number of messages are lost when the Master goes down or the disk is damaged
The Master and Slave much
Each Master is configured with a Slave and there are multiple master-slave pairs. The cluster adopts synchronous dual-write mode. When both the Master and Slave pairs are successfully written, a success message is returned to the application
- Advantages: High service availability and data availability
- Disadvantages: The performance of the asynchronous cluster is lower than that of the asynchronous cluster. In the current version, the active cluster cannot be automatically switched over to the active cluster when the standby cluster breaks down
Two primary and two secondary asynchronous clusters were installed
This paper adopts the two Master and two Slave installation mode, that is, the fourth multi Master and Slave
Port planning
First of all, I bought two cloud servers, which I usually use to learn to install some middleware, which is more convenient. If you have conditions, you can also buy them. Of course, you can also install virtual machines locally to operate them.
Next, I will implement two master and two slave installations through these two servers. First, I will plan their ports
First machine 42.192.77.73 # Port plan: 9876 NameServer1 10910 BrokerA-Master 10921 BrokerB-slave 9876 NameServer2 10920 BrokerB-master 10911 BrokerA-slave
Let me draw it a little bit more clearly
download
Go to rocketmq.apache.org/ for the latest download address, as indicated in the red box
All the addresses here can be downloaded
CD/jackxu wget HTTP: / / https://mirror.bit.edu.cn/apache/rocketmq/4.8.0/rocketmq-all-4.8.0-bin-release.zip
Download it, unzip it, and change the name
Unzip rocketmq-all-4.8.0-bin-release.zip mv unzip rocketmQ-all-4.8.0-bin -release.zip Rocketmq
Configure the first machine
Download and unzip it on both machines. In the rocketMQ /conf directory, there are three recommended configuration modes:
- 2m-2S-async (2 master and 2 slave async) — this is used in this paper
- 2m-2s-sync (2 primary and 2 secondary synchronization)
- 2 m – noslave (2)
Now you need to modify the files in the 2m-2s-async directory on both machines. Modify broker -A. perties on machine 42.192.77.73
cd /jackxu/rocketmq/conf/2m-2s-async
vim broker-a.properties
Changing the Cluster name
brokerClusterName=jackxu-cluster
Added content
# Enable autoCreateTopicEnable= True # Enable autoCreateTopicEnable=true # Enable autoCreateTopicEnable=true Advice line open, shut online autoCreateSubscriptionGroup = true # nameServer addresses, a semicolon namesrvAddr = 39.103.144.86:9876; 42.192.77.73:9876 # storage paths storePathRootDir = / jackxu rocketmq/store/broker - a # commitLog storage paths StorePathCommitLog = / jackxu/rocketmq/store/broker queue storage - a/commitlog # consumption path storage paths StorePathConsumeQueue = / jackxu rocketmq/store/broker - a/consumequeue # message index storage paths StorePathIndex = / jackxu rocketmq/store/broker - a/index # checkpoint file storage path StoreCheckpoint = / jackxu/rocketmq/store/checkpoint # abort abortFile file storage path = / jackxu rocketmq/store/abort
Modify the broker – b – supachai panitchpakdi roperties
vim broker-b-s.properties
Changing the Cluster name
brokerClusterName=jackxu-cluster
Added content
# Enable autoCreateTopicEnable= True # Enable autoCreateTopicEnable= True # Enable autoCreateTopicEnable= True Advice line open, shut online autoCreateSubscriptionGroup = true # nameServer addresses, a semicolon namesrvAddr = 39.103.144.86:9876; 42.192.77.73:9876 # storage paths storePathRootDir = / jackxu/rocketmq/store/broker - b - # s commitLog storage paths StorePathCommitLog = / jackxu/rocketmq/store/broker - b - # s/commitlog consumption queue storage paths storage paths StorePathConsumeQueue = / jackxu/rocketmq/store/broker - b - # s/consumequeue message index storage paths StorePathIndex = / jackxu rocketmq/store/broker - - s/b index # checkpoint file storage path StoreCheckpoint = / jackxu/rocketmq/store/checkpoint # abort abortFile file storage path = / jackxu rocketmq/store/abort
Configure a second machine
Modify broker -B.perties on machine 39.103.144.86
cd /jackxu/rocketmq/conf/2m-2s-async
vim broker-b.properties
Changing the Cluster name
brokerClusterName=jackxu-cluster
Added content
# Enable autoCreateTopicEnable= True # Enable autoCreateTopicEnable= True # Enable autoCreateTopicEnable= True Advice line open, shut online autoCreateSubscriptionGroup = true # nameServer addresses, a semicolon namesrvAddr = 39.103.144.86:9876; 42.192.77.73:9876 # storage paths storePathRootDir = / jackxu rocketmq/store/broker - b # commitLog storage paths StorePathCommitLog = / jackxu rocketmq/store/broker - # b/commitlog consumption queue storage paths storage paths StorePathConsumeQueue = / jackxu rocketmq/store/broker - b/consumequeue # message index storage paths StorePathIndex = / jackxu rocketmq/store/broker - b/index # checkpoint file storage path StoreCheckpoint = / jackxu/rocketmq/store/checkpoint # abort abortFile file storage path = / jackxu rocketmq/store/abort
Modify the broker – a – supachai panitchpakdi roperties
vim broker-a-s.properties
Changing the Cluster name
brokerClusterName=jackxu-cluster
Added content
# Enable autoCreateTopicEnable= True # Enable autoCreateTopicEnable=true # Enable autoCreateTopicEnable=true Advice line open, shut online autoCreateSubscriptionGroup = true # nameServer addresses, a semicolon namesrvAddr = 39.103.144.86:9876; 42.192.77.73:9876 # storage paths storePathRootDir = / jackxu rocketmq/store/broker - a - s # commitLog storage paths StorePathCommitLog = / jackxu rocketmq/store/broker - a - s / # commitlog consumption queue storage paths storage paths StorePathConsumeQueue = / jackxu rocketmq/store/broker - a - s / # consumequeue message index storage paths StorePathIndex = / jackxu rocketmq/store/broker - a - s/index # checkpoint file storage path StoreCheckpoint = / jackxu/rocketmq/store/checkpoint # abort abortFile file storage path = / jackxu rocketmq/store/abort
Creating a data directory
42.192.77.73 for the first machine, only once
mkdir -p /jackxu/rocketmq/store/broker-a /jackxu/rocketmq/store/broker-a/consumequeue /jackxu/rocketmq/store/broker-a/commitlog /jackxu/rocketmq/store/broker-a/index /jackxu/rocketmq/logs /jackxu/rocketmq/store/broker-b-s /jackxu/rocketmq/store/broker-b-s/consumequeue /jackxu/rocketmq/store/broker-b-s/commitlog /jackxu/rocketmq/store/broker-b-s/index
39.103.144.86 for the second machine, only one execution is required
mkdir -p /jackxu/rocketmq/store/broker-a-s /jackxu/rocketmq/store/broker-a-s/consumequeue /jackxu/rocketmq/store/broker-a-s/commitlog /jackxu/rocketmq/store/broker-a-s/index /jackxu/rocketmq/logs /jackxu/rocketmq/store/broker-b /jackxu/rocketmq/store/broker-b/consumequeue /jackxu/rocketmq/store/broker-b/commitlog /jackxu/rocketmq/store/broker-b/index
Start two Nameservers
Executed on both machines, & means running in the background. By default, Nameserver listens on port 9876
nohup sh /jackxu/rocketmq/bin/mqnamesrv >/jackxu/rocketmq/logs/mqnamesrv.log 2>&1 &
See the log
tail -f /jackxu/rocketmq/logs/mqnamesrv.log
Start the Broker
When started, in the following order, -c is the configuration file that specifies the broker
1, start 73 A main
nohup sh /jackxu/rocketmq/bin/mqbroker -c /jackxu/rocketmq/conf/2m-2s-async/broker-a.properties > /jackxu/rocketmq/logs/broker-a.log 2>&1 &
2. Start A from 86
nohup sh /jackxu/rocketmq/bin/mqbroker -c /jackxu/rocketmq/conf/2m-2s-async/broker-a-s.properties > /jackxu/rocketmq/logs/broker-a-s.log 2>&1 &
3, start 86 B master
nohup sh /jackxu/rocketmq/bin/mqbroker -c /jackxu/rocketmq/conf/2m-2s-async/broker-b.properties > /jackxu/rocketmq/logs/broker-b.log 2>&1 &
4, start 73 B from
nohup sh /jackxu/rocketmq/bin/mqbroker -c /jackxu/rocketmq/conf/2m-2s-async/broker-b-s.properties > /jackxu/rocketmq/logs/broker-b-s.log 2>&1 &
See the log
tail -f /jackxu/rocketmq/conf/2m-2s-async/broker-a.properties
tail -f /jackxu/rocketmq/conf/2m-2s-async/broker-a-s.properties
tail -f /jackxu/rocketmq/conf/2m-2s-async/broker-b.properties
tail -f /jackxu/rocketmq/conf/2m-2s-async/broker-b-s.properties
Check whether the startup is successful
Enter the JPS command, a total of four processes are fine
But most of the time it doesn’t go so smoothly, and I have some potholes in the installation:
- 1. I have not installed JDK, because this is my new server, there is no JDK environment on it. As you know, RocketMQ is written in Java, so I need Java environment to run, including JPS command is to view Java process
- 2. Insufficient memory, because the default configuration file sets a large memory, but my machine only has 1 core 2G, which is definitely not enough, so I will report insufficient memory when I start up
The solution is to modify the configuration file
vim /jackxu/rocketmq/bin/runserver.sh
vim /jackxu/rocketmq/bin/runbroker.sh
Change the memory size of the NameServer and Broker to a smaller size and restart
The shutdown command
When stopping services, it is important to stop the broker first and then the Nameserver second.
cd /jackxu/rocketmq/bin
sh mqshutdown namesrv
sh mqshutdown broker
Web Console Installation
Unlike Kafka, Rocket officially provides a visual console, which you can download here
https://github.com/apache/rocketmq-externals
This is an extension to RocketMQ, which includes not only the console extension, but also the big data Flume, hbase and other components and extensions.
download
Download the source code, the general download speed will be slow, can not wait to go to the web disk download link:
cd /jackxu
wget https://github.com/apache/rocketmq-externals/archive/master.zip
Unpack the
unzip master.zip
Modifying a Configuration File
CD/jackxu/rocketmq - externals - master/rocketmq - the console/SRC/main/resources vim application. The properties # this is a spring boot project, We need to modify the parameter # modify the port number: server port = 7298 # modify the name server addresses (multiple addresses with a semicolon in English) rocketmq. Config. NamesrvAddr = 39.103.144.86:9876; 42.192.77.73:9876
packaging
It should be packed into a JAR package. Here you need to install Maven first. If the compilation is slow, you can replace the image of Taobao
cd /jackxu/rocketmq-externals-master/rocketmq-console
mvn clean package -Dmaven.test.skip=true
Start the jars
CD target java-jar rocketmq-console-ng-2.0.0.jar
access
Visit http://42.192.77.73:7298/, you can see all already started successfully
Point on pit
There are two potholes here, which will report an error on startup
- (1) Spring Boot failed to connect at 39.103.144.86:9876; 42.192.77.73:9876, here my first reaction is the reason for the firewall, shut it down
systemctl disable firewalld.service
The second response is that the port is not open, Telnet
Telnet 42.192.77.73 9876
Sure enough, The Telnet failed. The reason is that I installed it on the cloud server, and the default port is not open, so I need to open it on the console. This is also an experience.
- (2) When it started again, it reported another error, failed to connect to 172.26.182.88:9876, at that time I was surprised, I wrote in the address did not have this address ah, how to connect to it, and this IP looked like an Intranet address, later I opened the Ali Cloud console to see, really is the Intranet address of this machine, Then I baidu a time, probably the reason is RocketMQ is ali open source, and that machine is ali cloud machine, its source code should be the priority to connect to ali cloud Intranet address, the practice of the Internet is in the configuration file inside the explicit plus the public address can be solved.
New public IP brokerIP1=39.103.144.86
Introduction to the console
- Operation and maintenance: mainly set nameserver and vipChannel.
- Cockpit: A dashboard for the console to view the number and trend of messages by broker and subject, respectively.
- Cluster: The entire RocketMQ cluster, including sharding, number, address, version, message production and message consumption TPS, which can be used as a data indicator when performing performance tests.
- Topic: Topic. You can add/update topics, and view information about topics, such as status, routing, consumer management, and sending messages.
- Consumer: You can view/create consumer groups in the current broker, including consumer information and consumption progress.
- Producer: You can view the producer group under the production group in the current broker, including producer information and producer status.
- Message: You can query specific messages by topic, messageID, and messageKey.
- User center: The language change is related to login (you need to enable the corresponding configuration in the console configuration, and you do not need to log in by default).
The four most commonly used sections are cluster, topic, consumer, and message.
Configuration File Description
The cluster name is brokerClusterName= JackXu -cluster for the above four machines. The cluster name is brokerClusterName= Jackxu -cluster. The cluster name is connected to the same NameServer. NamesrvAddr = 39.103.144.86:9876; 42.192.77.73:9876. BrokerId =0 in the configuration file represents master and brokerId=1 represents slave.
These two properties are also in the configuration file
BrokerRole can be configured as SYNC_MASTER or ASYNC_MASTER on the master broker and as slave on the Slave broker
The flow chart
The recommended configuration is asynchronous flush + synchronous replication.
HA and failover
In previous versions, RocketMQ was deployed in a master/slave mode, with a set of brokers with one master and zero to multiple slaves, providing high availability.
If the master is dead, the slave can still provide the read service. If slaveReadEnable=true is enabled, slave can also participate in the read load, but only if the master’s backlog exceeds 40% of the physical memory, the slave will switch to read from the server with brokerId 1 as the default. Specific to which machine is controlled by whichBrokerWhenConsumeSlowly parameters.
org.apache.rocketmq.common.subscription.SubscriptionGroupConfig
private long whichBrokerWhenConsumeSlowly=1;
Because of the existence of multiple masters, when one master fails, it can write to other masters.
RocketMQ version 4.5.0, released in March 2019, uses Dledger technology to solve the problem of automatic master selection. Dledger is a commitlog repository based on raft protocol, which is the key to RocketMQ’s new high availability multi-copy architecture. Its advantage is that it does not need to introduce external components, and the automatic primary selection logic is integrated into the process of each node, and the primary selection can be completed by communication between nodes.
Architecture diagram
In this case, commitLog is managed by Dledger and has the ability to select the master. This function is disabled by default. To enable this function, add the following parameters to the configuration file:
EnableDLegerCommitLog =true # DLedger Raft Group name dLegerGroup=broker-a # DLedger Group address and port DLegerPeers =n0-192.168.44.163:10911; N1-192.168.44.164:10911; N2-192.168.44.165:10911 # dLegerSelfId=n0
conclusion
Partners must practice installation when learning a middleware, first of all, to experience the installation process atmosphere, understand some parameters configuration, although we usually may not contact, but still need to learn, not necessarily need to be fine, at least to be able to.
Source: jack_xu |https://juejin.cn/post/692950…