⚙️ Writing Custom Producers & Consumers¶
Dispytch doesn’t lock you into any specific messaging backend. If you want to connect to something like Redis Streams,
SQS, or whatever queue you want—you can do that by implementing your own Producer
and Consumer
.
Here’s how.
🧪 Custom Producer¶
To build your own event emitter backend, implement the Producer
interface.
✍️ Interface¶
1 2 3 4 |
|
💡 Notes¶
topic
: where the event goespayload
: bytes containing the event payloadconfig
: optional backend-specific config, usually declared in the event as__backend_config__
- If your send logic times out raise
ProducerTimeout
✅ Example (Pseudocode!!!)¶
1 2 3 4 5 6 7 8 |
|
🧃 Custom Consumer¶
To receive and handle events from your own backend, implement the Consumer
interface.
✍️ Interface¶
1 2 3 4 5 6 7 8 |
|
💡 Notes¶
-
listen()
must yieldMessage
objects. This is an async generator. -
ack()
is called when Dispytch successfully processes an event. Use it to mark the event as handled (e.g., ack a Kafka offset or delete a message from a queue).
✅ Example (Pseudocode!!!)¶
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
|
🛠️ Use Your Custom Classes¶
Once implemented, you can use your custom producer and consumer classes directly in EventEmitter
and EventListener