Implementation steps for installing RocketMQ in docker

Implementation steps for installing RocketMQ in docker

1. Retrieve the image

docker search rocketmq 

Retrieve a specific version

curl https://registry.hub.docker.com/v1/repositories/foxiswho/rocketmq/tags | tr -d '[\[\]" ]' | tr '}' '\n' | awk -F: -v image='foxiswho/rocketmq' '{if(NR!=NF && $3 != ""){printf("%s:%s\n",image,$3)}}' 

View all versions of the current image shell command

curl https://registry.hub.docker.com/v1/repositories/foxiswho/rocketmq/tags\
| tr -d '[\[\]" ]' | tr '}' '\n'\
| awk -F: -v image='foxiswho/rocketmq' '{if(NR!=NF && $3 != ""){printf("%s:%s\n",image,$3)}}' 

2. Create Broker Server

docker run -d -p 9876:9876 --name rmqserver foxiswho/rocketmq:server-4.5.1 

3. Create a broker

docker run -d -p 10911:10911 -p 10909:10909\
 --name rmqbroker --link rmqserver:namesrv\
 -e "NAMESRV_ADDR=namesrv:9876" -e "JAVA_OPTS=-Duser.home=/opt"\
 -e "JAVA_OPT_EXT=-server -Xms128m -Xmx128m"\
 foxiswho/rocketmq:broker-4.5.1 

Configure broker.conf

Enter the rmqbroker container

docker exec -it rmqbroker /bin/bash

cd /etc/rocketmq/

vi broker.conf

4. Create RocketMQ console

docker run -d --name rmqconsole -p 8180:8080 --link rmqserver:namesrv\
 -e "JAVA_OPTS=-Drocketmq.namesrv.addr=namesrv:9876\
 -Dcom.rocketmq.sendMessageWithVIPChannel=false"\
 -t styletang/rocketmq-console-ng 

Then check the startup status with the following command

docker ps | grep rocketmq

http://192.168.23.131:8180/

5. Testing

Since I installed rocketmq on the host machine, the test is as follows:

#Test message sending command sh tools.sh org.apache.rocketmq.example.quickstart.Producer 

#Test message receiving command sh tools.sh org.apache.rocketmq.example.quickstart.Consumer

6. Java Sample

<dependency>
	    <groupId>org.apache.rocketmq</groupId>
	    <artifactId>rocketmq-client</artifactId>
	    <version>4.9.2</version>
	</dependency>

Message sending (Producer sends synchronous messages)

import org.apache.rocketmq.client.producer.DefaultMQProducer;
import org.apache.rocketmq.client.producer.SendResult;
import org.apache.rocketmq.common.message.Message;
import org.apache.rocketmq.remoting.common.RemotingHelper;
 
 
public class SyncProducer {
	public static void main(String[] args) throws Exception {
    	// Instantiate the message producer Producer
        DefaultMQProducer producer = new DefaultMQProducer("zhuzeqing-1");
    	// Set the address of NameServer producer.setNamesrvAddr("192.168.23.131:9876");
    	// Start the Producer instance producer.start();
    	for (int i = 0; i < 1; i++) {
    	    // Create a message and specify the Topic, Tag and message body Message msg = new Message("zhuzeqing-1-Topic" /* Topic */,
        	"TagA" /* Tag */,
        	("hello, rocketmq --" + i).getBytes(RemotingHelper.DEFAULT_CHARSET) /* Message body */
        	);
        	// Send a message to a Broker
            SendResult sendResult = producer.send(msg);
            // Use sendResult to return whether the message was successfully delivered System.out.printf("%s%n", sendResult);
    	}
    	// If no more messages are sent, close the Producer instance.
    	producer.shutdown();
    }
}

Consumption News

import java.util.List;
 
import org.apache.rocketmq.client.consumer.DefaultMQPushConsumer;
import org.apache.rocketmq.client.consumer.listener.ConsumeConcurrentlyContext;
import org.apache.rocketmq.client.consumer.listener.ConsumeConcurrentlyStatus;
import org.apache.rocketmq.client.consumer.listener.MessageListenerConcurrently;
import org.apache.rocketmq.client.exception.MQClientException;
import org.apache.rocketmq.common.message.MessageExt;
 
public class Consumer {
 
	public static void main(String[] args) throws InterruptedException, MQClientException {
 
    	// Instantiate the consumer DefaultMQPushConsumer consumer = new DefaultMQPushConsumer("zhuzeqing-1");
 
    	// Set the NameServer address consumer.setNamesrvAddr("192.168.23.131:9876");
 
    	// Subscribe to one or more Topics and Tags to filter the messages that need to be consumed consumer.subscribe("zhuzeqing-1-Topic", "*");
    	// Register the callback implementation class to handle the messages pulled back from the broker consumer.registerMessageListener(new MessageListenerConcurrently() {
            public ConsumeConcurrentlyStatus consumeMessage(List<MessageExt> msgs, ConsumeConcurrentlyContext context) {
                System.out.printf("%s Receive New Messages: %s %n", Thread.currentThread().getName(), msgs);
                // Mark that the message has been consumed successfully return ConsumeConcurrentlyStatus.CONSUME_SUCCESS;
            }
        });
        // Start the consumer instance consumer.start();
        System.out.printf("Consumer Started.%n");
	}
}

VII. Others

Check rmqbroker IP

docker inspect rmqbroker 

The default configuration file path in the Broker container is

/etc/rocketmq/broker.conf

Official website: Apache RocketMQ

refer to:

Installation and use of RocketMQ in Docker_Feng Libin's Blog-CSDN Blog_docker rocketmq

This is the end of this article about the implementation steps of installing RocketMQ in docker. For more information about installing RocketMQ in docker, 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:
  • A very detailed tutorial on installing rocketmq under Docker Desktop
  • Docker installation rocketMQ tutorial (most detailed)
  • Detailed installation and use of RocketMQ in Docker
  • Docker installation of RocketMQ and solutions to problems encountered during installation

<<:  A pitfall and solution of using fileReader

>>:  Some conclusions on developing mobile websites

Recommend

Example code for CSS columns to achieve two-end alignment layout

1. Going around in circles After going around in ...

A simple method to merge and remove duplicate MySQL tables

Scenario: The crawled data generates a data table...

Vue realizes the whole process of slider drag verification function

Rendering Define the skeleton, write HTML and CSS...

Two ways to declare private variables in JavaScript

Preface JavaScript is not like other languages ​​...

Detailed example of SpringBoot+nginx to achieve resource upload function

Recently, I have been learning to use nginx to pl...

Linux common basic commands and usage

This article uses examples to illustrate common b...

How to recover deleted MySQL 8.0.17 root account and password under Windows

I finished learning SQL by myself not long ago, a...

Five delay methods for MySQL time blind injection

Five delay methods for MySQL time blind injection...

Detailed example of using useState in react

useState useState adds some internal state to a c...

HTML Web Page List Tags Learning Tutorial

HTML web page list tag learning tutorial. In HTML ...

How to configure pseudo-static and client-adaptive Nginx

The backend uses the thinkphp3.2.3 framework. If ...