[英]Azure Functions Event Hub binding retry
我有一個帶有輸出綁定的HTTP觸發函數,其中使用IAsyncCollector<string> outputEventHubMessages
outputEventHubMessages.AddAsync("message")
將消息發送到事件中心。
如果由於某種原因,事件中心發生中斷/故障並且不接受消息,Azure功能會重試發送嗎?
謝謝。
據我所知,如果另一個輸出綁定無法完成其工作(例如,連接到事件中心),則HTTP綁定將向您返回500。 它不會重試該操作。 這是響應正文的示例:
{
"id": "112a4e4f-2c6b-4b43-85a6-a8d801ca6f23",
"requestId": "0c0514e3-27dc-476f-8a85-3c8fe77aa762",
"statusCode": 500,
"errorCode": 0,
"message": "Exception while executing function: Functions.SoFunc -> Error while handling parameter outputEventHubMessage after function returned: -> Put token failed. status-code: 404, status-description: The messaging entity 'sb://tmdevmike.servicebus.windows.net/outeventhub' could not be found.."
}
我不能引用任何官方文檔。
最好在輸出綁定中內置此功能。 但是,以下代碼段顯示了向事件中心重試消息的示例。 該概念基於捕獲輸出綁定上的錯誤並將消息發送到存儲隊列以重試過程:
[FunctionName("Function4")]
public static async Task<HttpResponseMessage> Run(
[HttpTrigger(AuthorizationLevel.Function, "post")] HttpRequestMessage req,
[EventHub("%EventHub%", Connection = "connectionEventHub")] IAsyncCollector<string> outputEventHubMessages,
[Queue("%RetryQueue%")] IAsyncCollector<string> outputQueueRetryMessages,
TraceWriter log)
{
log.Info("C# HTTP trigger function processed a request.");
// Get request body
string message = JsonConvert.SerializeObject(JObject.Parse(await req.Content.ReadAsStringAsync()));
try
{
await outputEventHubMessages.AddAsync(message);
await outputEventHubMessages.FlushAsync();
}
catch(Exception ex)
{
log.Error(ex.Message);
//await Task.Delay(5000);
await outputQueueRetryMessages.AddAsync(message);
}
return req.CreateResponse(HttpStatusCode.OK);
}
可以在host.json文件中配置隊列:
{
"queues": {
"maxDequeueCount": 3,
"visibilityTimeout": "00:00:30"
}
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.