[zeromq-dev] right patterns

Benjamin Cordes benjamin.l.cordes at gmail.com
Fri Feb 7 18:09:40 CET 2014

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)

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])

#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

port = "5555"

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
>> _______________________________________________
>> 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
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.zeromq.org/pipermail/zeromq-dev/attachments/20140207/700f92ba/attachment.htm>

More information about the zeromq-dev mailing list