Download the PHP package webit/message-bus-sf-event-dispatcher without Composer
On this page you can find all versions of the php package webit/message-bus-sf-event-dispatcher. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Informations about the package message-bus-sf-event-dispatcher
Message Bus - Symfony Event Dispatcher Infrastructure
Symfony Event Dispatcher infrastructure for Message Bus
Installation
Usage
Publisher integration
To publish Message via Symfony Event Dispatcher use EventDispatcherPublisher
MessageBusEventFactory
You need to tell the EventDispatcherPublisher how to translate your Message into the event name and event object of Symfony Event Dispatcher. Implement and configure MessageBusEventFactory.
MessageBusEventFactory: Example
Let's say you're going to publish messages of two types: type-1 and type-2 and you want to map then to two different Events of Symfony Event Dispatcher Event1 and Event2.
Option 1: implement MessageBusEventFactory
Then combine both factories together
Option 2: Use GenericMessageBusEventFactory and implement its dependencies
then
Option 3: Implement your own strategy
As EventDispatcherPublisher expects an interface MessageBusEventFactory as a dependency, you can provide your own implementation for it. Also you can provide and combine inner interfaces used by GenericMessageBusEventFactory: SymfonyEventFactory and EventNameResolver.
If you like JMSSerializer to produce Symfony Event object, use JMSSerializerSymfonyEventFactory.
Putting the stuff together
Event consumption
Why to consume events at all?
-
Dispatches public events to the Message Bus If you want some events to be public and other applications be able to listen to them, use PublishingConsumer to publish them using different infrastructure (AMQP for example).
- Asynchronous events processing If you want some events to be processed asynchronously, use PublishingConsumer to publish them using different infrastructure (AMQP for example), then listen for them.
To consume Message created from Event of Symfony Event Dispatcher, use EventConsumingListener. It requires MessageFromEventFactory and Consumer to be provided.
GenericMessageFromEventFactory
It requires EventSerialiser and MessageTypeResolver (by default uses event name)
Option 1: Implement own EventSerialiser
Option 2: Use JMSSerializer to Serialise Event
Use FromMessageAwareEventMessageFromEventFactory
Your event can optionally implements MessageAwareEvent interface.
Then you can use FromMessageAwareEventMessageFromEventFactory to produce an event
Putting all together
Configure MessageFromEventFactory
Create a listener
Register the listener on Symfony Event Dispatcher for all required events
Running tests
Install dependencies with composer
All versions of message-bus-sf-event-dispatcher with dependencies
webit/message-bus Version ^1.0.0
symfony/event-dispatcher Version ^3.0|^4.0