tempestphp / tempest-framework

The PHP framework that gets out of your way 🌊
https://tempest.stitcher.io
MIT License
635 stars 44 forks source link

Event Bus improvements #267

Open brendt opened 6 months ago

brendt commented 6 months ago

We discussed potential improvements for the current event bus in tempestphp/tempest-framework#6. This issue lists those improvements.

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: [
                    Topic::all(), // Basically Topic::new('*')->toQueue('*')
                ]
            ),

            // RabbitMQ transport which allows cross-platform event handling
            // but restricted to pets!
            new Transport(
                driver: new RabbitMqDriver(host: 'localhost'),
                topics: [
                    Topic::new('pets.*')->toQueue('pets'),
                ]
            ),
        ]
    )
);
#[Topic('pets.cats')]
final readonly class ItHappened
{ /* … */ }

This API can still change.

brendt commented 6 months ago

I suggest we don't include this in 1.0, but aim for it to a next minor release