[zeromq-dev] Problems with PUB/SUB sockets and OpenPGM

Steven McCoy steven.mccoy at miru.hk
Wed Jul 7 03:49:45 CEST 2010


On 30 June 2010 20:30, Jens Mehnert <jens.mehnert at smeet.com> wrote:

>  Hello Steve, thanks for the quick answer. What about my other problem.
> Isn't it possible to bind /connect a sender/receiver
> to two different sockets on the same interface like this:
>
> private static final ZMQ.Context CONTEXT = ZMQ.context (1);
> private static final ZMQ.Socket PRODUCER_SOCKET = CONTEXT.socket(ZMQ.PUB);
> private static final ZMQ.Socket CONSUMER_SOCKET = CONTEXT.socket(ZMQ.SUB);
> ...
>
> PRODUCER_SOCKET.bind("tcp://127.0.0.1:5555");
>
> CONSUMER_SOCKET.setsockopt(ZMQ.SUBSCRIBE, "");
> CONSUMER_SOCKET.connect("tcp://127.0.0.1:5555");
> ...
>
> Producer Thread:
>
> while(!Thread.currentThread().interrupted()) {
>     try {
>         String value = TinyUUID.randomTinyUUID().toString();
>         LOG.debug("Send " + value);
>         PRODUCER_SOCKET.send(value.getBytes(), 0);
>         Thread.sleep(1000);
>     } catch (Exception e) {
>         throw new RuntimeException(e);
>     }
> }
>
> Consumer Thread (Runnable scheduled via ExecutorService):
>
>
> while (!Thread.currentThread().isInterrupted()) {
>     try {
>         LOG.debug("Receiving ...");
>
>         byte[] rawMessage = CONSUMER_SOCKET.recv(0);
>         LOG.debug("Received %s", new String(rawMessage));
>
>     } catch (Exception e) {
>         LOG.error("An error occured handling zmq message ...");
>     }
> }
>
> The problem is that the send thread using the producer socket blocks on
> send.  If I don't
> start the consumer send() does not block. Furthermore, If I use the two
> different VMs (
> one producer, one consumer main app) it works splendidly too.
>
> What am I doing wrong?
>
> Best regards, Jens
>
>

Bump,  I answered the PGM part, no idea about the ZMQ part.  Hopefully
someone else answers.

-- 
Steve-o
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.zeromq.org/pipermail/zeromq-dev/attachments/20100707/e9e8f0a3/attachment.htm>


More information about the zeromq-dev mailing list