Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to install RocketMQ in docker

2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/02 Report--

This article will explain in detail how to install RocketMQ in docker. The editor thinks it is very practical, so I share it with you for reference. I hope you can get something after reading this article.

1. Retrieve the image docker search rocketmq

Retrieve the specific version

Curl https://registry.hub.docker.com/v1/repositories/foxiswho/rocketmq/tags | tr-d'[\ [\] "]'| tr'}'\ n' | awk-F:-v image='foxiswho/rocketmq''{if (NRV vehicles NF & & $3! =") {printf ("% SRV% 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 (NRNAV) NF & & $3! =") {printf ("% SV% s\ n", image,$3)}}'

2. Create Broker Serverdocker run-d-p 9876-name rmqserver foxiswho/rocketmq:server-4.5.1

3. Create brokerdocker run-d-p 10911 JAVA_OPTS=-Duser.home=/opt 10911-p 10909 link rmqserver:namesrv 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/bashcd / etc/rocketmq/vi broker.conf

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

Then check the startup with the following command

Docker ps | grep rocketmq

Http://192.168.23.131:8180/

5. Testing

Since I installed rocketmq on the host, 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 org.apache.rocketmq rocketmq-client 4.9.2

Message sending (Producers send 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 message producer Producer DefaultMQProducer producer = new DefaultMQProducer ("zhuzeqing-1") / / set the address of NameServer producer.setNamesrvAddr ("192.168.23.131pur9876"); / / launch Producer instance producer.start (); for (int I = 0; I < 1) Create the message and specify 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); / / return whether the message was successfully delivered to System.out.printf ("% s% n", sendResult) via sendResult;} / / if the message is no longer sent, close the Producer instance. Producer.shutdown ();}}

Consumption message

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 address consumer.setNamesrvAddr of the NameServer ("192.168.23.131 args 9876") / / subscribe to one or more Topic and Tag to filter the message consumer.subscribe to be consumed ("zhuzeqing-1-Topic", "*") / / register the callback implementation class to process the message pulled from broker consumer.registerMessageListener (new MessageListenerConcurrently () {public ConsumeConcurrentlyStatus consumeMessage (List msgs, ConsumeConcurrentlyContext context) {System.out.printf ("% s Receive New Messages:% s% n", Thread.currentThread () .getName (), msgs) / / Mark that the message has been successfully consumed by return ConsumeConcurrentlyStatus.CONSUME_SUCCESS;}}); / / launch the consumer instance consumer.start (); System.out.printf ("Consumer Started.%n");}} VII.

View rmqbroker IP

Docker inspect rmqbroker

The path to the default configuration file in the Broker container is

/ etc/rocketmq/broker.conf

Official website: Apache RocketMQ

This is the end of this article on "how to install RocketMQ in docker". I hope the above content can be of some help to you, so that you can learn more knowledge. if you think the article is good, please share it for more people to see.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report