0

我正在使用带有 ASP.Net MVC 2 C# 的 Azure 开发 MVC webapp。我有一个工作角色,我在其中与队列交互,阅读带有图像的消息。我在我的 WebRole 中初始化了队列,并且我想调用一个方法来将我的控制器中的元素排入队列。我不知道怎么打这个电话。

谢谢!

4

1 回答 1

2

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.

于 2010-11-28T14:15:47.153 回答