Example #1
0
def test_zmsg():
    m = zmsg.new()
    foo = zframe.new('foo')
    zmsg.push(m, foo)
    assert zmsg.first(m) == foo
    bar = zframe.new('bar')
    zmsg.push(m, bar)
    assert zmsg.first(m) == bar
    assert zmsg.last(m) == foo
    zmsg.append(m, zframe.new('ding'))
    assert zframe.data(zmsg.last(m)) == 'ding'

    ctx = zctx.new()
    p = zsocket.new(ctx, zmq.PUB)
    u = zsocket.new(ctx, zmq.SUB)
    zsockopt.set_subscribe(u, '')
    zsocket.bind(p, 'inproc://qer')
    zsocket.connect(u, 'inproc://qer')
    zmsg.send(m, p)
    zsocket.poll(u, 1)
    n = zmsg.recv(u)
    assert zmsg.size(n) == 3
    assert zframe.data(zmsg.next(n)) == 'bar'
    assert zframe.data(zmsg.next(n)) == 'foo'
    assert zframe.data(zmsg.next(n)) == 'ding'
    assert zmsg.next(n) is None
Example #2
0
def echo_actor(pipe, args):
    assert args == "Hello, World"
    zsock.signal(pipe, 0)
    while True:
        msg = zmsg.recv(pipe)
        if not msg:
            break
        command = zmsg.popstr(msg)
        if command == "$TERM":
            return
        elif command == "ECHO":
            zmsg.send(msg, pipe)
        else:
            raise TypeError("E: invalid message to actor")
Example #3
0
def test_zmsg():
    m = zmsg.new()
    foo = zframe.new('foo')
    zmsg.push(m, foo)
    assert zmsg.first(m) == foo
    bar = zframe.new('bar')
    zmsg.push(m, bar)
    assert zmsg.first(m) == bar
    assert zmsg.last(m) == foo
    zmsg.append(m, zframe.new('ding'))

    # dup and mutate the buffer view
    d = zframe.dup(zmsg.last(m))
    assert zframe.data(d)[:] == 'ding'
    zframe.data(d)[1] = 'o'
    assert zframe.data(d)[:] == 'dong'
    assert zframe.size(d) == 4
    zmsg.append(m, d)

    ctx = zctx.new()
    p = zsocket.new(ctx, zmq.PUB)
    u = zsocket.new(ctx, zmq.SUB)
    zsocket.set_subscribe(u, '')
    zsocket.bind(p, 'inproc://qer')
    zsocket.connect(u, 'inproc://qer')
    zmsg.send(m, p)
    zsocket.poll(u, 1)
    n = zmsg.recv(u)
    assert zmsg.size(n) == 4
    assert zframe.data(zmsg.next(n))[:] == 'bar'
    assert zframe.data(zmsg.next(n))[:] == 'foo'
    assert zframe.data(zmsg.next(n))[:] == 'ding'
    assert zframe.data(zmsg.next(n))[:] == 'dong'
    assert zmsg.next(n) is None

    zmsg.destroy(n)
Example #4
0
 def recv_msg(self):
     return Message(zmsg.recv(self.sock))
Example #5
0
 def recv_msg(self):
     return Message(zmsg.recv(self.sock))