コード例 #1
0
    def __init__(self,
                 controllercls,
                 connection,
                 exchange,
                 topic,
                 pool=None,
                 poolsize=1000):
        self.nodeid = UIDGEN()

        if pool is None:
            self.procpool = GreenPool(size=poolsize)
        else:
            self.procpool = pool

        self.connection = connection
        self.controller = controllercls()
        self.topic = topic
        self.greenlet = None
        self.messagesem = Semaphore()
        self.consume_ready = Event()

        node_topic = "{}.{}".format(self.topic, self.nodeid)
        self.queues = [
            entities.get_topic_queue(exchange, topic),
            entities.get_topic_queue(exchange, node_topic),
            entities.get_fanout_queue(topic),
        ]
        self._channel = None
        self._consumers = None
コード例 #2
0
def test_replying_to_nova_call(connection):
    with connection as conn:
        with conn.channel() as chan:
            queue = entities.get_topic_queue(flags.FLAGS.control_exchange,
                                             topic='test',
                                             channel=chan)
            queue.declare()

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

            eventlet.spawn(listen)

            res = rpc.call(novacontext.get_admin_context(),
                           topic='test',
                           msg={
                               'method': 'testmethod',
                               'args': {
                                   'foo': 'bar',
                               },
                           },
                           timeout=2)
            assert res == ['testmethod', {'foo': 'bar'}]
コード例 #3
0
ファイル: test_sending.py プロジェクト: edwardgeorge/newrpc
 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)
コード例 #4
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)
コード例 #5
0
ファイル: service.py プロジェクト: edwardgeorge/newrpc
    def __init__(self, controllercls,
            connection, exchange, topic,
            pool=None, poolsize=1000):
        self.nodeid = UIDGEN()

        if pool is None:
            self.procpool = GreenPool(size=poolsize)
        else:
            self.procpool = pool

        self.connection = connection
        self.controller = controllercls()
        self.topic = topic
        self.greenlet = None
        self.messagesem = Semaphore()
        self.consume_ready = Event()

        node_topic = "{}.{}".format(self.topic, self.nodeid)
        self.queues = [entities.get_topic_queue(exchange, topic),
                       entities.get_topic_queue(exchange, node_topic),
                       entities.get_fanout_queue(topic), ]
        self._channel = None
        self._consumers = None
コード例 #6
0
ファイル: test_sending.py プロジェクト: edwardgeorge/newrpc
def test_send_topic(connection):
    with connection as conn:
        with conn.channel() as chan:
            queue = entities.get_topic_queue('test_rpc', 'test', channel=chan)
            queue.declare()

            sending.send_topic(conn,
                    exchange='test_rpc',
                    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
コード例 #7
0
def test_send_topic(connection):
    with connection as conn:
        with conn.channel() as chan:
            queue = entities.get_topic_queue('test_rpc', 'test', channel=chan)
            queue.declare()

            sending.send_topic(conn,
                               exchange='test_rpc',
                               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
コード例 #8
0
def test_replying_to_nova_call(connection):
    with connection as conn:
        with conn.channel() as chan:
            queue = entities.get_topic_queue(flags.FLAGS.control_exchange,
                    topic='test',
                    channel=chan)
            queue.declare()

            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))
            eventlet.spawn(listen)

            res = rpc.call(novacontext.get_admin_context(),
                    topic='test',
                    msg={'method': 'testmethod',
                         'args': {'foo': 'bar', }, },
                    timeout=2)
            assert res == ['testmethod', {'foo': 'bar'}]