Introduction to rocketmq

Official address: https://rocketmq.apache.org/
Installation package download address: https://archive.apache.org/dist/rocketmq/

1, Introduction to rocketmq

RcoketMQ is a message oriented middleware with low latency, high reliability, scalability and ease of use. It has the following characteristics:

Support publish / subscribe (Pub/Sub) and peer-to-peer (P2P) message models
Reliable first in first out (FIFO) and strict sequential delivery in a queue
It supports two message modes: pull and push
Accumulation capacity of millions of messages in a single queue
Support a variety of message protocols, such as JMS, MQTT, etc
The distributed high availability deployment architecture meets the semantics of message passing at least once
Provide docker images for isolation testing and cloud cluster deployment
Provide dashboard (rocketmq console ng) with rich functions such as configuration, indicators and monitoring

2, rocketmq architecture

As can be seen from this figure, there are four clusters, namely NameServer cluster, Broker cluster, Producer cluster and Consumer cluster:
1. NameServer: provides lightweight service discovery and routing. Each NameServer records complete routing information, provides equivalent read-write services, and supports rapid storage expansion.
2. Broker: it handles message storage by providing lightweight Topic and Queue mechanisms, and supports push and pull modes and fault-tolerant mechanism of master-slave structure.
3. Producer: producer, the instance that generates messages. Producers with the same Producer Group form a cluster.
4. Consumer: consumer, an instance that receives messages for consumption. Consumers with the same Consumer Group form a cluster.

3, rocketmq deployment mode

1. Single master mode
There is only one master node. Once the master node goes down, the whole service will not be available, which is suitable for personal learning.
2. Multi master mode
Multiple master nodes form a cluster. The downtime or restart of a single master node has no impact on the application.
Advantage: highest performance of all modes
Disadvantages: during the downtime of a single master node, the messages that are not consumed will not be available before the node is restored, and the real-time performance of the messages will be affected.
Note: using synchronous disk brushing can ensure that messages are not lost. At the same time, the queue corresponding to the topic should be distributed among nodes in the cluster, not only on a certain node. Otherwise, the downtime of the node will affect the applications subscribing to the topic.
3. Multi master multi slave asynchronous replication mode
On the basis of multi master mode, each master node has at least one corresponding slave. master
Nodes are readable and writable, but slave can only read and cannot write, which is similar to the active and standby mode of mysql.
Advantages: when the master goes down, consumers can read messages from the slave. The real-time performance of messages will not be affected, and the performance is almost the same as that of multiple masters.
Disadvantages: using the synchronous mode of asynchronous replication may have the problem of message loss.
4. Multi master multi slave synchronous double write mode
Similar to the multi master and multi slave asynchronous replication mode, the difference lies in the data synchronization mode between master and slave.
Advantages: the synchronous mode of synchronous double write can ensure no data loss.
Disadvantages: sending a single message RT will be slightly longer, and the performance is about 10% lower than that of asynchronous replication.
Disk flushing strategy: synchronous disk flushing and asynchronous disk flushing (refers to whether the node's own data is stored synchronously or asynchronously)
Synchronous mode: synchronous double write and asynchronous replication (refers to the synchronization of data between a group of master and slave)
Note: to ensure reliable data, synchronous disk brushing and synchronous double write are required, but the performance will be lower than other methods.

4, Single master mode deployment

1. Download binary installation package

> wget https://archive.apache.org/dist/rocketmq/4.9.3/rocketmq-all-4.9.3-bin-release.zip
> unzip rocketmq-all-4.9.3-bin-release.zip

Extension:
If Download https://archive.apache.org/dist/rocketmq/4.9.3/rocketmq-all-4.9.3-source-release.zip
 It needs to be used after decompression mvn -Prelease-all -DskipTests clean install -U Command compilation, compiled directory distribution/target/rocketmq-4.9.3/rocketmq-4.9.3 You can use it

2. Modify the startup memory of NameServer

Modify the configuration of these two files
> bin/runserver.sh
 take JAVA_OPT="${JAVA_OPT} -server -Xms4g -Xmx4g -Xmn2g -XX:MetaspaceSize=128m -XX:MaxMetaspaceSize=320m"
Change to JAVA_OPT="${JAVA_OPT} -server -Xms512m -Xmx512m -Xmn256m"

> bin/runbroker.sh
 take JAVA_OPT="${JAVA_OPT} -server -Xms8g -Xmx8g"
Change to JAVA_OPT="${JAVA_OPT} -server -Xms512m -Xmx512m"

3. Start and close sever

###Start server
> nohup sh bin/mqnamesrv &
> tail -f ~/logs/rocketmqlogs/namesrv.log
The Name Server boot success...

###Shut down the server
> sh bin/mqshutdown namesrv

4. Starting and closing broker

###Start broker
> nohup sh bin/mqbroker -n localhost:9876 &
> tail -f ~/logs/rocketmqlogs/broker.log 
The broker[%s, 172.30.30.233:10911] boot success...

###Close broker
> sh bin/mqshutdown broker

5. Specify IP to start broker in case of multiple network cards

###Set the IP address of the broker
> echo "brokerIP1=192.168.16.239" > conf/broker.properties

### -c parameter specifies the configuration file
> nohup sh bin/mqbroker -n 192.168.16.239:9876 autoCreateTopicEnable=true -c conf/broker.properties & 

6. Create topic

> sh bin/mqadmin updateTopic -n localhost:9876 -b localhost:10911 -t demo

-b appoint Broker

7. Send and receive messages

###send message
> export NAMESRV_ADDR=localhost:9876
> sh bin/tools.sh org.apache.rocketmq.example.quickstart.Producer
SendResult [sendStatus=SEND_OK, msgId= ...


###receive messages
> sh bin/tools.sh org.apache.rocketmq.example.quickstart.Consumer
ConsumeMessageThread_%d Receive New Messages: [MessageExt...

5, Visual monitoring platform rocketmq console ng

Project address: https://github.com/apache/rocketmq-externals

### Download and compile
> git clone -b release-rocketmq-console-1.0.0 https://github.com/apache/rocketmq-externals.git 
perhaps
> git clone -b mqtt-mesh https://github.com/apache/rocketmq-externals.git
> cd rocketmq-externals/rocketmq-console/
> mvn clean install -Dmaven.test.skip
> ls target/rocketmq-console-ng-*.jar
target/rocketmq-console-ng-2.0.0.jar


### Start ng, where the start port is specified
nohup java -jar -Xms512m -Xmx512m rocketmq-console-ng-2.0.0.jar --server.port=8090 & 


### visit
http://192.168.16.239:8090

Keywords: Linux RocketMQ

Added by gwledig on Thu, 10 Mar 2022 04:48:50 +0200