附一个rocketmq各语言客户端仓库:https://github.com/apache/incubator-rocketmq-externals,我用go客户端,但是master分支的go没有producer,在go-client-develop分支有,尚未合并入主干。
1 安装jdk
1、http://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html挑一个jdk下载下来。因为需要accept license,不能wget直接下载
2、tar zxvf xxxx
3、mkdir /usr/local/jdk/jre-xx
4、mv xxx /usr/local/jdk/jre-xx
修改环境变量
# vi /etc/profile
#set java env
JAVA_HOME=/usr/local/jdk/
JRE_HOME=/usr/local/jdk/jre
CLASS_PATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar:$JAVA_HOME/lib
PATH=$PATH:$JAVA_HOME/bin:$JRE_HOME/bin
export JAVA_HOME JRE_HOME CLASS_PATH PATH
# source /etc/profile
验证java
#java -version
java version "1.8.0_144"
Java(TM) SE Runtime Environment (build 1.8.0_144-b01)
Java HotSpot(TM) 64-Bit Server VM (build 25.144-b01, mixed mode)
2 安装mvn
1、wget http://mirrors.hust.edu.cn/apache/maven/maven-3/3.5.0/binaries/apache-maven-3.5.0-bin.tar.gz
2、tar zxvf apache-maven-3.5.0-bin.tar.gz
3、mv apache-maven-3.5.0-bin.tar.gz /usr/local/apache-maven
4、# vi /etc/profile
export M2_HOME=/usr/local/apache-maven
export PATH=$PATH:$M2_HOME/bin
# source /etc/profile
5、验证是否安装成功
# mvn -version
Apache Maven 3.5.0 (ff8f5e7444045639af65f6095c62210b5713f426; 2017-04-04T03:39:06+08:00)
Maven home: /usr/local/apache-maven
Java version: 1.8.0_144, vendor: Oracle Corporation
Java home: /usr/local/jdk/jre
Default locale: zh_CN, platform encoding: UTF-8
OS name: "linux", version: "2.6.32-358.el6.x86_64", arch: "amd64", family: "unix"
6、配置maven国内镜像
修改maven根目录下的conf文件夹中的setting.xml文件,内容如下:
<mirrors>
<mirror>
<id>alimaven</id>
<name>aliyun maven</name>
<url>http://maven.aliyun.com/nexus/content/groups/public/</url>
<mirrorOf>central</mirrorOf>
</mirror>
</mirrors>
3 安装rocketmq
Clone & Build
> git clone https://github.com/apache/incubator-rocketmq.git
>
cdincubator-rocketmq
> mvn -Prelease-all -DskipTests clean install -U
>
cddistribution/target/apache-rocketmq
如果服务器内存不够,可以修改
runserver.sh
脚本(
mqnamesrv
文件中通过
runserver.sh
脚本调用
Name Server
的主函数
com.alibaba.rocketmq.namesrv.NamesrvStartup
启动
Name Server
)中的
JAVA_OPT_1
参数
Start Name Server
> nohup sh bin/mqnamesrv &
> tail -f ~/logs/rocketmqlogs/namesrv.log
The Name Server boot success...
Start Broker
> nohup sh bin/mqbroker -n localhost:9876 &
> tail -f ~/logs/rocketmqlogs/broker.log
The broker[%s, 172.30.30.233:10911] boot success...
Send & Receive Messages
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
>
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...
Shutdown Servers
> 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
More
https://rocketmq.incubator.apache.org/docs/quick-start/