tempest-framework
tempest-framework copied to clipboard
Support different event bus transports
We discussed potential improvements for the current event bus in tempestphp/tempest-framework#6. This issue lists those improvements.
- Transports: A driver (for lack of a better term) that the event bus uses to interact with queues and topics. Multiple can be registered, but Tempest ships with one defined by default that handles all topics. We might have to split these into
SynchronousTransportandAsynchronousTransportinterfaces. - Queues: A channel for events to go to
- Topics: Specific events that a listener might subscribe to (e.g.,
pets.*)
In the configuration of a transport, we can define what topics we are interested in and/or handle some basic routing to queues. For example:
new GenericEventBus(
new EventBusConfig(
transports: [
// Tempest transport registered by default,
// sufficient for most.
new Transport(
driver: new TempestSynchronousDriver(),
topics: [
new Topic(), // Basically new Topic('*')->toQueue('*')
]
),
// RabbitMQ transport which allows cross-platform event handling
// but restricted to pets!
new Transport(
driver: new RabbitMqDriver(host: 'localhost'),
topics: [
new Topic('pets.*')->toQueue('pets'),
]
),
]
)
);
#[Topic('pets.cats')]
final readonly class ItHappened
{ /* … */ }
This API can still change.
I suggest we don't include this in 1.0, but aim for it to a next minor release