一、检索镜像
1
|
docker search rocketmq |
检索具体版本
1
|
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)}}' |
查看当前镜像所有的版本shell命令
1
2
3
|
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)}}' |
二、创建broker server
1
|
docker run -d -p 9876:9876 --name rmqserver foxiswho /rocketmq :server-4.5.1 |
三、创建broker
1
2
3
4
5
|
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 |
配置broker.conf
进入rmqbroker容器
1
2
3
4
5
|
docker exec -it rmqbroker /bin/bash cd /etc/rocketmq/ vi broker.conf |
四、创建rocketmq console
1
2
3
4
|
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 |
然后通过如下命令检查一下启动情况
1
|
docker ps | grep rocketmq |
http://192.168.23.131:8180/
五、测试
由于我在宿主机安装rocketmq,测试如下:
1
2
|
#测试消息发送命令 sh tools.sh org.apache.rocketmq.example.quickstart.producer |
1
2
|
#测试消息接收命令 sh tools.sh org.apache.rocketmq.example.quickstart.consumer |
六、java样例
1
2
3
4
5
|
< dependency > < groupid >org.apache.rocketmq</ groupid > < artifactid >rocketmq-client</ artifactid > < version >4.9.2</ version > </ dependency > |
消息发送(producer端发送同步消息)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
|
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 { // 实例化消息生产者producer defaultmqproducer producer = new defaultmqproducer( "zhuzeqing-1" ); // 设置nameserver的地址 producer.setnamesrvaddr( "192.168.23.131:9876" ); // 启动producer实例 producer.start(); for ( int i = 0 ; i < 1 ; i++) { // 创建消息,并指定topic,tag和消息体 message msg = new message( "zhuzeqing-1-topic" /* topic */, "taga" /* tag */, ("hello,rocketmq --" + i).getbytes(remotinghelper.default_charset) /* message body */ ); // 发送消息到一个broker sendresult sendresult = producer.send(msg); // 通过sendresult返回消息是否成功送达 system.out.printf( "%s%n" , sendresult); } // 如果不再发送消息,关闭producer实例。 producer.shutdown(); } } |
消费消息
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
|
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 { // 实例化消费者 defaultmqpushconsumer consumer = new defaultmqpushconsumer( "zhuzeqing-1" ); // 设置nameserver的地址 consumer.setnamesrvaddr( "192.168.23.131:9876" ); // 订阅一个或者多个topic,以及tag来过滤需要消费的消息 consumer.subscribe( "zhuzeqing-1-topic" , "*" ); // 注册回调实现类来处理从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); // 标记该消息已经被成功消费 return consumeconcurrentlystatus.consume_success; } }); // 启动消费者实例 consumer.start(); system.out.printf( "consumer started.%n" ); } } |
七、其他
查看rmqbroker ip
1
|
docker inspect rmqbroker |
broker容器中默认的配置文件的路径为
1
|
/etc/rocketmq/broker.conf |
参考:
docker中rocketmq的安装与使用_冯立彬的博客-csdn博客_docker rocketmq
到此这篇关于docker安装rocketmq的实现步骤的文章就介绍到这了,更多相关docker安装rocketmq内容请搜索服务器之家以前的文章或继续浏览下面的相关文章希望大家以后多多支持服务器之家!
原文链接:https://blog.csdn.net/u012965203/article/details/121236406