MAC下搭建RocketMQ

1. 从发布版下载并构建

点击 这里 下载4.2.0发行版源代码,也可以点击 这里 下载二进制发行版。

现在执行以下命令来解压4.2.0源版本并构建.

1

2

3

4

$ unzip rocketmq-all-4.2.0-source-release.zip

$ cd rocketmq-all-4.2.0/

$ mvn -Prelease-all -DskipTests clean install -U

$ cd distribution/target/apache-rocketmq

2.环境配置

在.bash_profile中配置mq的环境变量

1

$ vim .bash_profile

2

export ROCKETMQ_HOME=/Development/RuntimeEnvironment/rocketmq

export PATH=$ROCKETMQ_HOME/bin:$PATH

3

$ source /etc/profile

3. 启动 Name Server服务

1

2

3

$ nohup sh bin/mqnamesrv &

$ tail -f ~/logs/rocketmqlogs/namesrv.log

The Name Server boot success...

4. 启动 broker

1

2

3

$ nohup sh bin/mqbroker -n 127.0.0.1:9876 &

$ tail -f ~/logs/rocketmqlogs/broker.log

The broker[%s, 172.30.30.233:10911] boot success...

指定broker.conf配置文件:

1

nohup sh bin/mqbroker -n 127.0.0.1:9876 -c ./conf/broker.conf &

5.发送和接收消息

在发送/接收消息之前,我们需要告诉客户端服务器的位置。 RocketMQ提供了多种方式来实现这一点。 为了简单起见,我们使用环境变量NAMESRV_ADDR

1

2

3

4

5

6

$ 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...

6.关闭服务

1

2

3

4

5

6

7

$ 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

发布了102 篇原创文章 · 获赞 10 · 访问量 2万+

猜你喜欢

转载自blog.csdn.net/u012921921/article/details/104322321