cat /etc/redhat-release
CentOS Linux release 7.3.1611 (Core)
uname -a
Linux master 3.10.0-514.el7.x86_64 #1 SMP Tue Nov 22 16:42:41 UTC 2016 x86_64 x86_64 x86_64 GNU/Linux
tar -zxvf jdk-8u231-linux-x64.tar.gz -C /opt/soft
tar -zxvf apache-maven-3.5.4-bin.tar.gz -C /opt/soft
unzip rocketmq-all-4.4.0-bin-release.zip -d /opt/soft/rocketmq
vi /etc/profile
JAVA_HOME=/opt/soft/jdk1.8.0_231
PATH=$JAVA_HOME/bin:$PATH
CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar
MAVEN_HOME=/opt/soft/apache-maven-3.5.4
PATH=$PATH:$MAVEN_HOME/bin
ROCKETMQ_HOME=/opt/soft/rocketmq/
PATH=$ROCKETMQ_HOME/bin:$PATH
export JAVA_HOME
export PATH
export CLASSPATH
export ROCKETMQ_HOME
source /etc/profile
java -version
java version "1.8.0_231"
Java(TM) SE Runtime Environment (build 1.8.0_231-b11)
mvn -v
Apache Maven 3.5.4 (1edded0938998edf8bf061f1ceb3cfdeccf443fe; 2018-06-18T02:33:14+08:00)
Maven home: /opt/soft/apache-maven-3.5.4
Java version: 1.8.0_231, vendor: Oracle Corporation, runtime: /opt/soft/jdk1.8.0_231/jre
Default locale: zh_CN, platform encoding: UTF-8
OS name: "linux", version: "3.10.0-514.el7.x86_64", arch: "amd64", family: "unix"
# 创建软连接
ln -s rocketmq-4.4.0/ rocketmq
mkdir -p /opt/soft/rocketmq/data
mkdir -p /opt/soft/rocketmq/logs
vim /opt/soft/rocketmq/conf/broker.conf
修改内容如下:
brokerClusterName = DefaultCluster
brokerName = broker-a
brokerId = 0
deleteWhen = 04
fileReservedTime = 48
brokerRole = ASYNC_MASTER
flushDiskType = ASYNC_FLUSH
# rocket-name服务地址,多个地址用;分开
namesrvAddr=192.168.100.129:9876
brokerIP1=192.168.100.129
#允许自动创建主题topic
autoCreateTopicEnable=true
#broker监听端口
listenPort=10911
#数据存储位置
storePathRootDir=/opt/soft/rocketmq/data
storePathCommitLog=/opt/soft/rocketmq/logs
JAVA_OPT="${JAVA_OPT} -server -Xms512m -Xmx512m -Xmn256m -XX:MetaspaceSize=128m -XX:MaxMetaspaceSize=128m"
JAVA_OPT="${JAVA_OPT} -server -Xms512m -Xmx512m -Xmn128m"
[root@master bin]# nohup mqnamesrv -n 192.168.100.129:9876 &
[1] 2937
[root@master bin]# nohup: 忽略输入并把输出追加到"nohup.out"
[root@master bin]# nohup mqbroker -n 192.168.100.129:9876 - c ../conf/broker.conf autoCreateTopicEnable=true &
[2] 2968
[root@master bin]# nohup: 忽略输入并把输出追加到"nohup.out"
# 查看broker启动配置:
[root@master bin]# sh mqbroker -m
[root@master bin]# jps
3030 Jps
2940 NamesrvStartup
2972 BrokerStartup
tail -200f ~/logs/rocketmqlogs/namesrv.log
tail -200f ~/logs/rocketmqlogs/broker.log
# 设置NameServer地址
export NAMESRV_ADDR=192.168.100.129:9876
# 测试发送端
sh tools.sh org.apache.rocketmq.example.quickstart.Producer
# 测试消费端
sh tools.sh org.apache.rocketmq.example.quickstart.Consumer
[root@master bin]# sh mqshutdown broker
The mqbroker(2972) is running...
Send shutdown request to mqbroker(2972) OK
[root@master bin]# sh mqshutdown namesrv
The mqnamesrv(2940) is running...
Send shutdown request to mqnamesrv(2940) OK
git clone https://github.com/apache/rocketmq-externals.git
rocketmq-externals/rocketmq-console
mvn clean package -Dmaven.test.skip=true
rocketmq-externals/rocketmq-console/target/rocketmq-console-ng-1.0.1.jar
java -jar rocketmq-console-ng-1.0.1.jar --rocketmq.config.namesrvAddr='192.168.100.129:9876'
# 关闭防火墙
systemctl stop firewalld.service
# 查看防火墙状态
firewall-cmd --state
http://192.168.100.129:8080/#/
DefaultMQProducer producer = new DefaultMQProducer("ts_group");
producer.setNamesrvAddr("192.168.100.129:9876");
producer.setInstanceName("Instance1");
producer.setRetryTimesWhenSendFailed(3);
producer.start();
System.out.println("product start ...");
for(int i=0; i<4; i++) {
Message message = new Message("ts_topic",
"TagA",
"key-" + i,
("Hello RocketMQ-" + i).getBytes());
SendResult sr = producer.send(message);
System.out.println(sr);
}
producer.shutdown();
DefaultMQPushConsumer consumer = new DefaultMQPushConsumer("ts_group");
consumer.setNamesrvAddr("192.168.100.129:9876");
consumer.setConsumeFromWhere(ConsumeFromWhere.CONSUME_FROM_FIRST_OFFSET);
consumer.subscribe("ts_topic","*");
consumer.registerMessageListener(new MessageListenerConcurrently() {
@Override
public ConsumeConcurrentlyStatus consumeMessage(List<MessageExt> msgs, ConsumeConcurrentlyContext context) {
MessageExt msg = msgs.get(0);
try {
Integer queueId = msg.getQueueId();
String msgId = msg.getMsgId();
String topic = msg.getTopic();
String tags = msg.getTags();
String keys = msg.getKeys();
String msgBody = new String(msg.getBody(), RemotingHelper.DEFAULT_CHARSET);
System.out.println(msg);
} catch (Exception ex) {
ex.printStackTrace();
return ConsumeConcurrentlyStatus.RECONSUME_LATER;
}
return ConsumeConcurrentlyStatus.CONSUME_SUCCESS;
}
});
consumer.start();
System.out.println("consumer start ...");