Azure 角色和实例
我是否可以在同一个实例上运行 Web 角色和辅助角色,或者我是否必须获得 2 个单独的托管实例并支付两倍的费用?
我有一个 WCF Web API,我想将其托管在 Azure 上。我还有一个辅助角色,用于侦听 Azure 存储中的队列。每次将消息添加到队列时,它都会获取该消息并根据该消息运行一个小任务。
我想知道是否可以在同一个实例上运行这两个。
Can I have a Web Role and a Worker role run on the same instance, or do I have to obtain 2 separate hosting instances and pay twice the amount I would otherwise?
I have a WCF Web API that I want to host on Azure. I also have a Worker Role that listens to a Queue in Azure Storage. Every time a message is added to the Queue, it will obtain that and run a small task depending on the message.
I was wondering if I can just run these two on the same instance or not.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
“辅助角色”和“Web 角色”只是“运行 IIS 的 Windows Server 2008”和“不运行 IIS 的 Windows Server 2008”的简单模板。关键是“角色”是Windows Server虚拟机的定义。对于每个“角色”,您都有一个或多个实例。
在 Windows Azure 中,两种角色类型都能够在启动脚本或 OnStart() 处理程序中安装软件、修改注册表设置等,并且都允许您在 Run 中运行代码。 () 方法。
在您的情况下,您可以在 Web 角色中运行 WCF Web 服务,然后在您的 Run() 方法(在同一角色中)中启动一个进程,侦听您发布的队列消息。 WCF 网络服务。不需要有新的角色。
现在:一旦进入高容量情况,您可能希望将代码拆分为单独的角色,以便可以独立扩展它们(虚拟机大小和虚拟机数量)。
我在此处发布了关于此问题的另一个答案。
"Worker Role" and "Web Role" are just simple templates for "Windows Server 2008 with IIS running" and "Windows Server 2008 without IIS running." The key is that a "role" is a definition of a Windows Server virtual machine. For each "role" you have one or more instances.
In Windows Azure, both role types have the ability to install software, modify registry settings, etc. in either a startup script or
OnStart()
handler, and both let you run code in theRun()
method.In your case, you can run your WCF Web Service in a Web Role, and then in your
Run()
method (in the same role), kick off a process that listens to queue messages posted by your WCF web services. No need to have a new role.Now: Once you get into high-volume situations, you might want to split your code into separate roles, so you can scale them independently (both in VM size and VM quantity).
I posted another answer about this here.
这完全取决于您的要求。您只需拥有一个辅助角色,按照此处所述公开外部终结点并公开 WCF服务。您还可以拥有作为 WCF 服务的 Web 角色,并启动一个检查队列的后台线程。 Worker 正在对消息做什么?执行什么过程?这也对解决方案产生影响。
您需要考虑的一个关键问题是 WCF 服务和队列检索任务之间的扩展要求是否相同。如果他们是单一角色应该足够好开始。
It completely depends on your requirement. You can simply have a Worker Role that exposes an external endpoint as described here and expose a WCF Service. You can also have Web Role that is a WCF Service and spin up a background thread that checks the queue. What is the Worker doing with the message? What process is performed? That also has an impact on the solution.
A key thing you need to consider is whether the scaling requirement between your WCF Service and the queue retrieving tasks are the same. If they are a single role should be good enough to start with.