Implementation example of Docker rocketmq deployment

Implementation example of Docker rocketmq deployment

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.

Preparation

Before 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: rocketmqinc/rocketmq .

Next, create the MQ configuration file broker.conf and place it in /opt/rocketmq/conf . The configuration is 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 cloud host mq, this needs to be set to the cloud host IP
brokerIP1=10.10.101.80

Create the following folders: /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: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 rocketmq-spring-boot-starter module. The pom configuration is as follows:

<!--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 Caused by: org.apache.rocketmq.remoting.exception.RemotingTooMuchRequestException: sendDefaultImpl call timeout .

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 192.168.128.3:10911 is the docker container IP, which is a host internal IP. Here you need to set the IP to the IP of the cloud host, and modify brokerIP1 parameter in broker.conf .

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: 127.0.0.1:9876 . Since the mq console here uses a docker container, directly accessing 127.0.0.1:9876 in the container will access the container itself instead of the correct program in the host machine.

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
RocketMq docker construction and basic concepts
RocketMQ-Spring

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:
  • Fault avoidance mechanism designed by RocketMQ
  • RabbitMQ, RocketMQ, Kafka transaction, message loss, message sequence and message duplication processing strategy issues
  • Asynchronous disk flushing in RocketMQ design
  • RocketMQ design synchronous disk flushing
  • RocketMQ design master-slave replication and read-write separation

<<:  Should I use Bootstrap or jQuery Mobile for mobile web wap

>>:  How to understand the difference between ref toRef and toRefs in Vue3

Recommend

MySQL database backup and recovery implementation code

Database backup #grammar: # mysqldump -h server-u...

A collection of possible problems when migrating sqlite3 to mysql

Brief description Suitable for readers: Mobile de...

Several implementation methods of the tab bar (recommended)

Tabs: Category + Description Tag bar: Category =&...

Put frameset in body through iframe

Because frameset and body are on the same level, y...

How to get/calculate the offset of a page element using JavaScript

question By clicking a control, a floating layer ...

How to write a Node.JS version of a game

Table of contents Overview Build Process Related ...

Summary of 4 methods of div+css layout to achieve 2-end alignment of css

The div+css layout to achieve 2-end alignment is ...

Installation tutorial of MySQL 5.1 and 5.7 under Linux

The operating system for the following content is...

Two ways to create SSH server aliases in Linux

Preface If you frequently access many different r...

js version to realize calculator function

This article example shares the specific code of ...

Rendering Function & JSX Details

Table of contents 1. Basics 2. Nodes, trees, and ...

Centos7 installation of FFmpeg audio/video tool simple document

ffmpeg is a very powerful audio and video process...

How to install and connect Navicat in MySQL 8.0.20 and what to pay attention to

Things to note 1. First, you need to create a my....

Overview of time configuration under Linux system

1. Time types are divided into: 1. Network time (...