In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/02 Report--
RocketMQ how to get started quickly, I believe that many inexperienced people do not know what to do, so this article summarizes the causes of the problem and solutions, through this article I hope you can solve this problem.
This chapter briefly describes the introduction of RocketMQ, message sending and message receiving.
Introduce rocketmq-client org.apache.rocketmq rocketmq-client 4.2.0 to write Producerpublic class Producer {public static void main (String [] args) throws MQClientException, InterruptedException {DefaultMQProducer producer = new DefaultMQProducer ("producer_test"); producer.setNamesrvAddr ("10.10.12.203 producer.start (); for (int I = 0; I)
< 100; i++) { try { //构建消息 Message msg = new Message("TopicTest" /* Topic */, "TagA" /* Tag */, ("测试RocketMQ" + i).getBytes(RemotingHelper.DEFAULT_CHARSET) ); SendResult sendResult = producer.send(msg); System.out.printf("%s%n", sendResult); } catch (Exception e) { e.printStackTrace(); Thread.sleep(1000); } } producer.shutdown(); }} 查看结果 编写Consumerpublic static void main(String[] args){ try { DefaultMQPushConsumer consumer = new DefaultMQPushConsumer(); consumer.setConsumerGroup("consumer_test_push"); consumer.setNamesrvAddr("10.10.12.203:9876;10.10.12.204:9876"); consumer.subscribe("TopicTest", "*"); consumer.registerMessageListener(new MessageListenerConcurrently(){ @Override public ConsumeConcurrentlyStatus consumeMessage(List paramList, ConsumeConcurrentlyContext paramConsumeConcurrentlyContext) { try { for(MessageExt msg : paramList){ String msgbody = new String(msg.getBody(), "utf-8"); System.out.println(" MessageBody: "+ msgbody);//输出消息内容 } } catch (Exception e) { e.printStackTrace(); return ConsumeConcurrentlyStatus.RECONSUME_LATER; //稍后再试 } return ConsumeConcurrentlyStatus.CONSUME_SUCCESS; //消费成功 } }); consumer.start(); } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } } 查看结果When you see the results of consumption, you may wonder why we produce messages sequentially when we produce messages, and why we don't consume them sequentially when we consume them.
The disorder of MQ messages. Each topic corresponds to multiple queues. When producing messages, they are placed in different queues according to the algorithm, while consumption is out of order (discussed later in ordered messages).
It is also possible that a message is consumed many times. The goal of RocketMQ is not to lose data, and each message is sent at least once. The internal implementation through ACK's confirmation mechanism will focus on later discussion.
Message management console
In order to easily view the details of the message, we can better manage and view the details of the message through the control console of the message. of course, we can also provide more management for the operation and maintenance through the commands provided by the background.
RocketMQ-Console address: https://github.com/apache/rocketmq-externals/tree/master/rocketmq-console
You can download directly to the local and then compile through mavne to get jar. This project is a SpringBoot project.
Mvn clean package-Dmaven.test.skip=truejava-jar target/rocketmq-console-ng-1.0.0.jar
Throw it on the linux server and start it.
(1) set specific RocketMQ parameters at startup
Java-jar rocketmq-console-ng-1.0.0.jar-server.port=12581-rocketmq.config.namesrvAddr=10.10.12.203:9876;10.10.12.204:9876
(2) directly modify the configuration file in rocketmq-console-ng-1.0.0.jar, find the file rocketmq-console-ng-1.0.0.jar\ BOOT-INF\ classes\ application.properties, and modify the value of rocketmq.config.namesrvAddr according to your NamesrvAddr. The default port is 12581.
Log in to the browser to view console information
View node information of RocketMQ cluster
Query messages based on the subject time period
View the specific information of a message
The control console provides a lot of operation and maintenance functions that can greatly improve our operation and maintenance efficiency, including creating themes, modifying themes, sending messages, viewing consumer information and other functions that we do not introduce one by one, and can be easily understood and used.
After reading the above, have you mastered how to get started with RocketMQ? If you want to learn more skills or want to know more about it, you are welcome to follow the industry information channel, thank you for reading!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.