[zeromq-dev] any examples of using downstream/upstream sockets?

Martin Sustrik sustrik at 250bpm.com
Sun Mar 28 10:06:19 CEST 2010


anton at angri.ru wrote:

>> http://github.com/sustrik/cppbutterfly
> 
> Ok, it compiles (after adding #include <stdlib.h>). 

In all the cpp files?

>And how to use it?
> :) What does it do?

See here:

http://www.zeromq.org/tutorials:butterfly

Ignore the code samples as they use old (1.0) API.

> Here is the simple python code which demonstrates that downstream
> sockets feel okay without upstream ones:
> 
> #!/usr/bin/env python
> import time
> import zmq
> 
> MSGS = 1000
> 
> def main():
>     ctx = zmq.Context()
>     s = ctx.socket(zmq.DOWNSTREAM)
>     s.connect('tcp://127.0.0.1:5000')
>     start = time.time()
>     for i in xrange(MSGS):
>         s.send('message%i' % i)
>     elapsed = (time.time() - start) * (10 ** 6)
>     print 'sent %i messages in %.3f us' % (MSGS, elapsed)
> 
> if __name__ == '__main__':
>     main()
> 
> I've tried to add sleep() right before closing a socket, run
> downstreamer, go ahead to this sleep (when all messages go away) and
> run upstreamer after that. No luck: it receives no messages. Is such
> behaviour (similar to pub/sub) expected with downstream/upstream?

Ok. I'll check this.

Martin




More information about the zeromq-dev mailing list