简体   繁体   English

同时管理多个Azure Service Bus队列

[英]Managing multiple Azure Service Bus Queues concurrently

I'm using an Azure environment and developing in .NET 我正在使用Azure环境并在.NET中进行开发

I am running a web app (ClientApp) that takes client data to perform a series of calculations. 我正在运行一个Web应用程序(ClientApp),该应用程序将使用客户端数据来执行一系列计算。 The calculations are performance intensive, so they are running on a separate web app (CalcApp). 计算需要大量的性能,因此它们在单独的Web应用程序(CalcApp)上运行。

Currently, the ClientApp sends the calculation request to the CalcApp. 当前,ClientApp将计算请求发送到CalcApp。 The requests from every client are put into a common queue and run one at a time, FIFO. 来自每个客户端的请求被放入一个公共队列,并一次运行一个FIFO。 My goal is to create separate queues for each client and run several calculations concurrently. 我的目标是为每个客户端创建单独的队列,并同时运行多个计算。

I am thinking of using the Azure Service Bus queues to accomplish this. 我正在考虑使用Azure Service Bus队列来完成此任务。 On the ClientApp, the service bus would check for an existing queue for that client and create one if needed. 在ClientApp上,服务总线将检查该客户端的现有队列,并在需要时创建一个队列。 On the CalcApp, the app would periodically check for existing queues. 在CalcApp上,该应用程序将定期检查现有队列。 If it finds a new queue, then it would create a new QueueClient that uses OnMessageAsync() and RunCalculationsAsync() as the callback function. 如果找到新队列,则将创建一个使用OnMessageAsync()和RunCalculationsAsync()作为回调函数的新QueueClient。

Is this feasible or even a good idea? 这可行甚至是个好主意吗?

I would consider using multiple consumers instead, perhaps with a topic denoting the "client" if you need to differentiate the type of processing based on which client originated it. 我将考虑使用多个使用者,如果您需要根据哪个客户端发起处理来区分处理类型,则可能会使用一个表示“客户端”的主题。 Each client can add an entry into the queue, and the consumers "fight" over the messages. 每个客户端都可以将一个条目添加到队列中,并且消费者可以“争夺”消息。 There is no chance of the same message being processed twice if you follow this approach. 如果您采用这种方法,则相同的消息将不会被处理两次。

I'm not sure having multiple queues is necessary. 我不确定是否需要多个队列。

Here is more information on the Competing Consumers pattern. 这是有关“竞争消费者”模式的更多信息。
https://msdn.microsoft.com/en-us/library/dn568101.aspx https://msdn.microsoft.com/zh-CN/library/dn568101.aspx

You could also build one consumer and spawn multiple threads. 您还可以建立一个使用者并产生多个线程。 In this model, you would have one queue and one consumer, but still have the ability to calculate more than one at a time. 在此模型中,您将只有一个队列和一个使用者,但是仍然能够一次计算多个。 Ultimately, though, competing consumers is far more scalable, using a combination of both strategies. 最终,尽管如此,使用两种策略的组合,竞争消费者的可扩展性要大得多。

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

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