Scenario
Lets say I have three major components of a system:
UI - Collects input from the user and creates a LoginUserCommand that is sent over a message bus. The user interface then listens to this message bus for MessageReceivedEvent(s).
User Service - receives a LoginUserCommand and raises a UserLoggedInEvent. The critical part here is that Message Service needs to be told to begin receiving messages.
Message Service - raises MessageReceivedEvent(s) for logged in users.
Options
The design question I have is regarding the interaction between the User Service and the Message Service.
When a user logs in a number of things need to happen - the services need to coordinate so that the UI begins to receive messages.
Should I...
- Have the User Service raise a UserLoggedInEvent and have the Message Service listen to this event and perform the work required for the user to receive messages?
...or...
- Have the User Service raise a UserLoggedInEvent BUT then create a command - StartMessageReceivingCommand and explicitly send this to the Message Service?
Question
What are the Pros/Cons of each approach? (cascading events vs. explicit commands). Are there any other options?
if your services are real services just raise a userloggedinevent and let the "message service" decide what to do next. the user service should have no knowledge about an message service that needs to start receiving messages if a user has logged in. just raise the event and let every subscriber decide on his own what to do next.