0
votes

I'm developing a new C# Azure Durable Function that uses the RabbitMQ binding as a trigger when a new XML message is published to a queue. The starter function starts one of two orchestration functions, based on the content of the XML message.

I would like the starter function to ensure that only one instance of a given orchestration type run at any one time. So, it would be ok for a single instance of orchestration type A and orchestration type B to be running concurrently; but never two instances of type A or type B.

There's a good doc here that describes how to query orchestration state. What I'm not sure of is what to do with a new message that's received by the RabbitMQ binding, if the starter determines that an orchestration of the relevant type is currently running?

1

1 Answers

0
votes

I was able to solve this with a couple of nuggets. In the host.json file I set the prefectchCount to 1:

"extensions": {
"rabbitMQ": {
  "prefetchCount": 1 
}

In the orchestration starter code (triggered by receipt of a message from RabbitMQ) I loop until there are no instances of the orchestration running, then start a new one:

while (runningInstances.DurableOrchestrationState.Where
                    (x => x.Name == PortfolioActivationOrchestration
                    && x.RuntimeStatus == OrchestrationRuntimeStatus.Running).Count() > 0)
                {
                    _sl.LogInfo("Going to wait for PortfolioActivationOrchestration to complete");
                    Thread.Sleep(1000);
                    runningInstances = await starter.ListInstancesAsync(
                        noFilter,
                        CancellationToken.None);
                }
await starter.StartNewAsync(ClientActivationOrchestration, propBag);