In Symfony applications, this is very similar to an event-based system - but over different threads and not the standard PHP single-threaded way of working. Of course, PHP can only work over one thread at a time, which is why it is effectively handled by a different process. The original process stops when the message is delivered to the bus.
One of the big advantages of a message is that it is asynchronous, the sender does not wait for a response from the receiver. Another advantage is that they are reliable, when the processor stops answering, the message waits in the bus until it can be picked up.
These are the major changes compared to the Event system.
Advantages:
- Better application structure because not everything has to be in the same place, this is partly also an advantage of the event system. But there everything still has to live in the same application. A message that comes via a bus should not be handled in the same application and not even in the same language.
- Asynchronous processing of data.
- It is an easy way to increase scale. Multiple workers can be added to handle heavy events. This way it is easy to scale up where possible.
Furthermore David goes very deep into how the Symfony Messenger works. But there are also a number of framework diagnostic tips, including this one:
Your message is quite small and only contains the id of the object it's about. The subscriber will then retrieve the same data from the database. This ensures that the receiver always has the most recent data. This tip was contradicted in the next session of Samuel Roze, according to him it is sometimes possible to put all the data in the message. Interesting that it is always looked at from our own background.
Symfony Messenger also has rejuvenation built-in. This means that a process itself can process a number of messages before it closes itself. This process can then be restarted by supervisor/docker.
The next concept was about transport decorators, this is a way to wrap a message that is sent out with extra metadata before it is effectively put on the bus.
David gave some examples, including deduplicate - this is a semaphore system in Redis. This ensures that a product can only be put on the queue once until it is finished. This way, fast updates can't overload the queue.
In the chat of the talk there was a lot of talk about message architectures. A tip was to use the doctrine/database transport by default, which is easy to start with.
There are other implementations possible as soon as there is scaling up, moving your messages to Amazon SQS, Redis, AMQP or Apache Kafka will automatically reduce the load on your database.