Example #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']
Example #2
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
Example #3
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
Example #4
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"]