This section will introduce the method of quickly building and deploying a single-Master RocketMQ cluster to complete simple message sending and receiving.
- 64-bit OS，Linux/Unix/macOS is recommended
- 64-bit JDK 1.8+
1. Get Apache RocketMQ
The following instruction takes the application of RocketMQ 4.9.4 source package in Linux environment as an example in order to introduce the installation process of RocketMQ.
Extract the source package of RocketMQ 4.9.4, then compile and build the binary executables:
$ unzip rocketmq-all-4.9.4-source-release.zip
$ cd rocketmq-all-4.9.4-source-release/
$ mvn -Prelease-all -DskipTests clean install -U
$ cd distribution/target/rocketmq-4.9.4/rocketmq-4.9.4
2. Start the NameServer
After the installation of RocketMQ, start the NameServer:
### Start the namesrv service
$ nohup sh bin/mqnamesrv &
### Verify that the namesrv service is started successfully
$ tail -f ~/logs/rocketmqlogs/namesrv.log
The Name Server boot success...
Once we see 'The Name Server boot success..' from namesrv.log, it means the NameServer has been started successfully.
3. Start the Broker
Start the Broker after the NameServer has been launched:
### Start the broker service
$ nohup sh bin/mqbroker -n localhost:9876 &
### Verify that the broker service is started successfully, for example, the broker's ip is 192.168.1.2 and the name is broker-a
$ tail -f ~/logs/rocketmqlogs/broker.log
The broker[broker-a,18.104.22.168:10911] boot success...
Once we see “The broker[brokerName,ip:port] boot success..” from broker.log, it means the Broker has been started successfully.
Thus far, a single-Master RocketMQ cluster has been deployed, and we are able to send and receive simple messages by scripts.
4. Send and Receive Messages
Before sending and receiving messages, the clients need to identify the address of the NameServer. RocketMQ has multiple ways to set the NameServer address on the client side. One of them is to modify the environment variable
$ export NAMESRV_ADDR=localhost:9876
$ sh bin/tools.sh org.apache.rocketmq.example.quickstart.Producer
SendResult [sendStatus=SEND_OK, msgId= ...
$ sh bin/tools.sh org.apache.rocketmq.example.quickstart.Consumer
ConsumeMessageThread_%d Receive New Messages: [MessageExt...
5. Shutdown Servers
After finishing the practice, we could shut down the service by the following commands:
$ sh bin/mqshutdown broker
The mqbroker(36695) is running...
Send shutdown request to mqbroker(36695) OK
$ sh bin/mqshutdown namesrv
The mqnamesrv(36664) is running...
Send shutdown request to mqnamesrv(36664) OK