Skip to content

SubscriptionStrategy

Interface for event store backend subscription. Defines the contract for subscribing to event streams in various ways.

Source code in event_sourcery/_event_store/subscription/interfaces.py
class SubscriptionStrategy:
    """
    Interface for event store backend subscription.
    Defines the contract for subscribing to event streams in various ways.
    """

    def subscribe_to_all(
        self,
        start_from: Position,
        batch_size: int,
        timelimit: timedelta,
    ) -> Iterator[list[RecordedRaw]]:
        """
        Subscribes to all events in the event store, starting from a given position.

        Args:
            start_from (Position): The position to start reading events from.
            batch_size (int): The maximum number of events to return in each batch.
            timelimit (timedelta): The maximum time to spend reading one batch.

        Returns:
            Iterator[list[RecordedRaw]]: An iterator over batches of recorded events.
        """
        raise NotImplementedError()

    def subscribe_to_category(
        self,
        start_from: Position,
        batch_size: int,
        timelimit: timedelta,
        category: str,
    ) -> Iterator[list[RecordedRaw]]:
        """
        Subscribes to all events in a given category of streams, starting from a
        given position.

        Args:
            start_from (Position): The position to start reading events from.
            batch_size (int): The maximum number of events to return in each batch.
            timelimit (timedelta): The maximum time to spend reading one batch.
            category (str): The category of streams to subscribe to.

        Returns:
            Iterator[list[RecordedRaw]]: An iterator over batches of recorded events.
        """
        raise NotImplementedError()

    def subscribe_to_events(
        self,
        start_from: Position,
        batch_size: int,
        timelimit: timedelta,
        events: list[str],
    ) -> Iterator[list[RecordedRaw]]:
        """
        Subscribes to all events of the given event types, starting from a position.

        Args:
            start_from (Position): The position to start reading events from.
            batch_size (int): The maximum number of events to return in each batch.
            timelimit (timedelta): The maximum time to spend reading one batch.
            events (list[str]): The list of event type names to subscribe to.

        Returns:
            Iterator[list[RecordedRaw]]: An iterator over batches of recorded events.
        """
        raise NotImplementedError()

subscribe_to_all(start_from, batch_size, timelimit)

Subscribes to all events in the event store, starting from a given position.

Parameters:

Name Type Description Default
start_from Position

The position to start reading events from.

required
batch_size int

The maximum number of events to return in each batch.

required
timelimit timedelta

The maximum time to spend reading one batch.

required

Returns:

Type Description
Iterator[list[RecordedRaw]]

Iterator[list[RecordedRaw]]: An iterator over batches of recorded events.

Source code in event_sourcery/_event_store/subscription/interfaces.py
def subscribe_to_all(
    self,
    start_from: Position,
    batch_size: int,
    timelimit: timedelta,
) -> Iterator[list[RecordedRaw]]:
    """
    Subscribes to all events in the event store, starting from a given position.

    Args:
        start_from (Position): The position to start reading events from.
        batch_size (int): The maximum number of events to return in each batch.
        timelimit (timedelta): The maximum time to spend reading one batch.

    Returns:
        Iterator[list[RecordedRaw]]: An iterator over batches of recorded events.
    """
    raise NotImplementedError()

subscribe_to_category(start_from, batch_size, timelimit, category)

Subscribes to all events in a given category of streams, starting from a given position.

Parameters:

Name Type Description Default
start_from Position

The position to start reading events from.

required
batch_size int

The maximum number of events to return in each batch.

required
timelimit timedelta

The maximum time to spend reading one batch.

required
category str

The category of streams to subscribe to.

required

Returns:

Type Description
Iterator[list[RecordedRaw]]

Iterator[list[RecordedRaw]]: An iterator over batches of recorded events.

Source code in event_sourcery/_event_store/subscription/interfaces.py
def subscribe_to_category(
    self,
    start_from: Position,
    batch_size: int,
    timelimit: timedelta,
    category: str,
) -> Iterator[list[RecordedRaw]]:
    """
    Subscribes to all events in a given category of streams, starting from a
    given position.

    Args:
        start_from (Position): The position to start reading events from.
        batch_size (int): The maximum number of events to return in each batch.
        timelimit (timedelta): The maximum time to spend reading one batch.
        category (str): The category of streams to subscribe to.

    Returns:
        Iterator[list[RecordedRaw]]: An iterator over batches of recorded events.
    """
    raise NotImplementedError()

subscribe_to_events(start_from, batch_size, timelimit, events)

Subscribes to all events of the given event types, starting from a position.

Parameters:

Name Type Description Default
start_from Position

The position to start reading events from.

required
batch_size int

The maximum number of events to return in each batch.

required
timelimit timedelta

The maximum time to spend reading one batch.

required
events list[str]

The list of event type names to subscribe to.

required

Returns:

Type Description
Iterator[list[RecordedRaw]]

Iterator[list[RecordedRaw]]: An iterator over batches of recorded events.

Source code in event_sourcery/_event_store/subscription/interfaces.py
def subscribe_to_events(
    self,
    start_from: Position,
    batch_size: int,
    timelimit: timedelta,
    events: list[str],
) -> Iterator[list[RecordedRaw]]:
    """
    Subscribes to all events of the given event types, starting from a position.

    Args:
        start_from (Position): The position to start reading events from.
        batch_size (int): The maximum number of events to return in each batch.
        timelimit (timedelta): The maximum time to spend reading one batch.
        events (list[str]): The list of event type names to subscribe to.

    Returns:
        Iterator[list[RecordedRaw]]: An iterator over batches of recorded events.
    """
    raise NotImplementedError()