本文介绍了JeroMQ中ZMQueue类的用途是什么的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我从JeroMQ检查了实现了Runnable接口的 ZMQueue 类的源代码,如下所示:

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 );
 }

如您在 run() 内部看到的那样,仅存在一条语句,即调用a

As you can see inside the run() only one statement is there, i.e. calling a

ZMQ.proxy() -这里会发生什么?

ZMQ.proxy() - what happens here?

在构造函数中,
它以Context实例作为参数,对此不执行任何操作.

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?

推荐答案

它是在单独的线程中工作的简单代理,它从一个套接字获取一个msg并将其放入另一个套接字,ZMQueue类只是某种高级jeromq/jzmq库中的api.

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.

您也可以使用不带ZMQueue类的代理( doc ).或者,您可以通过所需的任何处理自己实现一些更复杂的事情.

Also you can use proxy without ZMQueue class (doc).Or you can implement something more complicated by yourself with any processing you need.

这篇关于JeroMQ中ZMQueue类的用途是什么的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-07 20:25