I'm writing an app that needs to run a task at a specific moment in time so I am planning to use Quartz.NET for this. The task that needs to run though, has multiple steps, some of which could be a little intensive, so I was thinking of using something like MSMQ to queue each part of the task, and have smaller focused sub tasks that spread the load, than one bit task.
The only pro开发者_如何学Goblem with this, is that it would then bypass the Quartz.NET failed task feature that I would like to use to ensure a task completes.
Can anyone suggest a way to use either Quartz.NET alone to do everything? or how to use MSMQ aswell, and still be able to use the Quartz.NET "task failure" feature? (or any other way I may not know of?)
This sounds a lot like the concept of a saga within NServiceBus which is built on top of MSMQ. You dispatch work to nodes and they respond back with their work (or failures). The saga then coordinates what tasks should happen next.
http://docs.particular.net/nservicebus/sagas/
One of the primary reasons to utilize NServiceBus for this is that it abstracts away a lot of the infrastructure for you and it has you focus in on business behavior and the events corresponding to that behavior.
You can schedule other tasks from within a Quartz.Net task. This would give you the ability to use the task failure feature for all of the sub tabs, but you wouldn't be able to apply this to the main task. This provides in essence the same feature you wanted to implement, without having to use MSMQ.
The question only specifies that spreading the load of the work is desirable, rather than handing off control in an asynchronous call to another task/process/message handler.
That being the case, the Quartz job could push 'task' messages onto MSMQ for some other services to pick up. It could then wait for 'response' messages on another queue before exiting the Execute
method. It could do this by polling that queue. Once it has received either a success or failure message it can then exit the Execute
method either cleanly or by throwing a JobExecutionException
.
This solution isn't too elegant. The request/response mechanism and transport can be abstracted out, e.g. by WCF or NServiceBus, but the fact that you're implicitly after what is basically a duplex communication means that it isn't well suited to MSMQ. It's possible though (see http://www.codeproject.com/Articles/41907/WCF-Duplex-MSMQ or http://docs.particular.net/samples/fullduplex/). You may just be better using a series of web services of some kind, asynchronously invoke them and wait on all the completions.
精彩评论