[英]Azure Service Bus Retry Policy doesn't change the behavior
我正在嘗試了解Azure Service Bus上的重試策略,但是它沒有按我期望的方式工作。 我有以下代碼,它們既偵聽消息,又將消息發送到特定的天藍色隊列。
using System;
using Microsoft.ServiceBus;
using Microsoft.ServiceBus.Messaging;
namespace ServiceBusTester
{
class Program
{
static void Main(string[] args)
{
var connectionString = "Endpoint=sb://<NamespaceName>.servicebus.windows.net/;SharedAccessKeyName=RootManageSharedAccessKey;SharedAccessKey=<SharedAccessKey>";
var queueName = "MyTestQueue";
var retryPolicy = new RetryExponential(TimeSpan.FromSeconds(0), TimeSpan.FromSeconds(30), 15);
var ns = NamespaceManager.CreateFromConnectionString(connectionString);
ns.Settings.RetryPolicy = retryPolicy;
if (!ns.QueueExists(queueName))
ns.CreateQueue(queueName);
var mf = MessagingFactory.CreateFromConnectionString(connectionString);
mf.RetryPolicy = retryPolicy;
var mr = mf.CreateMessageReceiver(queueName);
mr.RetryPolicy = retryPolicy;
var retryCount = 0;
mr.OnMessage(_ =>
{
retryCount++;
Console.WriteLine($"{retryCount.ToString().PadLeft(4, ' ')} - Message Received: {_.GetBody<string>()}");
_.Abandon();
}, new OnMessageOptions() { AutoComplete = true });
var client = QueueClient.CreateFromConnectionString(connectionString, queueName);
client.RetryPolicy = retryPolicy;
var message = new BrokeredMessage("This is a test message!");
client.Send(message);
Console.WriteLine("Press any key to exit...");
Console.ReadKey();
}
}
}
即使我指定重試策略應重試15次,但我仍然看到它僅重試默認值10次。 我什至嘗試使用NoRetry策略,但仍重試10次。
我還驗證了隊列上的“ Maximum Delivery Count
”被設置為任意大的數字,但這沒有任何改變:
我確定我將重試策略分配給眾多不同的客戶/工廠的做法過分,但是我不確定這里出了什么問題。
當存在瞬態錯誤沒有立即出現在您的代碼中時,ASB客戶端將使用RetryExponential
。 即客戶端內置的內部重試機制,可以在引發異常之前代表您執行重試。 如果沒有異常, 並且您的回調顯式放棄了該消息,則此處甚至不使用重試策略,並且該消息僅經過正常傳遞,直到MaxDeliveryCount
次(在您的方案中為50次),之后是DLQed。
使用重試策略向ASB客戶端指定在放棄之前如何處理瞬態錯誤,而不是消息可以出隊多少次。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.