Reputation: 86957
I'm trying to use the v12 SDK of Azure Queues.
When I create my queue instance, the first thing I'm doing on application startup is to see if the queue exists. Based on the typical documentation examples:
// Get the connection string from app settings
string connectionString = ConfigurationManager.AppSettings["storageConnectionString"];
// Instantiate a QueueClient which will be used to create and manipulate the queue
QueueClient queueClient = new QueueClient(connectionString, "myqueue");
// Create the queue
queueClient.CreateIfNotExists();
This is great .. but .. if the code cannot access the Queue storage (e.g. bad connection string / localhost storage emulator hasn't 100% started up yet, etc) .. then it hangs for a long time .. before my Polly code kicks in for it's "retry policy".
Questions:
Upvotes: 1
Views: 2188
Reputation: 136196
Is there a way to let the client fail/quit after 5 seconds instead of me having to wait 30 or 60 seconds (like that's some default setting, deep down).
Please try the code below. It's a bit convoluted approach to set the request timeout in the new SDK. In the code, I am forcing the request to timeout after 10ms and instructing the SDK to not retry the request (options.Retry.MaxRetries = 0;
)
static void Main(string[] args)
{
HttpClient httpClient = new HttpClient()
{
Timeout = TimeSpan.FromMilliseconds(10)
};
var transport = new HttpClientTransport(httpClient);
QueueClientOptions options = new QueueClientOptions()
{
Transport = transport,
};
options.Retry.MaxRetries = 0;
var queueClient = new QueueClient(connectionString, "test", options);
queueClient.CreateIfNotExists();
Console.WriteLine("Press any key to continue.");
Console.ReadKey();
}
Does the client auto-retry? If yes, this means I don't need my polly code...
Yes it does. Here's the default retry policy:
Upvotes: 3