英文:
How can I debug and Azure Functions that is receiving the same message again and again?
问题
我有一个用C#编写的Azure Functions。触发器是来自ServiceBus的消息。
当它接收到消息时,它会启动一个进程来转换相同的数据。这个过程可能会相当长,大约50/60秒,而且这个过程会调用一些API。
我收到了以下错误消息:
> [2023-02-14T00:42:01.683Z] 执行 'getDataSB' (失败,
> Id=ec780726-d740-4445-b964-d8493233874a,持续时间=22985毫秒)
>
> [2023-02-14T00:42:01.685Z] System.Private.CoreLib: 在执行函数时出现异常:getDataSB. System.Net.Http:响应状态代码不指示成功:302 (Found)。
>
> [2023-02-14T00:42:01.747Z] 消息处理错误
> (Action=ProcessMessageCallback,EntityPath=vs,
> Endpoint=wb.servicebus.windows.net)
>
> [2023-02-14T00:42:01.748Z]
> System.Private.CoreLib: 在执行函数时出现异常:getDataSB. System.Net.Http:响应状态代码不
> 指示成功:302 (Found)。
我不确定错误是来自API还是来自Azure Functions。我一直不断地接收到相同的消息。我添加了很多日志,但它们没有显示在本地控制台中。
public class GetDataSB
{
private readonly ILogger<GetDataSB> _logger;
public GetReversoVerbSynonymSB(ILogger<GetDataSB> log)
{
_logger = log;
}
[FunctionName("getDataSB")]
public async Task Run(
[ServiceBusTrigger("vs", Connection = "SBConnectionString")]
string myQueueItem)
{
ServiceBusRequest request =
JsonSerializer.Deserialize<ServiceBusRequest>(myQueueItem);
string processName = Environment.GetEnvironmentVariable("ProcessName");
await ProcessService.ProcessData(request, processName, _logger);
}
}
ProcessService
是一个静态类。
public static class ProcessService {
public static async Task<IActionResult> ProcessData(
ServiceBusRequest request, string SystemUser, ILogger log) {
log.LogInformation("正在读取数据...");
}
}
有办法更改执行的超时时间吗?
我考虑通过在 host.json
中添加以下设置来限制并发数量:
{
"version": "2.0",
"logging": {
"applicationInsights": {
"samplingSettings": {
"isEnabled": true,
"excludedTypes": "Request"
}
}
},
"extensions": {
"serviceBus": {
"prefetchCount": 100,
"messageHandlerOptions": {
"autoComplete": true,
"maxConcurrentCalls": 1,
"maxAutoRenewDuration": "00:05:00"
},
"sessionHandlerOptions": {
"autoComplete": true,
"messageWaitTimeout": "00:00:30",
"maxAutoRenewDuration": "00:55:00",
"maxConcurrentSessions": 1
}
}
}
}
英文:
I have an Azure Functions in C#. The trigger is a message from a ServiceBus.
When it receives the message, it starts a process to convert same data. The process could be quite long, around 50/60 seconds and the process calls few APIs.
I get this error:
> [2023-02-14T00:42:01.683Z] Executed 'getDataSB' (Failed,
> Id=ec780726-d740-4445-b964-d8493233874a, Duration=22985ms)
>
> [2023-02-14T00:42:01.685Z] System.Private.CoreLib: Exception while
> executing function: getDataSB. System.Net.Http: Response
> status code does not indicate success: 302 (Found).
>
> [2023-02-14T00:42:01.747Z] Message processing error
> (Action=ProcessMessageCallback, EntityPath=vs,
> Endpoint=wb.servicebus.windows.net)
>
> [2023-02-14T00:42:01.748Z]
> System.Private.CoreLib: Exception while executing function:
> getDataSB. System.Net.Http: Response status code does
> not indicate success: 302 (Found).
I don't understand if the error is coming from the APIs or from the Azure Functions. I continue to receive the message again and again. I added a lot of logs but they are not displayed in the local console.
public class GetDataSB
{
private readonly ILogger<GetDataSB> _logger;
public GetReversoVerbSynonymSB(ILogger<GetDataSB> log)
{
_logger = log;
}
[FunctionName("getDataSB")]
public async Task Run(
[ServiceBusTrigger("vs", Connection = "SBConnectionString")]
string myQueueItem)
{
ServiceBusRequest request =
JsonSerializer.Deserialize<ServiceBusRequest>(myQueueItem);
string processName = Environment.GetEnvironmentVariable("ProcessName");
await ProcessService.ProcessData(request, processName, _logger);
}
}
ProcessService
is a static class.
public static class ProcessService {
public static async Task<IActionResult> ProcessData(
ServiceBusRequest request, string SystemUser, ILogger log) {
log.LogInformation("Reading data...");
}
}
Is there a way to change the time out of the execution?
I thought to limit the number of concurrency adding in the host.json
this setting:
{
"version": "2.0",
"logging": {
"applicationInsights": {
"samplingSettings": {
"isEnabled": true,
"excludedTypes": "Request"
}
}
},
"extensions": {
"serviceBus": {
"prefetchCount": 100,
"messageHandlerOptions": {
"autoComplete": true,
"maxConcurrentCalls": 1,
"maxAutoRenewDuration": "00:05:00"
},
"sessionHandlerOptions": {
"autoComplete": true,
"messageWaitTimeout": "00:00:30",
"maxAutoRenewDuration": "00:55:00",
"maxConcurrentSessions": 1
}
}
}
}
答案1
得分: 1
似乎您的Azure函数在处理来自ServiceBus的消息时出现了故障,结果是相同的消息一遍又一遍地传递给函数。可能有多种原因,比如您调用的API或Azure函数的配置存在问题。
调试此问题的步骤:
-
验证您从函数中调用的API的响应。
-
您看到的302响应表示重定向响应。这可能是因为您调用的API端点已被移动或临时不可用。确保您正在使用正确的API端点并且它是可用的。
-
检查Azure函数的日志。您提到添加了大量日志,但它们未显示在本地控制台中。确保您使用正确的日志配置并查看正确的日志流。您还可以尝试使用其他日志框架,如Serilog来记录进程的详细信息。
-
检查Azure函数的配置。有可能函数在能够完成处理之前超时。
您可以通过修改host.json
文件中的functionTimeout
属性来增加Azure函数的超时值
。
-
检查ServiceBus配置。可能消息没有被正确确认或处理,导致Azure函数重新传递它。
-
使用Azure Application Insights监视Azure函数。
这有助于识别函数中可能出现的性能问题、异常或其他问题。
感谢 @Skin 的评论。
使用Visual Studio调试器
附加进程。
选择要调试的进程。
有关更多信息,请参考以下MSDocs。
英文:
It seems like your Azure Function is failing to process the message received from the ServiceBus and as a result, the same message is being delivered to the function again and again. There could be several reasons for this, such as issues with the APIs that you are calling or issues with the configuration of your Azure Function.
Steps to debug this issue:
-
Verify the response of the APIs that you are calling from your function.
-
The 302 response that you are seeing indicates a redirection response. This could be because the API endpoint that you are calling has been moved or is temporarily unavailable. Make sure that you are using the correct API endpoint and that it is available.
-
Check the logs of your Azure Function. You mentioned that you added a lot of logs, but they are not displayed in the local console. Make sure that you are using the correct logging configuration and that you are looking at the correct log stream. You can also try to use other logging frameworks like Serilog to log the details of the process.
Check the configuration of your Azure Function. It is possible that the function is timing out before it can complete the process.
You can try to increase the timeout value
of the Azure Function by modifying the functionTimeout
property in the host.json
file.
Check the ServiceBus configuration. It is possible that the message is not being properly acknowledged or processed by the Azure Function, causing it to be redelivered.
Use Azure Application Insights to monitor your Azure Function.
This helps you in identifying any performance issues, exceptions, or other problems that may be occurring in your function.
Thanks @Skin for the comments.
Attach the processes with Visual Studio debugger
.
Selecting the process to debug.
For more information, refer the below MSDocs.
Attach processes with the debugger
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论