本文用到的安装包和可视化,链接:百度云
或者去官网自行下载,注:官网的可视化需要添加pom.xml依赖,我贴在下方了。
<dependency> <groupId>javax.xml.bind</groupId> <artifactId>jaxb-api</artifactId> <version>2.3.0</version> </dependency> <dependency> <groupId>com.sun.xml.bind</groupId> <artifactId>jaxb-impl</artifactId> <version>2.3.0</version> </dependency> <dependency> <groupId>com.sun.xml.bind</groupId> <artifactId>jaxb-core</artifactId> <version>2.3.0</version> </dependency> <dependency> <groupId>javax.activation</groupId> <artifactId>activation</artifactId> <version>1.1.1</version> </dependency>View Code
1.解压文件
unzip rocketmq-all-4.9.0-bin-release.zip
2.修改这2个文件 bin/runserver.sh ,bin/runbroker.sh
runbroker.sh:
#JAVA_OPT="${JAVA_OPT} -server -Xms8g -Xmx8g -Xmn4g"
JAVA_OPT="${JAVA_OPT} -server -Xms400m -Xmx400m -Xmn200m"
runserver.sh:
#JAVA_OPT="${JAVA_OPT} -server -Xms4g -Xmx4g -Xmn2g -XX:MetaspaceSize=128m -XX:MaxMetaspaceSize=320m"
JAVA_OPT="${JAVA_OPT} -server -Xms400m -Xmx400m -Xmn200m -XX:MetaspaceSize=128m -XX:MaxMetaspaceSize=128m"
3.启动nameserver并查看是否成功
sh bin/mqnamesrv &
tail -f ~/logs/rocketmqlogs/namesrv.log
4.启动broker并查看是否成功
nohup sh bin/mqbroker -n localhost:9876 &
tail -f ~/logs/rocketmqlogs/broker.log
mq安装完成,接下来可视化安装
5.修改可视化端口号和nameserver地址:
6.执行maven命令,打jar包
clean package -Dmaven.test.skip=true
7.启动jar包并登录可视化
java -jar rocketmq-console-ng-1.0.0.jar
8.消息测试:
<dependency> <groupId>org.apache.rocketmq</groupId> <artifactId>rocketmq-client</artifactId> <version>4.9.0</version> </dependency>
@GetMapping("/proder") @ResponseBody public String proder() throws Exception{ DefaultMQProducer producer = new DefaultMQProducer("ProderGroup"); producer.setNamesrvAddr("127.0.0.1:9876"); producer.start(); producer.setSendMsgTimeout(30000); for (int i = 0; i < 2; i++) { Message msg = new Message("order" ,("Hello_RocketMQ " + i).getBytes("UTF-8")); SendResult sendResult = producer.send(msg); System.out.println("sendResult======"+sendResult); //System.out.printf("%s%n", sendResult); } System.out.println("生产者发送了"); producer.shutdown(); return "null"; } @GetMapping("/consumer") @ResponseBody public String consumer() throws Exception{ DefaultMQPushConsumer consumer = new DefaultMQPushConsumer("ConsumerGroup"); consumer.setNamesrvAddr("127.0.0.1:9876"); consumer.subscribe("order","*"); consumer.registerMessageListener(new MessageListenerConcurrently() { @Override public ConsumeConcurrentlyStatus consumeMessage(List<MessageExt> msgs, ConsumeConcurrentlyContext context) { System.out.println("msgs======"+msgs); System.out.println("context======"+context); return null; } }); consumer.start(); System.out.println("消费者启动"); return "null"; }
9.访问proder,然后查看可视化 展现出发送的2条消息:
10.访问consumer,然后查看可视化 展现出消息被消费
标签:OPT,JAVA,producer,centos,安装,System,可视化,consumer,rocketmq From: https://www.cnblogs.com/entertain/p/18120844