1. Retrieve the imagedocker 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 Serverdocker run -d -p 9876:9876 --name rmqserver foxiswho/rocketmq:server-4.5.1 3. Create a brokerdocker 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 consoledocker 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. TestingSince 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. OthersCheck 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 pitfall and solution of using fileReader
>>: Some conclusions on developing mobile websites
Canal is an open source project under Alibaba, de...
Idea: Just sort randomly first and then group. 1....
Link: https://qydev.weixin.qq.com/wiki/index.php?...
CSS writing order 1. Position attributes (positio...
Everything needs a foundation. To build a house, ...
First: 4 ways to introduce CSS There are four way...
There is a requirement for a list containing mult...
When the server needs to be started during develo...
Install boost There are many ways to call C/C++ f...
Hardware View Commands system # uname -a # View k...
Preface Application scenario: probably the intern...
Table of contents Preface 1. EndPoint 2. Connecti...
1. at is configured to write "This is a at t...
This article shares a collection of Java problems...
1. The significance of building nexus service As ...