Run RocketMQ locally

This section will introduce the method of quickly building and deploying a single-Master RocketMQ cluster to complete simple message sending and receiving.

Run RocketMQ locally - 图1System Requirement

  1. 64-bit OS,Linux/Unix/macOS is recommended
  2. 64-bit JDK 1.8+

1. Get Apache RocketMQ

Run RocketMQ locally - 图2Download RocketMQ

RocketMQ’s installation is divided into two types: binary and source. Click here to download Apache RocketMQ 4.9.4 source package, or download the binary package from here. The binary package can be run directly since it has been compiled, and the source package needs to be compiled and run.

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:

  1. $ unzip rocketmq-all-4.9.4-source-release.zip
  2. $ cd rocketmq-all-4.9.4-source-release/
  3. $ mvn -Prelease-all -DskipTests clean install -U
  4. $ cd distribution/target/rocketmq-4.9.4/rocketmq-4.9.4

2. Start the NameServer

After the installation of RocketMQ, start the NameServer:

  1. ### Start the namesrv service
  2. $ nohup sh bin/mqnamesrv &
  3. ### Verify that the namesrv service is started successfully
  4. $ tail -f ~/logs/rocketmqlogs/namesrv.log
  5. The Name Server boot success...

Run RocketMQ locally - 图3info

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:

  1. ### Start the broker service
  2. $ nohup sh bin/mqbroker -n localhost:9876 &
  3. ### 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
  4. $ tail -f ~/logs/rocketmqlogs/broker.log
  5. The broker[broker-a,192.169.1.2:10911] boot success...

Run RocketMQ locally - 图4info

Once we see “The broker[brokerName,ip:port] boot success..” from broker.log, it means the Broker has been started successfully.

Run RocketMQ locally - 图5note

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 NAMESRV_ADDR :

  1. $ export NAMESRV_ADDR=localhost:9876
  2. $ sh bin/tools.sh org.apache.rocketmq.example.quickstart.Producer
  3. SendResult [sendStatus=SEND_OK, msgId= ...
  4. $ sh bin/tools.sh org.apache.rocketmq.example.quickstart.Consumer
  5. ConsumeMessageThread_%d Receive New Messages: [MessageExt...

5. Shutdown Servers

After finishing the practice, we could shut down the service by the following commands:

  1. $ sh bin/mqshutdown broker
  2. The mqbroker(36695) is running...
  3. Send shutdown request to mqbroker(36695) OK
  4. $ sh bin/mqshutdown namesrv
  5. The mqnamesrv(36664) is running...
  6. Send shutdown request to mqnamesrv(36664) OK