Reputation: 23
I'm working on a MVC webapp using Azure with ASP.Net MVC 2 C#. I have a worker role from where I interact with a queue reading messages with images. I initialize the queue in my WebRole, and I want to call a method to enqueue elements from my controller. I don't know how to do this call.
Thanks!
Upvotes: 0
Views: 515
Reputation: 71055
Adding to the queue is straightforward:
var queueClient = CloudStorageAccount.FromConfigurationSetting("mystorage").CreateCloudQueueClient();
var myQueue = queueClient.GetQueueReference("myqueue");
string myMessageContent = "Some formatted queue message"; // this could be bytes as well
var myQueueMessage = new CloudQueueMessage(myMessageContent);
myQueue.AddMessage(myQueueMessage);
One bit of advice: When creating the queue, do it in your role's OnStart(), not in the Run(). This way, it'll be created before your web app ever shows up in the Azure load balancer.
Upvotes: 2