Hi Jon,

> I'm new to zeromq so please forgive me if this is obvious, but I couldn't 
> find the answer anywhere.
>
> I am using the Java bindings and have a pub/sub socket arrangement. My 
> subscriber listens with recv() in its own thread, blocking when there is no 
> data. My question is how do I cleanly terminate the blocked subscriber when 
> the subscription is no longer needed?
>
> I understand from the docs that a context is thread-safe, but sockets have 
> thread-affinity. So I assume that I shouldn't call close() on the socket from 
> another thread to break the blocked call. The only solution I've found so far 
> is to call term() on the context. This works, but means I have to have a 
> separate context for each subscriber which I don't think is what's intended.
>
> What is the proper pattern for this?

Two use cases:

1. If you are shutting down the process, you should call zmq_term which 
will in turn cause all blocking calls to return with ETERM error.

2. If you want to unblock only a single thread, use inproc transport to 
send it an "unblock" message. The destination thread can use zmq_poll to 
wait for either a new business message or an "unblock" message.

Martin
_______________________________________________
zeromq-dev mailing list
[email protected]
http://lists.zeromq.org/mailman/listinfo/zeromq-dev

Reply via email to