You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Doctrine2 has lifecycle events which trigger on create, update, delete. We can hook into those events and push a new message with enough information a processor might do something with it (for example, clear cache, run webhooks, run long running jobs which waited for that entity to reach that state in the attached state machine, etc).
I've created a sample implementation with usage example from Symfony container (disregard the userToken stuff in the processor, that's a hacky implementation for which I'll open another issue).
It works like this (C/P from gitter):
you create an entity, persist it
Doctrine triggers a postPersist, passing the entity
DoctrineEventConverter creates a new DoctrineEventMessage from the Doctrine event
(passing event type, entity class and entity PK)
TestProcessor attaches a user token to the message before sending it
(this is temporary, need a better way to do it, maybe an extension of some sort?)
DoctrineEventConverter sends the message via the producer
<transport>
worker running enqueue:consume picks up the message, passes it back to DoctrineEventConverter
DoctrineEventConverter creates a new DoctrineEventMessage from the PSR message
TestProcessor pulls the user token from the message, stores it to its own tokenStorage and also to gedmo (temporary, also)
DoctrineEventConverter fetches the entity by class+ID, stores it to DoctrineEventMessage and passes it to TestProcessor
TestProcessor appends the string " processed" to the entity name
Doctrine triggers a postUpdate, passing the entity
we start from 3) again, but this time the origin is the worker, not ourselves
if anybody was listening for postUpdate, it would trigger here again (so you can chain events)
it stops once all processors decline to do an entity change
The text was updated successfully, but these errors were encountered:
Just a reminder for myself: this approach does NOT work.
If you attach two listeners to postPersist, seeing as the RabbitMQ exchange is "fanout", there will be a Cartesian amount of messages (N = number of listeners) because: N times sent (by each listener) x N times delivered (by RabbitMQ + fanout) = N^2 deliveries.
Doctrine events need to be converted to Enqueue messages from a single dedicated service which triggers all the events (for all listeners).
Doctrine2 has lifecycle events which trigger on create, update, delete. We can hook into those events and push a new message with enough information a processor might do something with it (for example, clear cache, run webhooks, run long running jobs which waited for that entity to reach that state in the attached state machine, etc).
I've created a sample implementation with usage example from Symfony container (disregard the
userToken
stuff in the processor, that's a hacky implementation for which I'll open another issue).It works like this (C/P from gitter):
(passing event type, entity class and entity PK)
(this is temporary, need a better way to do it, maybe an extension of some sort?)
The text was updated successfully, but these errors were encountered: