0

I am trying to write a workflow to listen serviceBustrigger using durable azure functions. But client running without orchestrator. Neither throwing any error. Can anyone tell what am i missing to enable seriveBusTrigger in durable function? Following is the client function code :

[FunctionName("UpdateGlobalRatesOnRSLs")]
        public static async Task Run(
            [ServiceBusTrigger("%EventMessageTopic%", "%Subscriber%", Connection = "ServiceBus")] string message,
            MessageReceiver messageReceiver,
            string lockToken,
            [DurableClient] IDurableOrchestrationClient starter, ILogger log)
        {
            log.LogInformation($"message - " + message);
            if (string.IsNullOrWhiteSpace(message)) await messageReceiver.DeadLetterAsync(lockToken, "Message content is empty.", "Message content is empty.");

            var orchestrationInput = JsonConvert.DeserializeObject(message);
            string instanceId = await starter.StartNewAsync<object>("UpdateGlobalRatesOnRSLs_OrchestrationFunction", orchestrationInput);
            log.LogInformation($"Orchestration Started with ID: {instanceId}");
            
        }
    

Or please share any working code sample.

Cindy Pau
  • 13,085
  • 1
  • 15
  • 27

1 Answers1

0

In theory, just call the method of starting the orchestrator can make the orchestrator start. Are you testing local or in Azure? Do you set a value in the environment variable?

You used %%, so you need to specify the value of the environment variable so that the binding or trigger can obtain the specified information. Locally, you need to set values in the ‘values’ section of local.settings.json, while on azure you need to set values in the configuration settings.

The following code is valid, you can refer to it:

using System.Collections.Generic;
using System.Net.Http;
using System.Threading.Tasks;
using Microsoft.Azure.WebJobs;
using Microsoft.Azure.WebJobs.Extensions.DurableTask;
using Microsoft.Azure.WebJobs.Extensions.Http;
using Microsoft.Azure.WebJobs.Host;
using Microsoft.Extensions.Logging;

namespace FunctionApp83
{
    public static class Function1
    {
        [FunctionName("Function1")]
        public static async Task<List<string>> RunOrchestrator(
            [OrchestrationTrigger] IDurableOrchestrationContext context)
        {
            var outputs = new List<string>();

            // Replace "hello" with the name of your Durable Activity Function.
            outputs.Add(await context.CallActivityAsync<string>("Function1_Hello", "Tokyo"));

            // returns ["Hello Tokyo!", "Hello Seattle!", "Hello London!"]
            return outputs;
        }

        [FunctionName("Function1_Hello")]
        public static string SayHello([ActivityTrigger] string name, ILogger log)
        {
            log.LogInformation($"Saying hello to {name}.");
            return $"Hello {name}!";
        }

        [FunctionName("Function1_HttpStart")]
        public static async Task HttpStart(
            [ServiceBusTrigger("%EventMessageTopic%", "%Subscriber%", Connection = "str")] string mySbMsg,
            [DurableClient] IDurableOrchestrationClient starter,
            ILogger log)
        {
            // Function input comes from the request content.
            string instanceId = await starter.StartNewAsync("Function1", null);

            log.LogInformation($"C# ServiceBus topic trigger function processed message: {mySbMsg}");
        }
    }
}

local.settings.json(on local):

{
    "IsEncrypted": false,
  "Values": {
    "AzureWebJobsStorage": "UseDevelopmentStorage=true",
    "FUNCTIONS_WORKER_RUNTIME": "dotnet",
    "str": "Endpoint=sb://bowman1012.servicebus.windows.net/;SharedAccessKeyName=xxxxxx",
    "EventMessageTopic": "bowman1012",
    "Subscriber": "test"
  }
}

Configuration settings(on azure):

enter image description here

Cindy Pau
  • 13,085
  • 1
  • 15
  • 27