예제 #1
0
    def response_greenthread():
        with get_connection() as conn:
            with conn.channel() as chan:
                queue = nova.get_topic_queue(
                    'test_rpc', 'test', channel=chan)
                queue.declare()
                queue_declared.send(True)

                msg = ifirst(queue_iterator(queue, no_ack=True, timeout=2))
                msgid, ctx, method, args = nova.parse_message(msg.payload)

                exchange = nova.get_reply_exchange(msgid)
                producer = Producer(chan, exchange=exchange, routing_key=msgid)

                for _ in range(3):
                    msg = dict(
                        result='should ignore this message',
                        failure=None, ending=False)
                    producer.publish(msg)
                    eventlet.sleep(0.1)

                msg = dict(result=args, failure=None, ending=False)
                producer.publish(msg)
                msg = dict(result=None, failure=None, ending=True)
                producer.publish(msg)
예제 #2
0
    def response_greenthread():
        with get_connection() as conn:
            with conn.channel() as chan:
                queue = nova.get_topic_queue('test_rpc', 'test', channel=chan)
                queue.declare()
                queue_declared.send(True)

                body, msg = ifirst(
                    queue_iterator(queue, no_ack=True, timeout=2))
                msgid, _, _, args = nova.parse_message(body)

                exchange = nova.get_reply_exchange(msgid)
                producer = Producer(chan, exchange=exchange, routing_key=msgid)

                for _ in range(3):
                    msg = dict(result='should ignore this message',
                               failure=None,
                               ending=False)
                    producer.publish(msg)
                    eventlet.sleep(0.1)

                msg = dict(result=args, failure=None, ending=False)
                producer.publish(msg)
                msg = dict(result=None, failure=None, ending=True)
                producer.publish(msg)
예제 #3
0
    def response_greenthread():
        with get_connection() as conn:
            with conn.channel() as chan:
                queue = nova.get_topic_queue('test_rpc', 'test', channel=chan)
                queue.declare()
                queue_declared.send(True)
                msg = ifirst(queue_iterator(queue, no_ack=True, timeout=2))
                msgid, _, _, args = nova.parse_message(msg.payload)

                exchange = nova.get_reply_exchange(msgid)
                producer = Producer(chan, exchange=exchange, routing_key=msgid)

                msg = {'result': args, 'failure': None, 'ending': False}
                producer.publish(msg)
                msg = {'result': None, 'failure': None, 'ending': True}
                producer.publish(msg)
예제 #4
0
파일: dependencies.py 프로젝트: ahmb/nameko
    def handle_message(self, body, message):
        container = self.container

        msgid, request_ctx, _, kwargs = parse_message(body)
        args = []

        self.check_signature(args, kwargs)

        handle_result = partial(self.handle_result, message, msgid)

        context_data = request_ctx.copy()
        try:
            container.spawn_worker(
                self, args, kwargs, context_data=context_data,
                handle_result=handle_result)
        except ContainerBeingKilled:
            self.rpc_consumer.requeue_message(message)
예제 #5
0
    def handle_message(self, body, message):
        container = self.container

        msgid, request_ctx, _, kwargs = parse_message(body)
        args = []

        self.check_signature(args, kwargs)

        handle_result = partial(self.handle_result, message, msgid)

        context_data = request_ctx.copy()
        try:
            container.spawn_worker(
                self, args, kwargs, context_data=context_data,
                handle_result=handle_result)
        except ContainerBeingKilled:
            self.rpc_consumer.requeue_message(message)
예제 #6
0
    def response_greenthread():
        with get_connection() as conn:
            with conn.channel() as chan:
                queue = nova.get_topic_queue(
                    'test_rpc', 'test', channel=chan)
                queue.declare()
                queue_declared.send(True)
                msg = ifirst(queue_iterator(queue, no_ack=True, timeout=2))
                msgid, ctx, method, args = nova.parse_message(msg.payload)

                exchange = nova.get_reply_exchange(msgid)
                producer = Producer(chan, exchange=exchange, routing_key=msgid)

                msg = {'result': args, 'failure': None, 'ending': False}
                producer.publish(msg)
                msg = {'result': None, 'failure': None, 'ending': True}
                producer.publish(msg)
예제 #7
0
파일: test_context.py 프로젝트: ahmb/nameko
    def test_transport(self):
        user_id = 1
        ctx = self._makeOne(user_id)

        message_base = {
            'method': 'rpc_call',
            'args': {'arg1': 'val1'},
            '_msg_id': ctx.request_id,
        }
        message = message_base.copy()

        ctx.add_to_message(message)

        msg_id, new_ctx, method, args = parse_message(message)

        assert msg_id == message_base['_msg_id']
        assert id(ctx) != id(new_ctx)
        assert ctx.to_dict() == new_ctx.to_dict()
        assert method == message_base['method']
        assert args == message_base['args']
예제 #8
0
    def response_greenthread():
        with get_connection() as conn:
            with conn.channel() as chan:
                queue = nova.get_topic_queue('test_rpc', 'test', channel=chan)
                queue.declare()
                queue_declared.send(True)
                body, msg = ifirst(
                    queue_iterator(queue, no_ack=True, timeout=2))
                msgid, _, _, _ = nova.parse_message(body)

                exchange = nova.get_reply_exchange(msgid)
                producer = Producer(chan, exchange=exchange, routing_key=msgid)

                exc = Exception('error')
                failure = (type(exc).__name__, str(exc))

                msg = {'result': None, 'failure': failure, 'ending': False}
                producer.publish(msg)
                msg = {'result': None, 'failure': None, 'ending': True}
                producer.publish(msg)
예제 #9
0
    def test_transport(self):
        user_id = 1
        ctx = self._makeOne(user_id)

        message_base = {
            'method': 'rpc_call',
            'args': {
                'arg1': 'val1'
            },
            '_msg_id': ctx.request_id,
        }
        message = message_base.copy()

        ctx.add_to_message(message)

        msg_id, new_ctx, method, args = parse_message(message)

        assert msg_id == message_base['_msg_id']
        assert id(ctx) != id(new_ctx)
        assert ctx.to_dict() == new_ctx.to_dict()
        assert method == message_base['method']
        assert args == message_base['args']