问题描述
我正在遍及ZeroMQ网站上的示例,并且所有Java示例都不适用于jzmq库。我认为它们可以与其他Java实现一起使用,但是我正在处理的项目正在使用jzmq。 JZMQ哪里有示例?
具体来说,如何创建“轮询器”?该示例具有:
context.createPoller(2);
context.getContext().poller();
并说要使用构造函数,但ZMQ.Poller构造函数受到保护。
您应该如何构建一个?
解决方法
我找到了一个代码示例,该示例使用JZMQ 3.1.0库创建了一个轮询器。它与其他Java API略有不同。
//You use the constructor that takes the number of pollers
ZMQ.Poller poller = new ZMQ.Poller(2);
//then you register your socket contexts
int id1 = poller.register(socket1,ZMQ.Poller.POLLIN);
int id2 = poller.register(socket2,ZMQ.Poller.POLLIN);
希望这对其他人有帮助。