一、项目需要用到Apache RocketMQ
Apache RocketMQ™ is an open source distributed messaging and streaming data platform.
这是阿里开源的一个消息中间件框架。
官网:官网
二、下面来快速开始
官方的快速开始文档
三、系统要求
The following softwares are assumed installed:
64bit OS, Linux/Unix/Mac is recommended;
64bit JDK 1.8+;
Maven 3.2.x
Git
四、先要去下载安装包
安装包网址
五、点击这个下载
六、解压
unzip rocketmq-all-4.2.0-source-release.zip
七、进入到项目目录下
cd rocketmq-all-4.2.0/
八、执行安装的操作
~/aliSpace/recketmq/rocketmq-all-4.2.0 ⌚ 14:20:14
$ mvn -Prelease-all -DskipTests clean install -U
[INFO] Scanning for projects...
[INFO] ------------------------------------------------------------------------
[INFO] Detecting the operating system and CPU architecture
[INFO] ------------------------------------------------------------------------
[INFO] os.detected.name: osx
[INFO] os.detected.arch: x86_64
[INFO] os.detected.classifier: osx-x86_64
......
[INFO] rocketmq-distribution 4.2.0 ........................ SUCCESS [ 4.717 s]
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 28.456 s
[INFO] Finished at: 2018-04-09T14:21:40+08:00
[INFO] Final Memory: 85M/1608M
[INFO] ------------------------------------------------------------------------
九、安装完成后是这个样子
~/aliSpace/recketmq/rocketmq-all-4.2.0 ⌚ 14:21:41
$ ls
1 client openmessaging
BUILDING common pom.xml
CONTRIBUTING.md dev remoting
DEPENDENCIES distribution srvutil
LICENSE example store
NOTICE filter style
PULL_REQUEST_TEMPLATE.md filtersrv target
README.md logappender test
broker namesrv tools
十、进入到启动文件所在的目录
~/aliSpace/recketmq/rocketmq-all-4.2.0 ⌚ 14:56:26
$ cd distribution/target/apache-rocketmq
~/aliSpace/recketmq/rocketmq-all-4.2.0/distribution/target/apache-rocketmq ⌚ 14:57:34
$ ls
LICENSE NOTICE README.md benchmark bin conf lib
十一、启动服务器,查看输出日志
启动服务器
~/aliSpace/recketmq/rocketmq-all-4.2.0/distribution/target/apache-rocketmq ⌚ 15:00:25
$ nohup sh bin/mqnamesrv &
查看启动日志
~/aliSpace/recketmq/rocketmq-all-4.2.0/distribution/target/apache-rocketmq ⌚ 15:00:44
$ tail -f ~/logs/rocketmqlogs/namesrv.log
2018-04-09 15:00:37 INFO main - tls.server.trustCertPath = null
2018-04-09 15:00:37 INFO main - tls.client.keyPath = null
2018-04-09 15:00:37 INFO main - tls.client.keyPassword = null
2018-04-09 15:00:37 INFO main - tls.client.certPath = null
2018-04-09 15:00:37 INFO main - tls.client.authServer = false
2018-04-09 15:00:37 INFO main - tls.client.trustCertPath = null
2018-04-09 15:00:37 INFO main - Using OpenSSL provider
2018-04-09 15:00:37 INFO main - SSLContext created for server
2018-04-09 15:00:37 INFO NettyEventExecutor - NettyEventExecutor service started
2018-04-09 15:00:37 INFO main - The Name Server boot success. serializeType=JSON
2018-04-09 15:01:37 INFO NSScheduledThread1 - --------------------------------------------------------
2018-04-09 15:01:37 INFO NSScheduledThread1 - configTable SIZE: 0
十二、启动经纪人,查看经纪人的启动日志
启动经纪人人
~/aliSpace/recketmq/rocketmq-all-4.2.0/distribution/target/apache-rocketmq ⌚ 15:02:57
$ nohup sh bin/mqbroker -n localhost:9876 &
[1] 2196
appending output to nohup.out
查看经纪人的启动日志
~/aliSpace/recketmq/rocketmq-all-4.2.0/distribution/target/apache-rocketmq ⌚ 15:03:15
$ tail -f ~/logs/rocketmqlogs/broker.log
2018-04-09 15:03:21 INFO main - load /Users/wangdong/store/config/consumerFilter.json OK
2018-04-09 15:03:21 INFO main - load /Users/wangdong/store/config/delayOffset.json OK
2018-04-09 15:03:21 INFO main - Set user specified name server address: localhost:9876
2018-04-09 15:03:21 INFO PullRequestHoldService - PullRequestHoldService service started
2018-04-09 15:03:21 INFO main - register broker to name server localhost:9876 OK
2018-04-09 15:03:21 INFO main - The broker[wdMac.local, 192.168.33.204:10911] boot success. serializeType=JSON and name server is localhost:9876
十三、发送或者接收消息
Before sending/receiving messages, we need to tell clients the location of name servers. RocketMQ provides multiple ways to achieve this. For simplicity, we use environment variable NAMESRV_ADDR
译:在发送/接收消息前,我们需要告诉客户端:消息服务器的地址:端口(本地的话可以用localhost:端口)。RocketMQ提供多种方式来实现它。
1.下面我们以命令行设置NAMESRV_ADDR的方式来实现它。
注意需要进入到mq目录下:
~/aliSpace/recketmq/rocketmq-all-4.2.0/distribution/target/apache-rocketmq ⌚ 15:17:31
$ export NAMESRV_ADDR=localhost:9876
2.发送一条消息
~/aliSpace/recketmq/rocketmq-all-4.2.0/distribution/target/apache-rocketmq ⌚ 15:26:44
$ sh bin/tools.sh org.apache.rocketmq.example.quickstart.Producer
SendResult [sendStatus=SEND_OK, msgId= ...
3.接收消息
~/aliSpace/recketmq/rocketmq-all-4.2.0/distribution/target/apache-rocketmq ⌚ 15:26:44
$ sh bin/tools.sh org.apache.rocketmq.example.quickstart.Consumer
ConsumeMessageThread_%d Receive New Messages: [MessageExt...
十四、关闭服务器和经纪人
关闭服务器
~/aliSpace/recketmq/rocketmq-all-4.2.0/distribution/target/apache-rocketmq ⌚ 15:25:25
$ sh bin/mqshutdown namesrv
The mqnamesrv(2083) is running...
Send shutdown request to mqnamesrv(2083) OK
关闭经纪人
~/aliSpace/recketmq/rocketmq-all-4.2.0/distribution/target/apache-rocketmq ⌚ 15:29:53
$ sh bin/mqshutdown broker
The mqbroker(2207) is running...
Send shutdown request to mqbroker(2207) OK
好了,一个简单的开始就结束了