Quick Guide to Installing, Configuring, and Using Apache RocketMQ 4.2
This tutorial provides a step‑by‑step walkthrough for setting up Apache RocketMQ 4.2 on a 64‑bit Linux system, covering environment prerequisites, downloading source, building binaries, starting NameServer and Broker, sending and receiving messages, and shutting down the services.
Environment Requirements
Use a 64‑bit Linux/Unix OS (e.g., CentOS 7.3) with JDK 1.8+, Maven 3.2.x installed. Install JDK and Maven as needed.
Download and Build
Download the source package:
wget https://www.apache.org/dyn/closer.cgi?path=rocketmq/4.2.0/rocketmq-all-4.2.0-source-release.zipUnzip and build:
unzip rocketmq-all-4.2.0-source-release.zip cd rocketmq-all-4.2.0 mvn -Prelease -DskipTests clean installAfter the build finishes, the distribution can be found under distribution/target/apache-rocketmq. The build logs show a series of SUCCESS messages for each module.
Start NameServer
Edit bin/runserver.sh to set JVM options, e.g.:
JAVA_OPT="${JAVA_OPT} -server -Xms1g -Xmx1g -Xmn512m -XX:MetaspaceSize=128m -XX:MaxMetaspaceSize=320m"Start the NameServer in background: nohup sh bin/mqnamesrv > /dev/null 2>&1 & Verify the startup log contains "NameServer boot success".
Start Broker
Similarly adjust bin/runbroker.sh JVM options: JAVA_OPT="${JAVA_OPT} -server -Xms1g -Xmx1g -Xmn512m" Start the broker:
nohup sh bin/mqbroker -n localhost:9876 > /dev/null 2>&1 &Check the broker log for "broker [...] boot success".
Verify Processes
jps netstat -ntlpEnsure NamesrvStartup and BrokerStartup are listening on ports 9876 and 10911 respectively.
Send and Receive Messages
Set the NameServer address: export NAMESRV_ADDR=localhost:9876 Run the provided quick‑start producer and consumer examples:
sh bin/tools.sh org.apache.rocketmq.example.quickstart.Producer sh bin/tools.sh org.apache.rocketmq.example.quickstart.ConsumerThe producer prints a SendResult with sendStatus=SEND_OK, and the consumer logs received messages.
Stop Services
Shutdown the broker: sh bin/mqshutdown broker Shutdown the NameServer: sh bin/mqshutdown namesrv Both commands send a shutdown request and confirm termination.
Contact
Author: Peng Lei – http://www.ymq.io/2018/01/29/MongoDB-2 – Email: [email protected] – WeChat: "搜云库" (public account for development knowledge sharing).
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
Architect's Tech Stack
Java backend, microservices, distributed systems, containerized programming, and more.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
