【solace】基于docker部署solace环境

一、solace

https://www.solace.dev/

solace是一款高性能的消息中间件

 

二、部署脚本

docker run -d \
  -p 8080:8080 \
  -p 55555:55555 \
  -p:8008:8008 \
  -p:1883:1883 \
  -p:8000:8000 \
  -p:5672:5672 \
  -p:9000:9000 \
  -p:2222:2222 \
  --shm-size=2g \
  --env username_admin_globalaccesslevel=admin \
  --env username_admin_password=admin \
  --name=solace \
  solace/solace-pubsub-standard:lts

接口介绍

image

 

三、检查

打开http://127.0.0.1:8080/

image

使用admin /admin登录

 

四、测试

publisher.py

核心代码

topic = Topic.of("solace/try/this/topic") 
messaging_service = MessagingService.builder().from_properties(broker_props).build().connect() 
direct_publisher = messaging_service.create_direct_message_publisher_builder().build().start() 
outbound_msg = messaging_service.message_builder().build("Hello world!") 
direct_publisher.publish(destination=topic, message=outbound_msg)

 

subscribe.py

核心代码

topic = Topic.of("solace/try/>") 
messaging_service = MessagingService.builder().from_properties(broker_props).build().connect() 
direct_receiver = messaging_service.create_direct_message_receiver_builder().with_subscriptions(topic).build().start() 
direct_receiver.receive_async(MessageHandlerImpl())

消息可以正常发送和接收即可

 

也可以使用界面进行测试

image

 

参考链接:

https://www.cnblogs.com/larrydpk/p/17059116.html

https://www.cnblogs.com/rongfengliang/p/14063645.html

 

posted @ 2025-09-30 15:59  代码诠释的世界  阅读(14)  评论(0)    收藏  举报