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 [email protected]: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

Display mode of elements in CSS

In CSS, element tags are divided into two categor...

Detailed explanation of Vue components

<body> <div id="root"> <...

Nginx merges request connections and speeds up website access examples

Preface As one of the best web servers in the wor...

Vue+element ui realizes anchor positioning

This article example shares the specific code of ...

How to find websites with SQL injection (must read)

Method 1: Use Google advanced search, for example...

Basic application methods of javascript embedded and external links

Table of contents Basic application of javascript...

How to create a basic image of the Python runtime environment using Docker

1. Preparation 1.1 Download the Python installati...

52 SQL statements to teach you performance optimization

1. To optimize the query, try to avoid full table...

Implementation of React page turner (including front and back ends)

Table of contents front end According to the abov...

Color matching techniques and effect display for beauty and styling websites

Color is one of the most important elements for a...

Detailed explanation of the use of React.cloneElement

Table of contents The role of cloneElement Usage ...

Detailed analysis of the chmod command to modify file permissions under Linux

Use the Linux chmod command to control who can ac...

How to install golang under linux

Go is an open source programming language that ma...