在 fault/exception 完成发送调用后,Azure 服务总线是否会继续重试?

Will Azure Service Bus continue retry after the Send call is complete with a fault/exception?

下面是发送批量消息的代码,下面的代码块是创建服务总线客户端时重试策略的设置。 在测试涉及暂时性网络故障的场景时,我们看到发送任务出现故障的日志,但在服务总线中看到了分配给批处理消息的消息 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,
        };

您的代码可以简化为以下内容:

try
{
  await tempSender.SendMessagesAsync(batch);

  _logger.Log($"Sent batch of size {batch.Count}", EventLevel.LogAlways);

  onCompletionCallBack(messages);
}
catch (Exception exception)
{
  _logger.Log($"Service Bus Send Task Faulted for batch {batchId}", EventLevel.Error);
}

在所有重试次数都用完之前,Service Bus SDK 不会抛出异常。有可能消息已发送,但尚未收到确认,这将解释您正在观察的内容。

Secondary query - How do I log the internal retry attempts?

暂时性失败和重试不会直接出现在您的应用程序中。要观察它们,您需要 enable SDK logging.