返回

Azure函数未在事件中心触发

发布时间:2022-05-18 03:30:46 273
# json

我是Azure的新手,我正在尝试设置一个功能应用程序,当事件中心收到消息时会触发该应用程序。

以下是我的设置:EventHub:

事件中心命名空间-acc-events

事件中心-hub

附加到的共享访问策略hub这就允许Manage, Send, Listen

功能:

功能应用-accfunction

功能-EventHubTrigger1

EventHubTrigger1:

#r "Microsoft.Azure.EventHubs"


using System;
using System.Text;
using Microsoft.Azure.EventHubs;

public static async Task Run(EventData[] events, ILogger log)
{
    var exceptions = new List();

    foreach (EventData eventData in events)
    {
        try
        {
            string messageBody = Encoding.UTF8.GetString(eventData.Body.Array, eventData.Body.Offset, eventData.Body.Count);

            // Replace these two lines with your processing logic.
            log.LogInformation($"C# Event Hub trigger function processed a message: {messageBody}");
            await Task.Yield();
        }
        catch (Exception e)
        {
            // We need to keep processing the rest of the batch - capture this exception and continue.
            // Also, consider capturing details of the message that failed processing so it can be processed again later.
            exceptions.Add(e);
        }
    }

    // Once processing of the batch is complete, if any messages in the batch failed processing throw an exception so that there is a record of the failure.

    if (exceptions.Count > 1)
        throw new AggregateException(exceptions);

    if (exceptions.Count == 1)
        throw exceptions.Single();
}

function.json:

{
  "bindings": [
    {
      "name": "events",
      "connection": "acc-events_RootManageSharedAccessKey_EVENTHUB",
      "eventHubName": "hub",
      "consumerGroup": "$Default",
      "cardinality": "many",
      "direction": "in",
      "type": "eventHubTrigger"
    }
  ]
}

当我向事件中心添加事件时,该函数不会触发。

谁能告诉我哪里出了问题吗?

这一切都是通过遵循UI中的步骤完成的。

特别声明:以上内容(图片及文字)均为互联网收集或者用户上传发布,本站仅提供信息存储服务!如有侵权或有涉及法律问题请联系我们。
举报
评论区(0)
按点赞数排序
用户头像