Azure函数在azure门户上显示0次执行

问题描述

我是一个天蓝色的新手。我的设置如下。我有一个IoT中心,一个事件中心和一个Azure函数。 想法是将消息发送到IoT中心,根据某种消息类型将其路由到事件中心,并使用该功能处理这些事件。

我创建了一个示例控制台应用程序,以将消息从我的机器发送到IoT中心。在Visual Studio(.Net Core)上创建了天蓝色函数,并将其发布到天蓝色函数应用程序。

现在,当我同时运行控制台应用程序项目和功能应用程序项目时,我看到了在IoT中心上收到的消息(通过查看azure门户),并且该函数被触发并收到了我发送的消息(通过使用功能应用程序查看在我的计算机上弹出的控制台)。

我的问题是,当我随后检查azure门户时,我看到函数执行计数为0,即使我在本地检查时看到函数正在选择事件。知道为什么会这样吗?

Event received by the function

zero executions shown on azure portal

功能代码基于Visual Studio随附的模板

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Microsoft.Azure.EventHubs;
using Microsoft.Azure.WebJobs;
using Microsoft.Extensions.Logging;

namespace FunctionApp2
{
    public static class Function1
    {
        [FunctionName("Function1")]
        public static async Task Run([EventHubTrigger("azureiotquickstarteventhub",Connection = "AzureEventHubConnectionString")] EventData[] events,ILogger log)
        {
            var exceptions = new List<Exception>();

            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();
        }
    }
}

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)