Azure应用功能应用程序' AppName'已关闭
我正在创建一个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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
谢谢@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.
To resolve the above issue ,When deploying Azure function with EventHub as in
local.settings.json
we provide the value foreventhubOutputConnectionAppSetting
.So when deploying function app to azure it can't readlocal.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 theeventhubOutputConnectionAppSetting
and save it.For more information please refer this SO THREAD for the similar issue.