[zeromq-dev] right patterns

Goswin von Brederlow goswin-v-b at web.de
Mon Feb 10 11:01:42 CET 2014


On Fri, Feb 07, 2014 at 06:09:40PM +0100, Benjamin Cordes wrote:
> Maybe a simple publisher on two channels is enough? i.e. in pyzmq the
> following you did not provide much information
> 
> # simple publisher
> 
> import zmq
> from random import randrange
> import random
> import time
> import json
> 
> context = zmq.Context()
> socket = context.socket(zmq.PUB)
> socket.bind("tcp://*:5555")
> 
> while True:
>     pubmsg = random.randrange(1,100)
>     print 'generated data ',pubmsg
>     j = json.dumps(pubmsg)
>     socket.send_multipart([b"high", j])
>     time.sleep(1) #pretend work
>     socket.send_multipart([b"low", j])

This assumes that within that 1 second all high priority subscribers
get the message. That probably works 999999 out of 1000000 times and
then there is the day you have some network congestion.

> #---------------------------------------------
> #simple subscriber
> import sys
> import zmq
> import random
> 
> context = zmq.Context()
> socket = context.socket(zmq.SUB)
> 
> 
> def sub(port):
>     socket.connect("tcp://localhost:" + port)
> 
>     ffilter = random.choice(["high","low"])
>     ffilter = ffilter.decode('ascii')
>     socket.setsockopt_string(zmq.SUBSCRIBE, ffilter)
>     c = 0
>     maxc = 100
>     while c < maxc:
>         string = socket.recv_string()
>         print string
>         c+=1
> 
> port = "5555"
> sub(port)
> 
> 
> 
> 
> 
> On Fri, Feb 7, 2014 at 5:28 PM, Lindley French <lindleyf at gmail.com> wrote:
> 
> > Can you clarify the need for this priority a bit? My first thought is to
> > create a hierarchy, so that the "top-tier" subscribers re-publish to those
> > who come after them. That isn't quite right though if your condition is
> > that *any* of the top-tier subscribers must receive the event before a
> > given node does, though, only if it's that a *specific* one does.
> >
> > Also be aware pub/sub doesn't mind dropping messages, so be careful using
> > in conjunction with the phrase "have to".
> >
> >
> > On Thu, Feb 6, 2014 at 9:33 AM, Lukas Zaoralek <lukas.zaoralek at gmail.com>wrote:
> >
> >> Hi Devs,
> >>
> >> I would like to publish hundreds even thousands events to subscribers as
> >> quick as possible, but there is a condition several subscribers have to
> >> fetch events firstly than others. In other words there exists priority
> >> which set of subscribers will get events first than others set of
> >> subscribers. Can I use only pub-sub pattern? Or do I have to combine
> >> sub-pub and req-rep patterns together in some advanced way? Thank you for
> >> your advice.
> >>
> >> Lukas

MfG
	Goswin



More information about the zeromq-dev mailing list