I recently learned to use RocketMQ and needed to build a RocketMQ server. This article mainly records the RocketMQ construction process and some pitfalls encountered in this process. PreparationBefore building, we need to do some preparation. Here we need to use docker to build the service, so we need to install docker in advance. In addition, since rocketmq requires the deployment of broker and nameserver, and considering that separate deployment is troublesome, docker-compose will be used here. The rocketmq architecture diagram is as follows: In addition, you also need to build a web visualization console to monitor the mq service status and message consumption. Rocketmq-console is used here, and the program will also be installed using docker. Deployment process First we need the rocketmq docker image. Here we can choose to make it ourselves, directly pull git@github.com:apache/rocketmq-docker.git, and then make the image. You can also directly use the official image on Docker Hub, the image name is: Next, create the MQ configuration file brokerClusterName = DefaultCluster brokerName = broker-a brokerId = 0 deleteWhen = 04 fileReservedTime = 48 brokerRole = ASYNC_MASTER flushDiskType = ASYNC_FLUSH # If the local program calls the cloud host mq, this needs to be set to the cloud host IP brokerIP1=10.10.101.80 Create the following folders: version: '2' services: namesrv: image: rocketmqinc/rocketmq container_name: rmqnamesrv ports: -9876:9876 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:10909 - 10911:10911 - 10912:10912 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: -namerv environment: -JAVA_HOME=/usr/lib/jvm/jre console: image: styletang/rocketmq-console-ng container_name: rocketmq-console-ng ports: -8087:8080 depends_on: -namerv environment: -JAVA_OPTS= -Dlogging.level.root=info -Drocketmq.namesrv.addr=rmqnamesrv:9876 - Dcom.rocketmq.sendMessageWithVIPChannel=false Note It should be noted here that both rocketmq broker and rokcetmq-console need to connect to the rokcetmq nameserver, and you need to know the nameserver IP. After using docker-compose, the above three docker containers will be orchestrated together. You can directly use the container name instead of the container IP, such as the nameserver container name rmqnamesrv. After the configuration is complete, run docker-compose up to start the three containers. After successful startup, access ip:8087 and check the mq external console. If you can see the following information, the rocketmq service is started successfully. First experience with RocketMQ Here we will use springboot to quickly get started with mq, and will use the <!--Add dependencies in pom.xml--> <dependency> <groupId>org.apache.rocketmq</groupId> <artifactId>rocketmq-spring-boot-starter</artifactId> <version>2.0.3</version> </dependency> The consumer service sender is configured as follows: ## application.properties rocketmq.name-server=ip:9876 rocketmq.producer.group=my-group The consumer service sender procedure is as follows: @SpringBootApplication public 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 configuration is as follows: ## application.properties rocketmq.name-server=ip:9876 The message consumer runs the following program: @SpringBootApplication public 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<String> { public void onMessage(String message) { log.info("received message: {}", message); } } } Related questions The message sender This exception is caused by the brokerip not being set correctly. Log in to the mq service console to view the broker configuration information. Above The mq console cannot view the mq service information normally. This problem is mainly caused by incorrect nameserver IP settings. Check the mq console operation and maintenance page to see the nameserver address information connected at this time. You can see that the address set here is: Here you need to configure the environment variables in Docker, the configuration is as follows: -JAVA_OPTS= -Dlogging.level.root=info -Drocketmq.namesrv.addr=rmqnamesrv:9876 Help Documentation rocketmq-docker Author:Leo_wl Source: http://www.cnblogs.com/Leo_wl/ This is the end of this article about the implementation example of Docker rocketmq deployment. For more relevant Docker rocketmq deployment content, please search for previous articles on 123WORDPRESS.COM or continue to browse the following related articles. I hope you will support 123WORDPRESS.COM in the future! You may also be interested in:
|
<<: Should I use Bootstrap or jQuery Mobile for mobile web wap
>>: How to understand the difference between ref toRef and toRefs in Vue3
Database backup #grammar: # mysqldump -h server-u...
Brief description Suitable for readers: Mobile de...
Tabs: Category + Description Tag bar: Category =&...
Because frameset and body are on the same level, y...
question By clicking a control, a floating layer ...
Table of contents Overview Build Process Related ...
The div+css layout to achieve 2-end alignment is ...
Table of contents First we need to build the page...
The operating system for the following content is...
Preface If you frequently access many different r...
This article example shares the specific code of ...
Table of contents 1. Basics 2. Nodes, trees, and ...
ffmpeg is a very powerful audio and video process...
Things to note 1. First, you need to create a my....
1. Time types are divided into: 1. Network time (...