async def reply_from_live(self, response: InboundMessage, output: Queue):
        if response.command == TcpCommand.PersistentSubscriptionConfirmation:
            self.subscription.out_queue = output
            return

        self.expect_only(TcpCommand.PersistentSubscriptionStreamEventAppeared, response)
        result = proto.StreamEventAppeared()
        result.ParseFromString(response.payload)
        await self.subscription.events.enqueue(_make_event(result.event))
Example #2
0
    async def reply_from_live(self, message, output):
        if message.command == TcpCommand.SubscriptionDropped:
            await self.drop_subscription(message)

            return

        self.expect_only(TcpCommand.StreamEventAppeared, message)
        result = proto.StreamEventAppeared()
        result.ParseFromString(message.payload)

        await self._yield_events([_make_event(result.event)])
Example #3
0
    async def reply_from_live(self, message: InboundMessage) -> None:
        self.expect_only(message, TcpCommand.StreamEventAppeared,
                         TcpCommand.SubscriptionConfirmation)

        if message.command is TcpCommand.SubscriptionConfirmation:
            return

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

        await self.subscription.events.enqueue(_make_event(result.event))
Example #4
0
 async def reply_from_catch_up(self, message, output):
     if message.command == TcpCommand.SubscriptionDropped:
         await self.drop_subscription(message)
     elif message.command == TcpCommand.SubscriptionConfirmation:
         confirmation = proto.SubscriptionConfirmation()
         confirmation.ParseFromString(message.payload)
         self.subscribe_from = confirmation.last_event_number
         self._logger.info(
             "Subscribed successfully, catching up with missed events from %s",
             self.next_event_number,
         )
         await output.put(self._fetch_page_message(self.next_event_number))
     elif message.command == TcpCommand.StreamEventAppeared:
         result = proto.StreamEventAppeared()
         result.ParseFromString(message.payload)
         self.buffer.append(_make_event(result.event))
     else:
         await ReadStreamEventsBehaviour.reply(self, message, output)
Example #5
0
def event_appeared(event_id, commit_position=1, prepare_position=1):
    message_id = uuid4()
    response = proto.StreamEventAppeared()

    response.event.event.event_stream_id = "stream-123"
    response.event.event.event_number = 32
    response.event.event.event_id = event_id.bytes_le
    response.event.event.event_type = "event-type"
    response.event.event.data_content_type = ContentType.Json
    response.event.event.metadata_content_type = ContentType.Binary
    response.event.commit_position = commit_position
    response.event.prepare_position = prepare_position
    response.event.event.data = """
    {
        'color': 'blue',
        'winner': false
    }
    """.encode("UTF-8")

    return InboundMessage(message_id, TcpCommand.StreamEventAppeared,
                          response.SerializeToString())
Example #6
0
def event_appeared(
    commit_position=None,
    prepare_position=None,
    event_number=10,
    event_id=None,
    type="some-event",
    data=None,
    stream="stream-123",
):
    response = proto.StreamEventAppeared()

    response.event.event.event_stream_id = stream
    response.event.event.event_number = event_number
    response.event.event.event_id = (event_id or uuid.uuid4()).bytes_le
    response.event.event.event_type = type
    response.event.event.data_content_type = msg.ContentType.Json
    response.event.event.metadata_content_type = msg.ContentType.Binary
    response.event.commit_position = commit_position or event_number
    response.event.prepare_position = prepare_position or event_number
    response.event.event.data = json.dumps(data).encode("UTF-8") if data else bytes()

    return (msg.TcpCommand.StreamEventAppeared, response.SerializeToString())