-->

Use Bus.Send (not Publish) from web applications (

2019-08-28 22:37发布

问题:

We have an asp.net mvc3 application which publishes a number of events. Recently, someone pointed out that we should be sending messages rather than publishing events from the web application and referenced this excellent blog post which makes perfect sense. However, I want to confirm that the points made in the post are still valid for NServiceBus v3.x?

Thanks!

回答1:

I would imagine that the reasoning behind the post would always hold true, irrespective of the version of NServiceBus.

That being said, there is nothing stopping you from publishing a message from a web-site. The idea behind publishing a message is that the message represents an event that is typically produced by some processing endpoint. Since a web application should not really be processing anything but rather be sending commands off to a processing endpoint it would stand to reason that a web application should not be publishing events.

So if you find yourself in a situation where it seems to make sense to publish from your web application it indicates that you need to make a design decision: either the design is not optimal (so the web application is performing processing) or you are constrained in some way the prohibits the implementation of a processing endpoint (maybe a shared hosting environment).