Skip to main content

Generic outbox worker for FastStream and custom repositories

Project description

outbox-worker

🌀 A generic asynchronous Outbox Worker for publishing events using FastStream and custom repositories. Supports payload validation and handler routing.

Installation

pip install git+https://github.com/your-org/outbox-worker.git

Or add it to your pyproject.toml:

[dependencies]
outbox-worker = { git = "https://github.com/your-org/outbox-worker.git" }

Quick Start

from faststream.rabbit import RabbitBroker
from outbox_worker import OutboxWorker, EventHandlerRouter
from your_project.handlers import YourHandler
from your_project.repos import your_event_repository_factory

router = EventHandlerRouter(
    handlers={
        "queue_name": YourHandler(),
    }
)

worker = OutboxWorker(
    event_repository_factory=your_event_repository_factory,
    broker=RabbitBroker("amqp://localhost/"),
    handler_router=router,
    batch_size=100,
    poll_interval=1.0,
)

await worker.run_polling()

Interfaces to Implement

HasOutboxPayload: Your event record type. Must have the fields:

  • id: int
  • queue: str
  • created_at: datetime
  • payload: dict
  • sent: bool
  • retry_count: int
  • is_failed: bool

OutboxEventRepository: Repository that fetches batches of events.

  • Method: fetch_batch(limit: int) -> Sequence[HasOutboxPayload]

  • Property: .session.commit() must be an async method

EventHandler: transforms a HasOutboxPayload record into a publishable dict

  • Method: to_payload(record) -> dict

EventHandlerRouter: routes records to the appropriate handler by queue name.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

outbox_worker-0.1.0.tar.gz (5.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

outbox_worker-0.1.0-py3-none-any.whl (5.4 kB view details)

Uploaded Python 3

File details

Details for the file outbox_worker-0.1.0.tar.gz.

File metadata

  • Download URL: outbox_worker-0.1.0.tar.gz
  • Upload date:
  • Size: 5.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.3

File hashes

Hashes for outbox_worker-0.1.0.tar.gz
Algorithm Hash digest
SHA256 00d883037441b053fad0184a732f72371cf7ca0693ee92b1228a689ec49f7b1b
MD5 afcad9602d147e9c16d9a03cc1a7e607
BLAKE2b-256 08bc48877d882bc13f290cd546e8bdc062bd3290d235d9cbffd294622f2d0d30

See more details on using hashes here.

File details

Details for the file outbox_worker-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: outbox_worker-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 5.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.3

File hashes

Hashes for outbox_worker-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 86d439d95a2ac9e2924cd687d5e0c6837e33fcf72bef307c672273d09fbe00bb
MD5 f4ad55095034a5eb416e6ca4812b9beb
BLAKE2b-256 717b783a8cbda3e517f42449d81fc513eb1a64f5361e9973cee88c05527d718f

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page