Is there a difference between a message handler and a command handler?
Or is there a difference between a command and a message?
Edit: There is 3rd candiate called command message … ugh.
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Actually, the difference is not in structure nor implementation, it is rather a conceptual one – both of these structures are to represent different concepts.
Message – a structure that transports some kind of information
Command – a structure that triggers some kind of action
That said, a Command is a kind of Message, as it transports information about action to invoke at least (and in most cases additional parameters as well).
In terms of implementation, both MessageHandlers and CommandHandlers look very similar and depend on what do you want to do with the information.
Examples:
UserRegisteredMessage (userName) – a message that informs about registered used in a system, a handler can for display this information on UI
RegisterUserCommand(userName) – a command that instructs our system to register a user, this may involve some kind of additional action (like checks for uniqueness) and can can fail.