In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-01 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article is about how to deploy Docker rocketmq. The editor thinks it is very practical, so share it with you as a reference and follow the editor to have a look.
Preparatory work
Before building, we need to do some preparatory work, here we need to use docker to build the service, so we need to install docker in advance. In addition, because rocketmq needs to deploy broker and nameserver, considering that it is troublesome to deploy separately, docker-compose will be used here.
The rocketmq architecture diagram is as follows:
In addition, you need to set up a web visual console to monitor the status of the mq service, as well as message consumption. Rocketmq-console is used here, and the program will also be installed using docker.
Deployment process
First of all, we need a rocketmq docker image. Here we can choose to make it ourselves, pull the git@github.com:apache/rocketmq-docker.git directly, and then create an image. In addition, you can also directly use the official image on docker hub, the image name: rocketmqinc/rocketmq.
Next, create the mq configuration file broker.conf, which is placed in / opt/rocketmq/conf and configured as follows:
BrokerClusterName = DefaultCluster brokerName = broker-a brokerId = 0 deleteWhen = 04 fileReservedTime = 48 brokerRole = ASYNC_MASTER flushDiskType = ASYNC_FLUSH # if the local program calls the CVM mq, this needs to be set to CVM IPbrokerIP1=10.10.101.80
Create the following folder: / opt/rocketmq/logs,/opt/rocketmq/store, and finally create the docker-compose.yml file with the following configuration:
Version: '2'services: namesrv: image: rocketmqinc/rocketmq container_name: rmqnamesrv ports:-9876 rocketmqinc/rocketmq container_name volumes:-/ opt/rocketmq/logs:/home/rocketmq/logs-/ opt/rocketmq/store:/home/rocketmq/store command: sh mqnamesrv broker: image: rocketmqinc/rocketmq container_name: rmqbroker ports:-10909-10911 volumes: -/ opt/rocketmq/logs:/home/rocketmq/logs-/ opt/rocketmq/store:/home/rocketmq/store-/ opt/rocketmq/conf/broker.conf:/opt/rocketmq-4.4.0/conf/broker.conf # command: sh mqbroker-n namesrv:9876 command: sh mqbroker-n namesrv:9876-c.. / conf/broker.conf depends_on:-namesrv environment:-JAVA_HOME= / usr/lib/jvm/jre console: image: styletang/rocketmq-console-ng container_name: rocketmq-console-ng ports:-8087 depends_on:-namesrv environment:-JAVA_OPTS=-Dlogging.level.root=info-Drocketmq.namesrv.addr=rmqnamesrv:9876-Dcom.rocketmq.sendMessageWithVIPChannel=false
Pay attention
It is important to note that both rocketmq broker and rokcetmq-console need to connect to rokcetmq nameserver and need to know nameserver ip. After using docker-compose, the above three docker containers will be choreographed together. You can directly use the container name instead of the container ip, such as the nameserver container name rmqnamesrv here.
After the configuration is completed, run docker-compose up to start the three containers. After starting successfully, visit ip:8087 and view the external console of mq. If you can see the following information, the rocketmq service starts successfully.
First experience of rocketmq
Here, springboot will be used to quickly get started with mq, and the rocketmq-spring-boot-starter module will be used. Pom is configured as follows:
Org.apache.rocketmq rocketmq-spring-boot-starter 2.0.3
The configuration of the consumer service sender is as follows:
# # application.propertiesrocketmq.name-server=ip:9876rocketmq.producer.group=my-group
The procedure for the sender of consumer service is as follows:
@ SpringBootApplicationpublic class ProducerApplication implements CommandLineRunner {@ Resource private RocketMQTemplate rocketMQTemplate; public static void main (String [] args) {SpringApplication.run (ProducerApplication.class, args);} public void run (String...) Args) throws Exception {rocketMQTemplate.convertAndSend ("test-topic-1", "Hello, World!"); rocketMQTemplate.send ("test-topic-1", MessageBuilder.withPayload ("Hello, World! I'm from spring message"). Build ();}}
The message consumer is configured as follows:
# # application.propertiesrocketmq.name-server=ip:9876
The message consumer runs the program as follows:
@ SpringBootApplicationpublic class ConsumerApplication {public static void main (String [] args) {SpringApplication.run (ConsumerApplication.class, args);} @ Slf4j @ Service @ RocketMQMessageListener (topic = "test-topic-1", consumerGroup = "my-consumer_test-topic-1") public static class MyConsumer1 implements RocketMQListener {public void onMessage (String message) {log.info ("received message: {}", message);} related questions
The message sender sends an exception, as shown in the figure: Caused by: org.apache.rocketmq.remoting.exception.RemotingTooMuchRequestException: sendDefaultImpl call timeout.
This exception is caused by the incorrect setting of brokerip. Log in to the mq service console and view the broker configuration information.
The above 192.168.128.3 IP 10911 is the docker container IP, which is an internal host IP. Here, you need to set IP to the IP of the CVM, and modify the brokerIP1 parameter in broker.conf.
The mq console cannot view mq service information properly.
This problem is mainly caused by the wrong nameserver ip setting. Check the operation and maintenance page of the mq console to see the nameserver address information of the connection at this time.
You can see that the address set here is 127.0.0.1pur9876. Since the docker container is used in the mq console, direct access to 127.0.0.1 9876 in the container will access its own internal program rather than the correct program in the host.
Here, you need to configure the environment variable in docker, as follows:
-JAVA_OPTS=-Dlogging.level.root=info-Drocketmq.namesrv.addr=rmqnamesrv:9876 Thank you for reading! This is the end of the article on "how to deploy Docker rocketmq". I hope the above content can be of some help to you, so that you can learn more knowledge. if you think the article is good, you can share it for more people to see!
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.