jeromq
jeromq copied to clipboard
Can we figure out the endpoint name given a zeromq socket variable?
If I have a ZeroMQ socket variable like this:
final Socket socket = getSocket();
Then can I figure out what endpoint or machine I have in that socket variable? I want to print out the endpoint name basically. I tried looking up the SocketBase class but couldn't figured it out.
This is the way I make Socket:
private Set<Socket> connect(final List<String> addresses, final int socketType) {
Set<Socket> sockets = new HashSet<>();
for (String address : addresses) {
Socket socket = ctx.createSocket(socketType);
String identity = String.format("%04X-%04X", random.nextInt(), random.nextInt());
socket.setIdentity(identity.getBytes(ZMQ.CHARSET));
socket.setTCPKeepAlive(1);
socket.setSendTimeOut(1);
socket.setLinger(2);
socket.connect(address);
sockets.add(socket);
}
return sockets;
}
If you are looking for local endpoints, please have a look on the ZMonitor:
https://github.com/zeromq/jeromq/blob/master/src/test/java/org/zeromq/ZMonitorTest.java
or more low-level:
https://github.com/zeromq/jeromq/blob/master/src/test/java/org/zeromq/TestEvents.java
What I meant was - If I have a Socket variable, then can I figure out what endpoint was used to make that Socket variable? All my endpoints are like this:
tcp://lmachineA:portNumber
I checked those two classes but can't see how to figure out how to extract endpoint given a socket variable unless I have missed something?
There seems to be a misunderstanding. In which way are they different from the addresses your code is supplying for the connect operation?
@fjamal21 Be aware that a socket may be connected to multiple endpoints in general. If there were a function to query this, it would need to return a list of endpoints.