The difference between a command and an event in bus communication seems a little vague to me. I know that commands should be executed once only, while an event can be handled multiple times, but still I'm not sure when to use a command or an event.
Let's look at an example:
When a new user registers to a web application, we should create him an account and send a confirmation email.
Creating the account - this seems to be the right spot to send a
CreateUserCommand to the bus and let a specialized component handle it.
Or maybe this shouldn't even be implemented with an asynchronous bus communication? We want the user to ba able to log in into the application right away. With the bus we have no guarantee when the command will be executed.
Sending email - after the component creates the account I can see 2 possibilities
- Send another command to the bus
- Publish an event
And than let the email sender component grab it and to it's job.
On one hand I want the confirmation email to be sent once only (use a command), on the other hand, I believe there can be multiple components interested in newly registered users. A logger or maybe an SMS sender.
How would you implement it?