Send 调用完成后出现故障/异常,Azure 服务总线是否会继续重试?
下面是批量发送消息的代码,下面的代码块是创建服务总线客户端时重试策略的设置。 在测试涉及瞬时网络故障的场景时,我们看到日志显示发送任务出现故障,但在服务总线中看到了分配给该批次消息的消息 ID 的消息。是否有可能即使进入故障后,重试仍然在后台发生?据我了解,只有在SDK完成重试过程后才会发生该故障。这是正确的吗?
辅助查询 - 如何记录内部重试尝试?
//Code for sending. Uses Azure.Messaging.ServiceBus
await tempSender.SendMessagesAsync(batch).ContinueWith(async (tStat) =>
{
if (tStat.IsFaulted || tStat.IsCanceled)
{
_logger.Log($"Service Bus Send Task Faulted for batch {batchId}", EventLevel.Error);
}
else
{
_logger.Log($"Sent batch of size {batch.Count}", EventLevel.LogAlways);
onCompletionCallBack(messages);
}
});
//Retry policy
protected ServiceBusRetryOptions GetRetryPolicy() => new ServiceBusRetryOptions()
{
Delay = TimeSpan.FromSeconds(0.1),
MaxDelay = TimeSpan.FromSeconds(30),
MaxRetries = 5,
Mode = ServiceBusRetryMode.Exponential,
};
The following is the code for sending batched messages and the code block following is the setting for retry policy while creating the service bus client.
While testing a scenario involving transient network fault, we see the log that the send task was faulted but the messages were seen in the service bus for the message-id that were assigned to the messages of the batch. Is it possible that the retry kept happening in the background even after entering the fault? I am of the understanding that the fault will happen only AFTER the retry procedures are completed by the SDK. Is that correct?
Secondary query - How do I log the internal retry attempts?
//Code for sending. Uses Azure.Messaging.ServiceBus
await tempSender.SendMessagesAsync(batch).ContinueWith(async (tStat) =>
{
if (tStat.IsFaulted || tStat.IsCanceled)
{
_logger.Log(quot;Service Bus Send Task Faulted for batch {batchId}", EventLevel.Error);
}
else
{
_logger.Log(quot;Sent batch of size {batch.Count}", EventLevel.LogAlways);
onCompletionCallBack(messages);
}
});
//Retry policy
protected ServiceBusRetryOptions GetRetryPolicy() => new ServiceBusRetryOptions()
{
Delay = TimeSpan.FromSeconds(0.1),
MaxDelay = TimeSpan.FromSeconds(30),
MaxRetries = 5,
Mode = ServiceBusRetryMode.Exponential,
};
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您的代码可以简化为以下内容:
在所有重试都用尽之前,Service Bus SDK 不会引发异常。有可能消息已发送,但尚未收到确认,这将解释您所观察到的情况。
Your code could be simplified to the following:
Service Bus SDK will not throw an exception until all retries are exhausted. There's a chance that the messages have been dispatched, but the acknowledgement hasn't been received, which will explain what you're observing.
瞬时失败和重试尝试不会直接显示在您的应用程序中。要观察它们,您需要 启用 SDK 日志记录。
Transient failures and retry attempts are not directly surfaced to your application. To observe them, you would need to enable SDK logging.