Laser queue storage in 2015?

What is the proper invocation / code to write to Azure Queue store in my own way?

Currently the pseudocode

Create a static class with your own StorageCredentials and CloudStorage resources. When starting the application, read the values ​​from the configuration file into the {get;} - only properties.

Create class using async Task method with input parameter of my application message type. The method serializes the type, creates a new CloudQueueMessage, a new CloudQueueClient, a new CloudQueue reference. If configuration information is required, it is read from the static class. Then my code:

await Task.Run( ()=> theref.AddMessage(themessage).

      

It seems to me that I have redundancy in the code and I am not sure what and how connections can be queued and also if I need retry logic as I would like with a database connection (SQL Server, etc. .).

I am trying to understand what steps of accessing a queue can be reduced or optimized in some way.

Any ideas are appreciated.

Using .NET 4.5.2, C #. The code runs in the cloud service (worker role).

Thank.

+3


source to share


2 answers


  • Azure Storage Client Library already repeats you by default in case of service / network errors. It will retry up to 3 times per operation.
  • You can change your call to await theref.AddMessageAsync(themessage)

    instead of blocking the synchronous call AddMessage

    on a separate thread.
  • Starting with the latest library, you can reuse the object CloudQueueClient

    to get a new reference to CloudQueue

    .
  • As long as you call AddMessageAsync

    sequentially, the same connection will be reused whenever possible. If you call it at the same time, more connections will be created, right down to ServicePointManager.DefaultConnectionLimit

    connections. So, if you want concurrent access to the queue, you can increase this number.
  • Disabling the Nagle algorithm via is ServicePointManager.UseNagleAlgorithm

    also recommended given the size of the messages in the queue.


+5


source


I would cache your CloudQueue link and reuse it. Every time you add a message to the queue, this class makes a REST call using the HttpClient. Since your credentials and memory / queue Uri are already known, this can save a few cycles.

Also, it is recommended to use AddMessageAsync instead of AddMessage.



As a reference, you can see the implementation in the repository client libraries here .

+2


source







All Articles