My system uses The Command Pattern with separate handlers. My commands are executed on a CommandService which currently handles all commands in-process.
I have certain commands which do at least 1 of these things that are slow operations:
- Sends an email
- Generates a PDF
- Sends a Fax
- Interacts with 3rd party web services
I want all of these commands to be handled out of process so that the UI is more snappy.
Should I use a messaging bus just for these commands, or should I have the in-process command handler call BeginInvoke()
?
Edit - Additional Info
The system has a small number of users (maybe 100 concurrent on a busy day), so the queue would likely never get very long. The main thing here is to reduce the amount of time the UI is blocked when sending an email with an attached PDF (the command in question). The employees have to execute that command many times in a day.
With the entire situation in mind, I think I'm going to go with BeginInvoke()
for now for several reasons:
- All the UI interactions would have to be touched to make sure that they behave as though the command succeeded. The reminder of "you need to send this document" is in multiple places in the UI and it does a full page refresh once the report is sent.
- It's the middle of my client's busy season (they do over 50% of their yearly business in the summer), so it doesn't seem wise to me at this time to introduce a whole new piece of infrastructure that I'm unfamiliar with administering.
But knowing what I know now, on a new system I would use a service bus from the get-go for any slow commands (virtually every system needs to send an email) and design the UI so that commands could more easily be switched from synchronous to asynchronous processing. In implementation, that basically means every POST is AJAX and performs an action in the UI as if it succeeded. (For an example of this, check out how Facebook handles comments.)