Azure应用功能应用程序' AppName'已关闭

发布于 2025-02-10 00:19:11 字数 4094 浏览 1 评论 0原文

我正在创建一个Azure应用功能,以从事件中心读取并写入另一个事件中心。最初,我只是从活动中心阅读并记录一些消息,这很好。

原始代码

        [FunctionName("EHFunction")]
        public static async Task Run(
            [EventHubTrigger("ehquery", Connection = "EventHubConnectionString")] EventData[] events,
            ILogger log)
        {
            var exceptions = new List<Exception>();

            foreach (EventData eventData in events)
            {
                try
                {
                    // Read event hub event which contains link to a blob with messages. Read messages from the blob storage endpoint.

                    foreach (var blobEntry in blobData)
                    {
                        foreach (var record in blobEntry.Records)
                        {
                            var recordStr = record.ToString();
                            log.LogInformation($"Record: {recordStr}");
                        }
                    }
                }
                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.
                    log.LogCritical(e.Message);
                    exceptions.Add(e);
                }
            }

这很棒。现在,我更新了代码以将记录写入新事件中心:

        [FunctionName("EHFunction")]
        public static async Task Run(
            [EventHubTrigger("ehquery", Connection = "EventHubConnectionString")] EventData[] events,
            [EventHub("ehquery-output", Connection = "EventHubOutputConnectionAppSetting")] IAsyncCollector<string> outputEvents,
            ILogger log)
        {
            var exceptions = new List<Exception>();

            foreach (EventData eventData in events)
            {
                try
                {
                    // Read event hub event which contains link to a blob with messages. Read messages from the blob storage endpoint.

                    foreach (var blobEntry in blobData)
                    {
                        foreach (var record in blobEntry.Records)
                        {
                            var recordStr = record.ToString();
                            await outputEvents.AddAsync(recordStr);
                        }
                    }
                }
                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.
                    log.LogCritical(e.Message);
                    exceptions.Add(e);
                }
            }

当我发布此功能时,我在Eventlog.xml文件中看到以下消息,

<EventData>
<Data>Application 'C:\Program Files (x86)\SiteExtensions\Functions\3.7.1\64bit\' started successfully.</Data>
<Data>Process Id: 3776.</Data>
<Data>File Version: 13.1.22054.23. Description: IIS ASP.NET Core Module V2 Request Handler. Commit: 509f6badec2f3162f0e50330cd9107e5624b379b</Data>
</EventData>
</Event>
<EventData>
<Data>Application 'MACHINE/WEBROOT/APPHOST/EHFunction' has shutdown.</Data>
<Data>Process Id: 4624.</Data>
<Data>File Version: 13.1.22054.23. Description: IIS ASP.NET Core Module V2 Request Handler. Commit: 509f6badec2f3162f0e50330cd9107e5624b379b</Data>
</EventData>
</Event>

这是我的local.settings.json for Reference

{
    "IsEncrypted": false,
  "Values": {
    "AzureWebJobsStorage": "UseDevelopmentStorage=true",
    "EventHubConnectionString": "Endpoint=sb://{inputeventhubconnectionstring}",
    "EventHubOutputConnectionAppSetting": "Endpoint=sb://{outputeventhubconnectionstring}",
    "FUNCTIONS_WORKER_RUNTIME": "dotnet"
  }
}

for hose gose中心?我在做什么错?

I am creating an Azure app function to read from an event hub and write to another event hub. Initially, I was only reading from the event hub and logging some message and that was working fine.

Original code

        [FunctionName("EHFunction")]
        public static async Task Run(
            [EventHubTrigger("ehquery", Connection = "EventHubConnectionString")] EventData[] events,
            ILogger log)
        {
            var exceptions = new List<Exception>();

            foreach (EventData eventData in events)
            {
                try
                {
                    // Read event hub event which contains link to a blob with messages. Read messages from the blob storage endpoint.

                    foreach (var blobEntry in blobData)
                    {
                        foreach (var record in blobEntry.Records)
                        {
                            var recordStr = record.ToString();
                            log.LogInformation(
quot;Record: {recordStr}");
                        }
                    }
                }
                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.
                    log.LogCritical(e.Message);
                    exceptions.Add(e);
                }
            }

This was working great. Now I updated code to write the records to a new event hub:

        [FunctionName("EHFunction")]
        public static async Task Run(
            [EventHubTrigger("ehquery", Connection = "EventHubConnectionString")] EventData[] events,
            [EventHub("ehquery-output", Connection = "EventHubOutputConnectionAppSetting")] IAsyncCollector<string> outputEvents,
            ILogger log)
        {
            var exceptions = new List<Exception>();

            foreach (EventData eventData in events)
            {
                try
                {
                    // Read event hub event which contains link to a blob with messages. Read messages from the blob storage endpoint.

                    foreach (var blobEntry in blobData)
                    {
                        foreach (var record in blobEntry.Records)
                        {
                            var recordStr = record.ToString();
                            await outputEvents.AddAsync(recordStr);
                        }
                    }
                }
                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.
                    log.LogCritical(e.Message);
                    exceptions.Add(e);
                }
            }

When I publish this function, I see the following messages in the eventlog.xml file

<EventData>
<Data>Application 'C:\Program Files (x86)\SiteExtensions\Functions\3.7.1\64bit\' started successfully.</Data>
<Data>Process Id: 3776.</Data>
<Data>File Version: 13.1.22054.23. Description: IIS ASP.NET Core Module V2 Request Handler. Commit: 509f6badec2f3162f0e50330cd9107e5624b379b</Data>
</EventData>
</Event>
<EventData>
<Data>Application 'MACHINE/WEBROOT/APPHOST/EHFunction' has shutdown.</Data>
<Data>Process Id: 4624.</Data>
<Data>File Version: 13.1.22054.23. Description: IIS ASP.NET Core Module V2 Request Handler. Commit: 509f6badec2f3162f0e50330cd9107e5624b379b</Data>
</EventData>
</Event>

This is my local.settings.json for reference

{
    "IsEncrypted": false,
  "Values": {
    "AzureWebJobsStorage": "UseDevelopmentStorage=true",
    "EventHubConnectionString": "Endpoint=sb://{inputeventhubconnectionstring}",
    "EventHubOutputConnectionAppSetting": "Endpoint=sb://{outputeventhubconnectionstring}",
    "FUNCTIONS_WORKER_RUNTIME": "dotnet"
  }
}

Why is the function unable to write to event hub? What am I doing wrong?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

锦爱 2025-02-17 00:19:11

谢谢@Gengis Khan,为您在评论中提到的为您服务的解决方案。我正在重新发布同样的解决方案,以便其他社区成员可以从中受益。

为什么该功能无法写入事件中心?我在做什么
错误?

要解决上述问题,当用local.settings.json.json中的EventHub部署Azure函数时,我们为EvensHubOutputConnectionAppsetting。应用程序到Azure无法读取local.settings.json我们需要在Portal上的函数中添加新的应用程序设置(通过 configuration-&gt; new应用程序设置)通过为eventHuboutputConnectionAppSetting提供正确的值,并保存它。

“在此处输入映像说明”

有关更多信息,请参阅此 < < a href =“ https://stackoverflow.com/questions/69486843/azure-function-app-does-not-trigger-by-event-hub”> ,所以线程 对于类似的问题

Thank you @Gengis Khan, for the solution that worked for you which you have mentioned in your comment. I am reposting the same solution so that other SO community members might benefit from it.

Why is the function unable to write to event hub? What am I doing
wrong?

To resolve the above issue ,When deploying Azure function with EventHub as in local.settings.json we provide the value for eventhubOutputConnectionAppSetting.So when deploying function app to azure it can't read local.settings.json file we need to add new App settings in the Function on Portal(via Configuration->New Application Settings) itself by providing the correct value for the eventhubOutputConnectionAppSetting and save it.

enter image description here

For more information please refer this SO THREAD for the similar issue.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文