Install
RocketMQ runs on all major operating systems and requires only a Java JDK version 8 or higher to be installed. To check, run java -version
:
$ java -version
java version "1.8.0_121"
For Windows users, click here to download the 5.2.0 RocketMQ binary release, unpack it to your local disk, such as D:\rocketmq
. For macOS and Linux users, execute following commands:
# Download release from the Apache mirror
$ wget https://dist.apache.org/repos/dist/release/rocketmq/5.2.0/rocketmq-all-5.2.0-bin-release.zip
# Unpack the release
$ unzip rocketmq-all-5.2.0-bin-release.zip
Prepare a terminal and change to the extracted bin
directory:
$ cd rocketmq-all-5.2.0-bin-release/bin
1) Start NameServer
NameServer will be listening at 0.0.0.0:9876
, make sure that the port is not used by others on the local machine, and then do as follows.
For macOS and Linux users:
### start Name Server
$ nohup sh mqnamesrv &
### check whether Name Server is successfully started
$ tail -f ~/logs/rocketmqlogs/namesrv.log
The Name Server boot success...
2) Start Broker
For macOS and Linux users:
### start Broker
$ nohup sh bin/mqbroker -n localhost:9876 &
### check whether Broker is successfully started, eg: Broker's IP is 192.168.1.2, Broker's name is broker-a
$ tail -f ~/logs/rocketmqlogs/broker.log
The broker[broker-a, 192.169.1.2:10911] boot success...
Architecture
RocketMQ consists of four parts: name servers, brokers, producers and consumers. Each of them can be horizontally extended without a single point of Failure.
NameServer Cluster The lightweight component for service discovery and they can be used to read and write routing information. Each one records global information, and supports fast storage expansion.
Broker Cluster They use lightweight TOPIC and QUEUE mechanisms to manage data storage. To realize fault tolerance, two copies or three copies of data are provided. And Client can get message in Push and Pull model. In addition, disaster recovery and rich metrics statistics are also supported.
Producer Cluster Producers can be distributed deployed, and messages from producers to brokers can be balanced through multi-path. In addition, fast failure and low latency are supported.
Consumer Cluster Consumers can also be distributed deployed in the push and pull model, and they can subscribe message real-time, consume message in the unit of cluster. Message broadcasting is also supported.
Use Cases for RocketMQ
Microservices Communication:
RocketMQ can act as a message broker between microservices, enabling asynchronous communication and decoupling services.
Event-Driven Systems:
RocketMQ can handle event-driven architectures, where various events are published and subscribed to by different services.
Data Streaming and ETL:
RocketMQ can be used to stream large volumes of data in real time, making it ideal for real-time analytics or ETL processes.
Reliable Message Queuing:
RocketMQ ensures message delivery and supports features like message persistence, retries, and dead-letter queues for failed messages.
Demo
Server
cd rocketmq-all-5.2.0-bin-release/bin
# Name Server
sh mqnamesrv
# broker
sh mqbroker -n localhost:9876
Client
# client via cli
# Create a Topic
sh mqadmin updateTopic -n <nameserver-address> -t <topic-name>
sh mqadmin updateTopic -n localhost:9876 -t TestTopic
# List Topics
sh mqadmin topicList -n <nameserver-address>
sh mqadmin topicList -n localhost:9876