How to create a Poller in jzmq Java bindings for ZeroMQ?

255 Views Asked by At

I am going through the examples on the ZeroMQ website and all the Java examples don't work for the jzmq library. I think they work with the other Java implementation but the project I am working on is using jzmq. Are there examples anywhere for JZMQ?

Specifically, how do you create a Poller? The example has:

context.createPoller(2);

There is a method on the context that is depreciated:

context.getContext().poller();

And says to use the constructor but the ZMQ.Poller constructor is protected.

How are you supposed to construct one?

1

There are 1 best solutions below

0
devo On

I found a code sample that creates a poller using JZMQ 3.1.0 library. It is just a little different than the other 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);

Hope this helps someone else.