[zeromq-dev] Handling Generic Events in the Message Loop

Lucas Hope lucas.r.hope at gmail.com
Wed Aug 8 05:12:30 CEST 2012

Hi there,

I had a simple solution to this in java. To link a third-party callback to
zeromq, I used a thread-safe BlockingQueue as an intermediate step (my
particular application used PriorityBlockingQueue).

1. Callbacks would push events to the blocking queue.

2. A separate thread would wait on the blocking queue and forward the event
to a zeromq socket (this works for push, pub, dealer, etc).

3. The main poll was connected to the above socket and therefore could
process the events as they came in.

There may be problems with the above implementation/concept but it worked
for me - albeit in a low bandwidth environment. I believe the use of the
single separate thread made the socket usage kosher according to zeromq
requirements. If the above is actually a good solution, it'd be pretty cool
to make a generic event-funnelling device in this way.



On Wed, Aug 8, 2012 at 8:18 AM, Aja Walker <Aja at ciscor.com> wrote:

> Hi all.****
> ** **
> I’m developing an application using 0MQ and the Java bindings and wanted
> to ask the community a question:  Has anyone found an elegant way to extend
> a 0MQ message loop into a more general purpose event loop?****
> ** **
> I’ll be more specific.  I have a thread that receives messages on a set of
> sockets via poll() and sends messages in response to those received
> messages.  Pretty standard so far.  Occasionally, however, another thread
> will generate some event in response to which the first thread needs to
> send a message on one of its sockets.  This other thread is not always
> under my control and is not even always the same thread (i.e. third party
> library) and so I have no way to give a socket to this other thread so that
> it can send my first thread a message notifying it of the event.  How do I
> get information about this event into my first thread so it can send its
> message?****
> ** **
> The only  solution I can think of (which is ugly) is to break out of the
> poll() call periodically and check an event queue shared by both threads.*
> ***
> ** **
> Other possibilities would be some sort of way to break the first thread
> out of poll() via another thread so that it can check the event queue
> immediately, or to somehow incorporate the 0MQ sockets into the Java NIO
> selector framework (which is interruptible), again so my first thread can
> check the event queue immediately.  It is not obvious to me how either of
> these would be done, if they can be done at all.****
> ** **
> Has anyone run into this situation using the Java bindings, and if so did
> you find a good solution?****
> ** **
> Thanks,****
> Aja Walker****
> _______________________________________________
> zeromq-dev mailing list
> zeromq-dev at lists.zeromq.org
> http://lists.zeromq.org/mailman/listinfo/zeromq-dev

Dr Lucas Hope - lucas.r.hope at skype
Machine Learning and Software Engineering Consultant
Melbourne, Australia
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.zeromq.org/pipermail/zeromq-dev/attachments/20120808/1a959efd/attachment.htm>

More information about the zeromq-dev mailing list