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 > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article mainly shows you "examples of the usage of RocketMq", which is easy to understand and clear. I hope it can help you solve your doubts. Let the editor lead you to study and learn the article "examples of the usage of RocketMq".
1. Set up rocketmq service
Download: https://www.apache.org/dyn/closer.cgi?path=rocketmq/4.5.1/rocketmq-all-4.5.1-bin-release.zip
# extract to: / usr/local/rocketmq-all-4.5.1-bin-release# Startup / shutdown Service: rocketmq # Startup: / usr/local/rocketmq-all-4.5.1-bin-release/bin/mqnamesrv-c / usr/local/rocketmq-all-4.5.1-bin-release/conf/namesrv.properties-n "192.168.1.180 usr/local/rocketmq-all-4.5.1-bin-release/conf/namesrv.properties 6500" & # set custom port: 6500-n / usr/local/rocketmq-all-4.5.1-bin-release/conf/namesrv.properties # file content is: listenPort=6600 # close: / usr/local/rocketmq-all-4.5.1-bin-release/bin/mqshutdown namesrv mqbroker: # start: AutoCreateTopicEnable=true (allows micro services to create topic) / usr/local/rocketmq-all-4.5.1-bin-release/bin/mqbroker-n "192.168.1.180 usr/local/rocketmq-all-4.5.1-bin-release/bin/mqbroker 6500" autoCreateTopicEnable=true & # close: / usr/local/rocketmq-all-4.5.1-bin-release/bin/mqshutdown broker
two。 Producer-microservice (send-queue messages)
# message body-object: @ Data@Builder@ToStringpublic class MemberMoneyMessage {int memberId; String event; double money;} # send message: @ AutowiredRocketMQTemplate rocketMQTemplate .. rocketMQTemplate.convertAndSend ("member-money-act", MemberMoneyMessage.builder () .event ("pay-order") .memberId (50) .money (100) .build ();. Configure rocket server: rocketmq:name-server: tsca.cc:6600producer: group: tsca-group
3. Consumer-microservice (processing-queuing messages)
# snooping processing (the sender's member-money-act is the same as the receiver's member-money-act): @ Service@RocketMQMessageListener (consumerGroup = "tsca-group", topic = "member-money-act") @ Slf4jpublic class MemberMoneyMqListener implements RocketMQListener {@ Override public void onMessage (MemberMoneyMessage memberMoneyMessage) {log.info ("received-user balance change"); log.info (JSON.toJSONString (memberMoneyMessage)) }} # configuration: rocketmq: name-server: tsca.cc:6600 producer: group: tsca-group
4. Build: rocketmq- console
# 1. Download the source code git clone https://github.com/apache/rocketmq-externals.git# 2. Open the rocketmq-console project with IDEA and modify the rocketmq version of the pom file (2-1). Change the rocketmq version of the pom file: 4.4.15 to 4.5.1 (2-2). Change the code: org/apache/rocketmq/console/service/impl/MessageServiceImpl.java# 92 rowsDefaultMQPullConsumer consumer = new DefaultMQPullConsumer (MixAll.TOOLS_CONSUMER_GROUP, null); change to: RPCHook rpcHook = null;DefaultMQPullConsumer consumer = new DefaultMQPullConsumer (MixAll.TOOLS_CONSUMER_GROUP, rpcHook); # 3. Change configuration # current webpage console port server.port=6650# rocketmq service port rocketmq.config.namesrvAddr=192.168.1.180:6600# 4. Compile and package mvn clean package-DskipTests# 5. Run java-jar-Dserver.port=6650-Drocketmq.config.namesrvAddr=192.168.1.180:6600 rocketmq-console-ng-1.0.1.jar above is all the content of this article "examples of the usage of RocketMq". Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!
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.