简体   繁体   English

在Owin Startup类中使用OnMessage订阅Azure Service Bus

[英]Subscribing to Azure Service Bus using OnMessage in Owin Startup class

I am working on a solution which will process messages from Azure Service Bus, my colleague suggested to use one of our existing Asp.Net WebApi App and subscribe to ASB in OWIN Startup eg 我正在开发一个解决方案来处理来自Azure Service Bus的消息,我的同事建议使用我们现有的Asp.Net WebApi应用程序并在OWIN Startup中订阅ASB,例如

public class Startup
{
    public void Configuration(IAppBuilder app)
    {
        // ... registering WebApi etc

        var queueClient = SubscriptionClient.CreateFromConnectionString("connection string", "sometopic", "somesubscription");

        queueClient.OnMessage(m =>
        {
            //do something with message

            m.Complete();
        }, new OnMessageOptions
        {
            AutoComplete = false,
            AutoRenewTimeout = TimeSpan.FromSeconds(30),
            MaxConcurrentCalls = 30
        });
    }
}

I personally think that this is not right way to do it and instead we should use WebJobs or WorkerRoles , hovewer I can't think of any arguments to convince him to my idea. 我个人认为这不是正确的方法,而是我们应该使用WebJobsWorkerRoles ,我想不出任何让他说服我的想法的论据。

So the questions is: 所以问题是:

  1. Who is right, me or my colleague, or maybe both solutions are ok ? 谁是对的,我或我的同事,或者两种解决方案都可以吗?
  2. In case if my colleague is not right what are the arguments against his solution ? 如果我的同事不对,反对他的解决方案的理由是什么?

If that web api project does more than just listening to this queue consider these advantages of using the web job or worker role approach: 如果该web api项目不只是监听此队列,请考虑使用Web作业或辅助角色方法的这些优点:

  • Worker role can scale independently of the web app 工作者角色可以独立于Web应用程序进行扩展
  • A web job / worker role can be updated independently of the web app 可以独立于Web应用程序更新Web作业/辅助角色
  • Process isolation: if one fails the other might still run. 进程隔离:如果一个失败,另一个可能仍然运行。

If you use Azure Functions ( https://azure.microsoft.com/en-us/services/functions/ ) you can even apply serverless computing. 如果您使用Azure功能( https://azure.microsoft.com/en-us/services/functions/ ),您甚至可以应用无服务器计算。 You pay only for the usage (not for the hosting of your function), and scales and can be updated independently as well. 您只需支付使用费用(不用于托管您的功能)和比例,也可以单独更新。

Technically both approaches will work. 从技术上讲,两种方法都可行。 If the processing of the messages has interaction with the web app directly (you did not tell what you do with the messages) it might make more sense to run it in the web app depending of the work. 如果消息的处理直接与Web应用程序交互(您没有告诉您对消息做了什么),那么根据工作在Web应用程序中运行它可能更有意义。

A web site is better in handling requests instead of running a continuous process. 网站更好地处理请求而不是运行连续过程。 A web job / worker role feels like a better environment for these kind of situations but also really take a look at Azure Functions. Web作业/工作者角色对于这种情况来说感觉就像是一个更好的环境,但也真正看看Azure功能。

One of the reasons that the Service Bus existed is to process this messages/queue in isolation as this particular process was identified to be a subsystem or subdomain of the bigger enterprise system. 服务总线存在的原因之一是单独处理此消息/队列,因为此特定进程被识别为较大企业系统的子系统或子域。 Therefore an app/service (in form of web worker roles/web jobs/azure functions) can be developed by same or different team that has focus domain knowledge of the subsystem. 因此,app / service(以web worker角色/ web作业/ azure函数的形式)可以由具有子系统的焦点领域知识的相同或不同团队开发。 Since it is an independent process it can be scaled independently if the need requires it. 由于它是一个独立的过程,因此可以根据需要独立扩展。

If the processing of the messages has dependency on the web app business logic/services, that can be a red flag as to why it needs to be in the Web API process. 如果消息的处理依赖于Web应用程序业务逻辑/服务,则可能是一个红旗,表明它为什么需要在Web API过程中。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM