-
Notifications
You must be signed in to change notification settings - Fork 41
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
IEventHandler #19
Comments
I'm not going to advance this, but I won't discourage events in ShortBus. I think it is a common application abstraction that needs to be serviced in many apps. (along with Tasks) That being said, I haven't made it there yet with ShortBus, so I'm not going to push out uninformed functionality. You are welcome to submit a PR or even a more detailed issue with examples, use cases, etc. |
Turns out I wrote something on my own a while ago very similar to ShortBus, so I could add the implementation pretty easily if @mhinze would like to assign this to me. I've been using it production for years and it's worked great. It really helps keep command handlers focused and promote business logic reuse. Basically, you add IEvent to event classes (e.g. OrderSubmitted), add IEventHandler, and a Publish(params IEvent[]) method to complement Send(). Assign to me and I should be able to bang it out quickly. |
Besides params arguments, what is the difference between Publish and Send? They both look up a handler and invoke that handler. Is there more to it? Does Publish support multiple handlers for same event? (That would be like the "old" ShortBus Send) Events, commands, queries.. these are semantic differences. I would like ShortBus to implement mediation and leave semantics to the client. |
I think there's meaningful semantic difference. Here's my understanding (which comes mostly from using NServiceBus): Commands (ShortBus and NSB look to be identical here):
Events:
Both IEvent and ICommand inherit from IMessage in NSB and Request/Response messages (which is what queries are) are simply IMessage in NSB. I like your model better for queries as I think it's more clear. Let me know what you think. Hope this helps. |
I agree that there is a meaningful semantic difference. What I'm saying is that the semantics belong to the consuming application, mediation belongs to shortbus. So if we need a new mediation pattern, such as bringing back the "old send", I'm in favor of it. In that case we would have two mediation patterns:
|
The consuming application would need to use the mediation pattern to match an event to it's event handlers. I had started looking at MassTransit as an example of a consuming application framework. If a framework like MassTransit already has a way to do the mediation then ShortBus may not be require. But if someone has written a simple windows service to process message there could be some value in this case. My thinking is that a command handler would create events for other sub-systems to be notified of changes. These sub-systems would handle these event by defining event handlers and ShortBus would be used to determine the correct event handlers. Is this the correct thinking? |
I think where you are getting hung up is that ShortBus is for in-process, On Tue, Jan 14, 2014 at 9:51 AM, Zachariah Young
|
So as soon as I starting thinking about putting the message on a queue it's not in-process or in-application? |
Correct. On Tue, Jan 14, 2014 at 10:47 AM, Zachariah Young
|
So it sounds like all that would be needed is Publish(), which expects 0 to many handlers, and IEvent. (It's never appropriate to publish a command or query.) Does that sound right? |
Please review the referenced PR.. Depending on client consumption patterns Commands could use either Request or Notification (for example, in my API, commands have a result (HTTP 201 w/ Location header, but in previous applications I would have used the Notification method) The goal here is to take ShortBus out of the CQRS lingo and be a general purpose mediator. While I think ShortBus is useful in CQRS-participating applications, it's not a plug and play CQRS framework. |
That looks pretty good to me. On another note, what do you return as an HTTP status code for a command that does a Delete? Seems like a 201 (Created) wouldn't be appropriate in that case. |
If successful, we return a 204. |
I've made the Mediator a bit more plain again and then applied the model with Response and Exception handling in Extension methods, I consider this a more clean and flexible approach. |
Should we include a marker for event handlers?
The text was updated successfully, but these errors were encountered: