Пример #1
0
    def on_callback(self, message: IncomingMessage):
        func_name = message.headers['FuncName']
        if func_name not in self.routes:
            return

        payload = self.deserialize(message.body)
        func = self.routes[func_name]

        try:
            result = yield from self._execute(func, payload)
            result = self.serialize(result)
            message_type = 'result'
        except Exception as e:
            result = self.serialize(e)
            message_type = 'error'

        result_message = Message(
            result,
            delivery_mode=message.delivery_mode,
            correlation_id=message.correlation_id,
            timestamp=time.time(),
            type=message_type,
        )

        yield from self.channel.default_exchange.publish(result_message,
                                                         message.reply_to,
                                                         mandatory=False)

        message.ack()
Пример #2
0
    def on_call_message(self, method_name: str, message: IncomingMessage):
        if method_name not in self.routes:
            log.warning("Method %r not registered in %r", method_name, self)
            return

        payload = self.deserialize(message.body)
        func = self.routes[method_name]

        try:
            result = yield from self.execute(func, payload)
            result = self.serialize(result)
            message_type = 'result'
        except Exception as e:
            result = self.serialize_exception(e)
            message_type = 'error'

        result_message = Message(
            result,
            delivery_mode=message.delivery_mode,
            correlation_id=message.correlation_id,
            timestamp=time.time(),
            type=message_type,
        )

        yield from self.channel.default_exchange.publish(result_message,
                                                         message.reply_to,
                                                         mandatory=False)

        message.ack()
Пример #3
0
    async def on_message(self, func, message: IncomingMessage):
        with message.process(requeue=True, ignore_processed=True):
            data = self.deserialize(message.body)

            try:
                await self.execute(func, data)
            except RejectMessage as e:
                message.reject(requeue=e.requeue)
            except NackMessage as e:
                message.nack(requeue=e.requeue)
Пример #4
0
 def on_callback(self, message: IncomingMessage):
     func_name = message.headers['FuncName']
     func = self.routes.get(func_name)
     if func:
         with message.process(requeue=True, ignore_processed=True):
             data = self.deserialize(message.body)
             yield from self._execute(func, data)
Пример #5
0
 async def on_message(self, func, message: IncomingMessage):
     with message.process(requeue=True, ignore_processed=True):
         data = self.deserialize(message.body)
         # logging.info(f"on_message: got data: {data}")
         try:
             await self.execute(func, data)
         except ChannelClosed as e:
             logging.error(e)
             await self.connect()
             await self.execute(func, data)
Пример #6
0
 def on_message(self, func, message: IncomingMessage):
     with message.process(requeue=True, ignore_processed=True):
         data = self.deserialize(message.body)
         yield from self.execute(func, data)
Пример #7
0
 async def on_message(self, message: IncomingMessage):
     async with message.process():
         future = self.futures.pop(message.correlation_id)
         future.set_result(message.body.decode())