Workflow with two receive activities and correlation - workflow-foundation-4

I've a workflow that has two receive activities in a pick activity. Whenever I get a request in the first request activity the workflow has to create a new instance while if the second receive activity get requests it should not create a new instance instead the messages should be routed to the already running instance (there should be an instance running already). How can I handle this?

I did some blog posts about how to setup message correlation to do this. Check here for a good starting point.

Related

Google Chat - Update Existing Message using Thread Message via Webhook

I am trying to update the existing message in Google Spaces, but it seems my webhook creates a new message every time. Any guidance will be appreciated.
if you look at the webhook i shared it contains a thredkey, i successfully created a message but unable to post Thread message even though using exactly as described by Google but for some reason my Thread webhook is posting a new message and not inside the Thread.
https://chat.googleapis.com/v1/spaces/AAAAxsij123/messages?&threadKey=g3kjfKDp123&key=AIzaSyDdI0hCZtE6vy123-WEfRq3CPzqKqgtHY&token=SE2dKe34qeSC6pvIc8NNCALCiUtdfo3FF5T_fWcFGT8%3D
It seems that you can only use a threadKey that you created with the same webhook, you cannot just grab the key from an existing thread to post in it. This is explained in the documentation here:
Each threadKey is unique to the app that sets it. If two different Chat apps or webhooks set the same threadKey, the messages do not thread. It is not possible to retrieve a threadKey from Chat API. The spaces.messages.thread.name field is the resource name of a thread in Chat API, not the threadKey.
This means that each webhook or Chat app has its own unique way to hash the string you used as threadKey and turn it into a "thread name", but as a result there's no (publicly available) way to do this process in reverse to get the threadKey from the "thread name". If you try to grab the name from an existing thread and add it as a key then it will just hash it again and turn it into a different one.
Essentially this means that, as the documentation explains, you have to create your own thread with an arbitrary string, then save that string to use it in the future. The arbitrary string can be anything so you can use something easy to remember. As shown in the docs:
https://chat.googleapis.com/v1/spaces/SPACE_ID/messages?threadKey=MY_KEY
Then just keep using MY_KEY in future messages and the webhook will post to the same thread. What you cannot do is to grab an existing thread, look for its ID and then try to post to it. The thread has to have been created by the same webhook.

Microservices async operation HTTP response

We're building a microservice app where clients can create projects. The following diagram shows the technical flow of this process:
My question: what HTTP response should the API gateway return to the client (step 1.)?
My initial idea was to give back a 202, but the problem there is that I don't know the Location yet (/projects/{id}), because the id of the project will be created at the Project Management Service.
Considering that the IDs of the newly created project entity is not known at the request time (i.e. it is generated after the insertion into the database) you indeed cannot generate the url to the project resource.
Instead, you could assign an ID (i.e. 1234-abcd-5678-efgh) to the command before sending to the bus and keep track of its execution status on the API gateway itself. Then you can respond to the client with an command execution status endpoint like /commands/1234-abcd-5678-efgh where it can query by polling.
The alternative would be to use another service that would reserve&deliver unique IDs but you must make a blocking call to it and this hurts scalability. Or you can host this service inside the API gateway itself (onto the same node) to minimize latency. Also, there is a risk of loosing some IDs in case of project creation failures but this can be compensated by releasing those IDs in those situations (thus increasing the architecture complexity).
A third solution could be the use of a project surogate ID, like a GUID, assigned as a property of the project, included in the command, having the purpose of an alternate identity that can be used only in the pre-creation phase of the process. Then, the response to the client could be like this: /projects/by-guid/1234-abcd-5678-efgh and after the project is created a GET to this url would permanently redirect to the final project url.

WF4 SendReply to Receive in another activity

I'm new to WF4 and was wondering if it was possible to send a reply to a receive activity defined in another workflow?
Once my WCF service receives a request I'm performing an operation in another activity and under certain conditions I want to send a reply to the request from this activity and then pause the workflow for further input. Is it possible to do this?
Thanks!
No that won't work. The Receive and the SendReply need to be linked to each other using an activity correlation handle.
What you can do however is use duplex communications where the second workflow sends a SOAP message to an endpoint with an address passed to it in the first message. Technically these are two separate requests and not related so there are no restrictions.

Invoke Child Workflow Activity Asynchronously

Team:
I need to invoke a WF activity (XAML) from a WF service (XAMLX) asynchronously. I am already referencing the Microsoft.Activities.Extensions framework and I'm running on the Platform Update 1 for the state machine -- so if the solution is already in one of those libraries I'm ready!
Now, I need to invoke that activity (XAML) asynchronously -- but it has an output parameter that needs to set a variable in the service (XAMLX). Can somebody please provide me a solution to this?
Thanks!
* UPDATE *
Now I can post pictures, * I think *, because I have enough reputation! Let me put a couple out here and try to better explain my problem. The first picture is the WF Service that has the two entry points for the workflow -- the second is the workflow itself.
This workflow is an orchestration mechanism that constantly restarts itself, and has some failover mechanisms (e.g. exit on error threshold and soft exit) so that we can manage our queue of durable transactions using WF!
Now, we had this workflow working great when it was all one WF Service because we could call the service, get a response back and send the value of that response back into another entry point in a trigger to issue a soft exit. However, a new requirement has arrisen asking us to make the workflow itself a WF activity in another project and have the Receive/Send-Reply sequences in the WF Service Application project.
However, we need to be able to startup this workflow and forget about it -- then let it know somehow that a soft exit is necessary later on down the road -- but since WF executes on a single thread this has become a bit challenging at best.
Strictly speaking in XAML activities Parallel and ParallelForEach are how you perform asynchrony.
The workflow scheduler only uses a single thread (much like UI) so any activity that is running will typically be running on the same thread, unless it implements AsyncCodeActivity, in which case you are simply handing back the scheduler thread to the runtime while waiting for a callback from whichever async code your AsyncCodeActivity implementation is calling.
Therefore are you sure this is what you want to achieve? Do you mean you want to run it after you have sent your initial response? In this case place your activity after the Send Reply.
Please provide more info if these suggestions don't answer your question./
Update:
The original requirement posed (separating implementation from the service Receive/Send activities) may actually be solved by hosting the target activity as a service. See the following link
http://blog.petegoo.com/index.php/2011/09/02/building-an-enterprise-workflow-system-with-wf4/

Multiple receive activities with the same operation name and signature

I have two Receive activities that both have the same operation name and signature (parameters). Is there a way to correlate a request to the workflow service to a specific Receive activity within a workflow instance? I understand how to correlate between workflow instances but not sure how (if you even can) to correlate a message to a specific Receive activity. I have a parameter in the signature of the Receive activity that could be used for the correlation.
See WF4 Workflow Services–Can you use the Same Operation more than once? for a look at this issue. Also Rory Primrose did an excellent followup with a technique that might work for you Calling a workflow service operation multiple times

Resources