Quick AzureQueueManager
using Microsoft.WindowsAzure;
using Microsoft.WindowsAzure.StorageClient;
using Microsoft.WindowsAzure.ServiceRuntime;
public enum QueueNameCategory
{
UnSpecified = 0,
A= 1,
B= 2,
C= 3,
D= 4,
E= 5
}
public class AzureQueueManager
{
private static Dictionary<QueueNameCategory, CloudQueue> _queueLookUp = new Dictionary<QueueNameCategory,CloudQueue>();
private static CloudQueueClient _queueClient = null;
private static CloudStorageAccount _cloudStorageAccount = null;
private static bool _initialized = false;
static AzureQueueManager()
{
try
{
_cloudStorageAccount = CloudStorageAccount.Parse("XYZ");
_queueClient = _cloudStorageAccount.CreateCloudQueueClient();
CloudQueue queue = _queueClient.GetQueueReference("queue1");
queue.CreateIfNotExist();
_queueLookUp.Add(QueueNameCategory.A, queue);
queue = _queueClient.GetQueueReference("queue2");
queue.CreateIfNotExist();
_queueLookUp.Add(QueueNameCategory.B, queue);
queue = _queueClient.GetQueueReference("queue3");
queue.CreateIfNotExist();
_queueLookUp.Add(QueueNameCategory.C, queue);
queue = _queueClient.GetQueueReference("queue4");
queue.CreateIfNotExist();
_queueLookUp.Add(QueueNameCategory.D, queue);
queue = _queueClient.GetQueueReference("queue5");
queue.CreateIfNotExist();
_queueLookUp.Add(QueueNameCategory.E, queue);
_initialized = true;
}
catch (Exception ex)
{
_initialized = false;
YourLogger.Log(ex);
}
}
public static bool Initialized
{
get { return AzureQueueManager._initialized; }
}
public static Dictionary<QueueNameCategory, CloudQueue> QueueLookUp
{
get { return AzureQueueManager._queueLookUp; }
}
}
Comments
Post a Comment