outbox

class mersal_alchemy.sqlalchemy_outbox_storage.SQLAlchemyOutboxStorage

Bases: OutboxStorage

__init__(config: SQLAlchemyOutboxStorageConfig) None
async get_next_message_batch() OutboxMessageBatch

Provide messages stored in the outbox.

async save(outgoing_messages: Sequence[OutgoingMessage], transaction_context: TransactionContext) None

Save outbox messages.

The TransactionContext can be used to obtain objects related to the current message being handled. For example, to obtain the database transaction/session.

Parameters:
  • outgoing_messages – A list of messages to be stored in the outbox.

  • transaction_context – The TransactionContext for the message that is currently being handled.

class mersal_alchemy.sqlalchemy_outbox_storage.SQLAlchemyOutboxStorageConfig

Bases: object

Configuration for SQLAlchemyOutboxStorage.

__init__(async_session_factory: async_sessionmaker[AsyncSession], table_name: str, session_extractor: Callable[[TransactionContext], AsyncSession], commit_on_save: bool = True, close_session_on_save: bool = True) None
async_session_factory: async_sessionmaker[AsyncSession]

Session factory used to create a session responsible for the outbox table and fetch outbox messages.

This is not used for creating the session responsible for saving the messages.

close_session_on_save: bool = True

Close session at the end of the save method.

This only applies if the session is also being committed.

commit_on_save: bool = True

Commit session at the end of the save method.

This defaults to True but should be set to False if something else is taking care of committing the session. Check the documentation for examples.

session_extractor: Callable[[TransactionContext], AsyncSession]

A callback used to obtain the SQLAlchemy session from the current TransactionContext.

table_name: str

Outbox table name.