B
B
BonBon Slick2020-12-07 15:01:53
symfony
BonBon Slick, 2020-12-07 15:01:53

New message bus handler vs handler subscriber?

https://symfony.com/doc/current/messenger.html#han...

What, where, when to use and why?

Examples:
1 - user registration through a social network or password
2 - user login through a social network or password
3 - deleting files, say photos, videos, music

This is the first thing that came to mind. Perhaps someone will explain or give an example from life when he used a listener and tell the community why he did this?
Everything will become unrealistically difficult if, for example, registration via social networks is also placed in RegisterUserHandler.
For example, there will be 2 messages RegisterUserWithPassword / RegisterSocialUser and both are handled in the same handler.
2 methods use some of the same services such as UserRepository but some are different, namely FaceBookApiService / GoogleApiService and others are needed only for social login and registration.
So, in each method we call
https://symfony.com/doc/current/messenger/dispatch...
the following commands, and in those other commands you can get lost in the chain of commands anyway.
But the question of command depth is completely different, I just wanted to show that the logic from the listener becomes more complicated, and the idea of ​​​​responsibility is even more blurred. And therefore I want to understand the meaning of adding such functionality and where, how to correctly apply it.



At the moment, there are only 2 handlers for Login / Registration by password and the same number through social networks + by the handler for deleting files, because. there it is necessary to call not only the FileStorageService, but also clean the entities, unbind from the user, etc. And that there will be 6+ handlers, if you take with related ones, then 10+.
The question arose because the ability to handle different commands in one handler seems to violate SOLID and the CQRS idea.
Because the team must handle 1 case to facilitate the logic. When there are many cases in one handler, this is already a service. For example, as EmailService or FileStorageService which are responsible for sending and mailing, managing files, recording, deleting, etc.

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question