async def _process_msg(self, sub): """ Receives the msgs from the STAN subscriptions and replies. By default it will reply back with an ack unless manual acking was specified in one of the subscription options. """ while True: try: raw_msg = await sub._msgs_queue.get() msg = Msg() msg_proto = protocol.MsgProto() msg_proto.ParseFromString(raw_msg.data) msg.proto = msg_proto msg.sub = sub # Yield the message to the subscription callback. await sub.cb(msg) if not sub.manual_acks: # Process auto-ack if not done manually in the callback, # by publishing into the ack inbox from the subscription. msg_ack = protocol.Ack() msg_ack.subject = msg.proto.subject msg_ack.sequence = msg.proto.sequence await self._nc.publish(sub.ack_inbox, msg_ack.SerializeToString()) except asyncio.CancelledError: break except: # FIXME: async callback to signal error continue
async def ack(self, msg): """ Used to manually acks a message. :param msg: Message which is pending to be acked by client. """ ack_proto = protocol.Ack() ack_proto.subject = msg.proto.subject ack_proto.sequence = msg.proto.sequence await self._nc.publish(msg.sub.ack_inbox, ack_proto.SerializeToString())
def _ack(self, seq: int): if not (isinstance(seq, list) or isinstance(seq, tuple)): seq = [seq] for seq in seq: ack = protocol.Ack() ack.subject = self.subject ack.sequence = seq asyncio.ensure_future( self.sc._nc.publish(self.sub.ack_inbox, ack.SerializeToString()), loop=self.loop, )