Azure:如何从 MVC 实现的控制器调用 WebRole 方法

发布于 2024-10-05 00:37:26 字数 151 浏览 0 评论 0原文

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

谢谢!

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!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

不必你懂 2024-10-12 00:37:26

添加到队列很简单:

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);

一点建议:创建队列时,在您的角色的 OnStart() 中执行此操作,而不是在 Run() 中执行。这样,它将在您的 Web 应用程序出现在 Azure 负载均衡器中之前创建。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文