微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

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

如何解决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();
        }
    }
}

解决方法

如果它在本地运行正常,但没有在azure门户中执行,则请检查是否在azure门户->您的功能应用配置中指定了“ AzureEventHubConnectionString”。步骤如下:

导航到azure门户->转到功能应用程序->配置->应用程序设置,在该页面上,请检查是否指定了“ AzureEventHubConnectionString”,并且其值应正确。屏幕截图如下:

enter image description here

顺便说一句,您最好为功能应用程序启用Application Insights,这可以为您带来更好的监控体验。您可以按照下面的屏幕快照启用Application Insights:

1。在azure门户中,单击功能应用程序实例,例如EventhubTrigger1

enter image description here

2。然后单击Monitor->单击Configure按钮以启用应用程序见解:

enter image description here

之后,当我执行该功能时,我可以在azure门户上看到它的执行情况:

enter image description here

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。