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 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
  • is_published: 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.1.tar.gz (6.0 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.1-py3-none-any.whl (5.6 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: outbox_worker-0.1.1.tar.gz
  • Upload date:
  • Size: 6.0 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.1.tar.gz
Algorithm Hash digest
SHA256 be7987dc331eefab20b02df3c8bb5a274a6ecc93f4a0e247ea2e09bf49afa784
MD5 f1b2da3ca953a53e87ad4e1703dbda44
BLAKE2b-256 59753e8948463ba2832337f06229a345374d71a2cc176fb5f3137d9ca5cced87

See more details on using hashes here.

File details

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

File metadata

  • Download URL: outbox_worker-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 5.6 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.1-py3-none-any.whl
Algorithm Hash digest
SHA256 bf1e1a283afde3ba18918c65679e9c076164148fb9060af7850aa8c515b34236
MD5 6c2e4e0a3d5d93314e825bd4d3f4614c
BLAKE2b-256 cddd266d1ce3fd4706cdb3465d0bbb91f1386b222697b82ada0bf99aca7790b0

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