Azure: How to call a WebRole method from a controller of my MVC implementation
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 开发者_JAVA百科I want to call a method to enqueue elements from my controller. I don't know how to do this call.
Thanks!
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.
精彩评论