SeriveBusTrigger 的 Durable Client 未调用 Orchestrator

问题描述

我正在尝试编写一个工作流来使用持久的 azure 函数来监听 serviceBustrigger。但是客户端在没有协调器的情况下运行。也不抛出任何错误。谁能告诉我在持久功能中启用 seriveBusTrigger 缺少什么? 以下是客户端功能代码

[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}");
            
        }
    

或者请分享任何工作代码示例。

解决方法

理论上只要调用启动orchestrator的方法就可以启动orchestrator。您是在本地测试还是在 Azure 中测试?你在环境变量中设置了一个值吗?

您使用了%%,因此需要指定环境变量的值,以便绑定或触发器可以获取指定信息。在本地,您需要在 local.settings.json 的“values”部分中设置值,而在 azure 中,您需要在配置设置中设置值。

以下代码有效,可以参考:

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

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...