Ejemplo n.º 1
0
def send_rpc(connection,
             context,
             exchange,
             topic,
             method,
             args,
             timeout=None,
             noreply=False,
             fanout=False):
    msgid, payload = create_rpcpayload(
        context, method, args, msg_id=(False if noreply or fanout else None))
    if fanout:
        send_fanout(connection, topic, payload)
        return
    if noreply:
        send_topic(connection, exchange, topic, payload)
        return
    with connection.channel() as channel:
        queue = entities.get_reply_queue(msgid, channel=channel)
        queue.declare()
        send_topic(connection, exchange, topic, payload)
        iter_ = consuming.queue_iterator(queue, timeout=timeout)
        iter_ = responses.iter_rpcresponses(iter_)
        ret = responses.last(iter_, ack_all=True)
        if ret is not None:
            return ret.payload['result']
Ejemplo n.º 2
0
 def response_greenthread():
     with get_connection() as conn:
         with conn.channel() as chan:
             queue = entities.get_topic_queue('test_rpc', 'test', channel=chan)
             queue.declare()
             msg = ifirst(consuming.queue_iterator(queue, no_ack=True, timeout=2))
             msgid, ctx, method, args = context.parse_message(msg.payload)
             sending.reply(conn, msgid, args)
Ejemplo n.º 3
0
 def response_greenthread():
     with get_connection() as conn:
         with conn.channel() as chan:
             queue = entities.get_topic_queue('test_rpc',
                                              'test',
                                              channel=chan)
             queue.declare()
             msg = ifirst(
                 consuming.queue_iterator(queue, no_ack=True, timeout=2))
             msgid, ctx, method, args = context.parse_message(msg.payload)
             sending.reply(conn, msgid, args)
Ejemplo n.º 4
0
def test_send_fanout(connection):
    with connection as conn:
        with conn.channel() as chan:
            queue = entities.get_fanout_queue('test', channel=chan)
            queue.declare()

            sending.send_fanout(conn, topic='test', data='success')
            msg = ifirst(
                consuming.queue_iterator(queue, no_ack=True, timeout=0.2))
            assert msg.payload == 'success'

    # check consumefrom has removed entry
    assert not consuming._conndrainers
Ejemplo n.º 5
0
def test_send_direct(connection):
    with connection as conn:
        msgid = uuid.uuid4().hex
        with conn.channel() as chan:
            queue = entities.get_reply_queue(msgid=msgid, channel=chan)
            queue.declare()

            sending.send_direct(conn, directid=msgid, data='success')
            msg = ifirst(
                consuming.queue_iterator(queue, no_ack=True, timeout=0.2))
            assert msg.payload == 'success'

    # check consumefrom has removed entry
    assert not consuming._conndrainers
Ejemplo n.º 6
0
def test_send_fanout(connection):
    with connection as conn:
        with conn.channel() as chan:
            queue = entities.get_fanout_queue('test', channel=chan)
            queue.declare()

            sending.send_fanout(conn,
                    topic='test',
                    data='success')
            msg = ifirst(consuming.queue_iterator(queue, no_ack=True, timeout=0.2))
            assert msg.payload == 'success'

    # check consumefrom has removed entry
    assert not consuming._conndrainers
Ejemplo n.º 7
0
def test_replying(connection):
    with connection as conn:
        msgid = uuid.uuid4().hex
        with conn.channel() as chan:
            queue = entities.get_reply_queue(msgid=msgid,
                    channel=chan)
            queue.declare()

            sending.reply(conn, msgid, 'success')
            msg = ifirst(consuming.queue_iterator(queue, no_ack=True, timeout=0.2))
            assert msg.payload['result'] == 'success'

    # check consumefrom has removed entry
    assert not consuming._conndrainers
Ejemplo n.º 8
0
def send_rpc(connection, context, exchange, topic, method, args, timeout=None, noreply=False, fanout=False):
    msgid, payload = create_rpcpayload(context, method, args, msg_id=(False if noreply or fanout else None))
    if fanout:
        send_fanout(connection, topic, payload)
        return
    if noreply:
        send_topic(connection, exchange, topic, payload)
        return
    with connection.channel() as channel:
        queue = entities.get_reply_queue(msgid, channel=channel)
        queue.declare()
        send_topic(connection, exchange, topic, payload)
        iter_ = consuming.queue_iterator(queue, timeout=timeout)
        iter_ = responses.iter_rpcresponses(iter_)
        ret = responses.last(iter_, ack_all=True)
        if ret is not None:
            return ret.payload["result"]
Ejemplo n.º 9
0
 def listen():
     msg = responses.ifirst(consuming.queue_iterator(
             queue, no_ack=True, timeout=2))
     msg.ack()
     msgid, ctx, method, args = context.parse_message(msg.payload)
     sending.reply(conn, msgid, (method, args))
Ejemplo n.º 10
0
 def listen():
     msg = responses.ifirst(
         consuming.queue_iterator(queue, no_ack=True, timeout=2))
     msg.ack()
     msgid, ctx, method, args = context.parse_message(msg.payload)
     sending.reply(conn, msgid, (method, args))