async def drop_subscription(self, response: InboundMessage) -> None:
        body = proto.SubscriptionDropped()
        body.ParseFromString(response.payload)

        if self.is_live and body.reason == messages.SubscriptionDropReason.Unsubscribed:

            await self.subscription.events.enqueue(StopAsyncIteration())
            return

        if self.is_live:
            await self.error(
                exceptions.SubscriptionFailed(self.conversation_id, body.reason)
            )
            return

        await self.error(
            exceptions.SubscriptionCreationFailed(self.conversation_id, body.reason)
        )
Exemple #2
0
    async def reply(self, message: InboundMessage, output: Queue) -> None:
        self.expect_only(TcpCommand.CreatePersistentSubscriptionCompleted,
                         message)

        result = proto.CreatePersistentSubscriptionCompleted()
        result.ParseFromString(message.payload)

        if result.result == SubscriptionResult.Success:
            self.is_complete = True
            self.result.set_result(None)

        elif result.result == SubscriptionResult.AccessDenied:
            await self.error(
                exceptions.AccessDenied(self.conversation_id,
                                        type(self).__name__, result.reason))
        else:
            await self.error(
                exceptions.SubscriptionCreationFailed(self.conversation_id,
                                                      result.reason))