Hi,
In my current project we need to have just one instance of a wf service in the cluster. That instance should be automatically created, that’s easy calling the receive in the global.asax, here is a good example:
http://blogs.msdn.com/b/rjacobs/archive/2010/09/01/how-to-make-the-wf4-batch-worker-autostart.aspx
But what happens if we have several machines trying to initialize the workflow? We need to create one, and just one, instance in a receive but later that instance should be the one who accepts the following messages, avoiding creating other instances.
The overall picture is the following parallel, in a branch we will be always receiving the initialization calls and in the other we will be executing the logic:
How can we receive the messages with the same instance? Is easy making a little trick in the receive shape:
- We create a correlation handler. Let’s call it singleIntanceHandler
- In the receive shape set the CorrelatesWith property with the singleInstanceHandler.
- In the CorrelatesOn definition you should insert a string, not an xpath expression. For instance: “asdf”.
- Leave the correlation initializer just with the handle for the response.
As I understand the first time it creates the instance initializating the correlation with “asdf”, the next time it receives a message, AppFabric looks if there is an instance that he could correlate with the string “asdf”, and it finds the one initialize in the first call.
Here is the code:
https://1drv.ms/u/s!Av_YzZiT16fZ1gWUs1-HPuG5qIoZ
Regards.
[…] All of this fits perfectly with the single instance pattern that I exposed in my last post. […]
This is a great post it raises some very interesting possibilities. Link to the example code appears to be dead would it be possible to re-post it?
I think now the link must work. Anyhow appfabric has been discontinued and we didn’t have a really really good experience with it. I would switch to nservicebus or something similar.