[zeromq-dev] Using zmq_proxy with ZMQ_STREAM socket

Pieter Hintjens ph at imatix.com
Tue Apr 7 08:20:15 CEST 2015


You cannot use a ZeroMQ socket from multiple threads. So you must
write to the STREAM socket from one thread only. If you create many
SUB sockets you can simply poll on them all, and forward any data to
the STREAM socket, from a single thread. You will need to send a
routing ID before each message, same as for ROUTER sockets.

On Mon, Apr 6, 2015 at 3:30 PM, Kil Tuy <kiltuy1 at gmail.com> wrote:
> I can get client connection events through STREAM socket (first identity and
> empty frame). Assume that I create a thread and a SUB socket for each client
> where thread will read through SUB and send through STREAM. Does sending
> concurrently through STREAM socket for each client in different threads
> cause any issues?
>
> 2015-04-06 13:29 GMT+03:00 Pieter Hintjens <ph at imatix.com>:
>>
>> You can use a stream socket to talk to the clients, yes, though you
>> must manage the clients yourself, mapping incoming SUB traffic to
>> whatever TCP protocol the clients speak, and sending each message to
>> all clients.
>>
>> On Mon, Apr 6, 2015 at 12:20 PM, Kil Tuy <kiltuy1 at gmail.com> wrote:
>> > I am trying to replace existing adhoc pub/sub mechanism with zeromq.
>> > Unfortunately clients are not in my control so I cannot plugin SUB
>> > sockets.
>> > I thought I could bridge the gap using STREAM socket.
>> >
>> > 2015-04-06 12:56 GMT+03:00 Pieter Hintjens <ph at imatix.com>:
>> >>
>> >> This won't work, no. The STREAM socket will accept many client
>> >> connections. You have to manage these in some way. There's not even a
>> >> sane meaning to bridging a SUB socket to a STREAM socket afaict, it's
>> >> like connecting a radio loudspeaker to a garden hose. What are you
>> >> actually trying to do?
>> >>
>> >> -Pieter
>> >>
>> >> On Mon, Apr 6, 2015 at 10:29 AM, Kil Tuy <kiltuy1 at gmail.com> wrote:
>> >> > Hi,
>> >> > Is it possible to use ZMQ_STREAM with proxy? The idea is to have
>> >> > proxy a
>> >> > SUB
>> >> > socket with a STREAM one. Following is what's working for me
>> >> > currently
>> >> > but I
>> >> > am looking forward to replace it with proxy. Sorry that the code is
>> >> > written
>> >> > using CLR binding.
>> >> >
>> >> >                 // Create subscriber
>> >> >                 ZSocket sub = new ZSocket(ctx, ZSocketType.SUB);
>> >> >                 sub.Connect("tcp://127.0.0.1:5564");
>> >> >                 sub.SubscribeAll();
>> >> >
>> >> >                 // Create streamer
>> >> >                 ZSocket stream = new ZSocket(ctx,
>> >> > ZSocketType.STREAM);
>> >> >                 stream.Bind("tcp://127.0.0.1:5565");
>> >> >
>> >> >                 // Read client connect message
>> >> >                 ZMessage msg = stream.ReceiveMessage();
>> >> >
>> >> >                 while (true)
>> >> >                 {
>> >> >                     // Forward message with a replaced id frame
>> >> >                     ZMessage zm = sub.ReceiveMessage();
>> >> >                     zm.ReplaceAt(0, msg[0]);
>> >> >                     stream.Send(zm);
>> >> >                 }
>> >> >
>> >> >                 /*ZContext.Proxy(stream, sub);*/
>> >> >
>> >> >    I tried using proxy method but it didn't work. Possible to replace
>> >> > the
>> >> > above code with proxy?
>> >> >
>> >> >
>> >> > _______________________________________________
>> >> > zeromq-dev mailing list
>> >> > zeromq-dev at lists.zeromq.org
>> >> > http://lists.zeromq.org/mailman/listinfo/zeromq-dev
>> >> >
>> >> _______________________________________________
>> >> zeromq-dev mailing list
>> >> zeromq-dev at lists.zeromq.org
>> >> http://lists.zeromq.org/mailman/listinfo/zeromq-dev
>> >
>> >
>> >
>> > _______________________________________________
>> > zeromq-dev mailing list
>> > zeromq-dev at lists.zeromq.org
>> > http://lists.zeromq.org/mailman/listinfo/zeromq-dev
>> >
>> _______________________________________________
>> zeromq-dev mailing list
>> zeromq-dev at lists.zeromq.org
>> http://lists.zeromq.org/mailman/listinfo/zeromq-dev
>
>
>
> _______________________________________________
> zeromq-dev mailing list
> zeromq-dev at lists.zeromq.org
> http://lists.zeromq.org/mailman/listinfo/zeromq-dev
>



More information about the zeromq-dev mailing list