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
1. Going around in circles After going around in ...
1. Introduction to Data Integrity 1. Introduction...
Scenario: The crawled data generates a data table...
Many people have encountered this error when star...
Rendering Define the skeleton, write HTML and CSS...
Examples: Through the PHP background code, you ca...
Preface JavaScript is not like other languages ...
Recently, I have been learning to use nginx to pl...
This article uses examples to illustrate common b...
I finished learning SQL by myself not long ago, a...
Five delay methods for MySQL time blind injection...
useState useState adds some internal state to a c...
HTML web page list tag learning tutorial. In HTML ...
1. Create tables <br /> First, create two t...
The backend uses the thinkphp3.2.3 framework. If ...