Пример #1
0
    topic = b''

print repr(url)
print repr(topic)

try:
    zmq_ctx = zmq.Context()

    sin = zmq_ctx.socket(zmq.SUB)
    sin.setsockopt(zmq.SUBSCRIBE, str(topic))
    sin.hwm = 10000
    ## sin.connect(url)
    sin.bind(url)

    ts = TopicSerializer()
    ts.dumps = marshal.dumps
    ts.loads = marshal.loads
    ts.multipart = True

    ## sin.recv()
    ## print 'run'

    while True:
        data = sin.recv_multipart()
        ## pprint(data)
        msg = ts.deserialize(data)
        
except KeyboardInterrupt:
    pass

print
Пример #2
0
    io_loop = IOLoop.instance()

    sin = zmq_ctx.socket(zmq.SUB)
    sin.setsockopt(zmq.SUBSCRIBE, str(topic))
    sin.setsockopt(zmq.HWM, 0)
    sin.connect(url)

    sout = zmq_ctx.socket(zmq.PUB)
    sout.setsockopt(zmq.HWM, 50000)
    sout.setsockopt(zmq.RATE, 50000000)
    sout.connect(url)

    ## sout.send(b'')

    ts = TopicSerializer()
    ts.dumps = msgpack.dumps
    ts.loads = msgpack.loads
    ts.multipart = False

    chan = Channel(sin, sout, ts)
    proc = Processor()
    proc.add_channel(chan, do_send=False)

    x = PeriodicCallback(sender, 1, io_loop)
    x.start()

    y = PeriodicCallback(proc.print_stat, 1000, io_loop)
    y.start()

    io_loop.start()
except KeyboardInterrupt: