问题
I checked source code of ZMQueue
class from JeroMQ which implements Runnable interface looks like:
private final Socket inSocket;
private final Socket outSocket;
public ZMQQueue( Context context, Socket inSocket, Socket outSocket ){
this.inSocket = inSocket;
this.outSocket = outSocket;
}
@Override
public void run(){
zmq.ZMQ.proxy( inSocket.base(), outSocket.base(), null );
}
As you can see inside the run()
only one statement is there, i.e. calling a
ZMQ.proxy()
- what happens here?
And in constructor,
it's taking a Context
instance as a parameter and doing nothing with it.
can any one explains, for what purpose this class has implemented?
回答1:
It's simple proxy that works in separate thread, it takes a msg from one socket and puts it to another, ZMQueue class is just a some kind of high-level api in jeromq/jzmq library.
Also you can use proxy without ZMQueue class (doc). Or you can implement something more complicated by yourself with any processing you need.
来源:https://stackoverflow.com/questions/41032230/what-is-the-use-of-zmqueue-class-in-jeromq