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()
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()
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)
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)
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)
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)
async def on_message(self, message: IncomingMessage): async with message.process(): future = self.futures.pop(message.correlation_id) future.set_result(message.body.decode())