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(
    source="profile",
    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.2.2.tar.gz (6.3 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.2.2-py3-none-any.whl (5.7 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: outbox_worker-0.2.2.tar.gz
  • Upload date:
  • Size: 6.3 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.2.2.tar.gz
Algorithm Hash digest
SHA256 49bfe8e377a9f26a302241b1880f1e75589a91b33c10c7e2aa6e663ab749086a
MD5 edfed035b340e9a9b600eb2014015b06
BLAKE2b-256 1fdcf4627677c777904c3d9d4c80dd04d4ba8708d15ba048bdcf47860da96ab9

See more details on using hashes here.

File details

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

File metadata

  • Download URL: outbox_worker-0.2.2-py3-none-any.whl
  • Upload date:
  • Size: 5.7 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.2.2-py3-none-any.whl
Algorithm Hash digest
SHA256 ced50b69be377d512cde2914b7c586e74e50efb21cb0a1532689262808d72673
MD5 99231eb458c7e012e21ec4a226144cd6
BLAKE2b-256 cc9292ab596ae3ca12aa8794268836e00498e0a942e0e80090bba64ff61a1673

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