forked from zeromq/jeromq
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpsenvsub.java
More file actions
32 lines (27 loc) · 881 Bytes
/
psenvsub.java
File metadata and controls
32 lines (27 loc) · 881 Bytes
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
package guide;
import org.zeromq.SocketType;
import org.zeromq.ZMQ;
import org.zeromq.ZMQ.Socket;
import org.zeromq.ZContext;
/**
* Pubsub envelope subscriber
*/
public class psenvsub
{
public static void main(String[] args)
{
// Prepare our context and subscriber
try (ZContext context = new ZContext()) {
Socket subscriber = context.createSocket(SocketType.SUB);
subscriber.connect("tcp://localhost:5563");
subscriber.subscribe("B".getBytes(ZMQ.CHARSET));
while (!Thread.currentThread().isInterrupted()) {
// Read envelope with address
String address = subscriber.recvStr();
// Read message contents
String contents = subscriber.recvStr();
System.out.println(address + " : " + contents);
}
}
}
}