[zeromq-dev] More questions about using 0MQ + Java

Attila-Mihaly Balazs x_at_y_or_z at yahoo.com
Mon May 30 12:47:48 CEST 2011

First of all I would like to thank for the quick support I've received 
until now, although all the problems were between chair and keyboard 
until now (and it is probably the case with the following):

The attached source code does the following:
     - from the main thread it creates the context (from the 
documentation [1] I understand that this can be passed around the threads)
     - I create two threads: one for receiving and one for sending
     - the sender thread uses a queue to buffer the messages for 
sending, so that they can be sent from the same thread
     - each thread creates its own socket (because sockets can't be 
passed between threads AFAIK) - the sender creates a PUB socket, while 
the receiver a SUB socket
     - the main thread waits for both the .bind and the .connect call to 
succeed in their respective threads
     - when a thread detects an exception, it closes its socket (to 
clean up)

The following scenarios all work:
     - calling context.term() from the main thread (where it was created)
     - calling context.term() from a new thread (not the main, nor the 
sender/receiver threads)

However the following doesn't work:
     - calling context.term() from the sender thread (so I would do 
subscribeSocket.close(); context.term();). It gives the following error 
message and terminates the process:
         Assertion failed: nbytes == sizeof (command_t) (mailbox.cpp:245)

My questions would be:
     - What am I doing wrong? I'm trying to achieve a clean stop (ie. if 
either the sender or the receiver die, the other should be stopped too)
     - Is there a more performant way to send messages //from an 
arbitrary thread// than creating one socket / thread or queuing them to 
a single thread?

Best regards,
Attila Balazs

[1] http://api.zeromq.org/2-1:zmq-init
-------------- next part --------------
A non-text attachment was scrubbed...
Name: TestJZMQ.java
Type: text/x-java
Size: 4947 bytes
Desc: not available
URL: <https://lists.zeromq.org/pipermail/zeromq-dev/attachments/20110530/672ce0a5/attachment.java>

More information about the zeromq-dev mailing list