- 引入jar包
<!-- https://mvnrepository.com/artifact/org.zeromq/jeromq -->
<dependency>
<groupId>org.zeromq</groupId>
<artifactId>jeromq</artifactId>
<version>0.5.2</version>
</dependency>
- 发布消息
public void ZMQPublisher(){
try(ZContext context = new ZContext()) {
ZMQ.Socket socket = context.createSocket(SocketType.PUB); //ZMQ.PUB 指定通讯模式为 【发布订阅模式】的 发布者
socket.bind ("tcp://*:5553"); //绑定服务地址及端口
while (true) {
String time = "Time:"+new Date().getTime() + "";
socket.send(time);
System.out.println("@@@@ Server Send:" + time);
try {
Thread.sleep(3000);