NServiceBus Distributor - 如何拆分应用程序 [英] NServiceBus Distributor - How to split application

查看:46
本文介绍了NServiceBus Distributor - 如何拆分应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们有 1 个服务,它从数据库中选择 som id,然后按顺序使用一些业务逻辑处理它们.我们希望横向扩展并并行执行的处理,而不会创建大量内部线程.

We have 1 service which selects som id's from the database and then processes them with some buisness logic in sequence. The processing we would like to scale out and do in parallel, without creating a lot of internal threads.

我的问题是:

如果我想使用 Distributor 进行横向扩展,应该怎么做以及如何做?

If I want to use the Distributor to scale out, how should and how can I do it?

解决方案 1:服务一分为二:

  1. 原始服务被修改为仅从数据库中选择 ID,然后将它们发送给工作人员.这将是分发服务器 (RunDistributorWithNoWorkerOnItsEndpoint).
  2. 一个新的服务,它将保存业务逻辑并作为一个工作器运行,处理每个传入的 ID.如果我想要更多的工人,我只需多次启动相同的过程.

解决方案 2:服务分为3个:

  1. 原始服务被修改为仅从数据库中选择 ID,然后将它们发送给分销商.
  2. 一个新的服务,分发器 (RunDistributorWithNoWorkerOnItsEndpoint),它只处理工作器的负载平衡.
  3. 一个新的服务,worker(s),它将保存业务逻辑并处理每个传入的 id.

解决方案 3:服务一分为二:

  1. 原来的服务被修改为只从数据库中选择id然后发送.作为发件人运行.
  2. 一个新的服务,它将持有业务逻辑并作为一个工人和一个分发者,处理每个传入的 ID 或分发它们.
  1. The original service is modified to only select the ids from the database and then send them. Running as a sender.
  2. A new service which will hold the buisness logic and function as a worker and a distributor, processing every incomming id or distributing them.

解决方案 1 对我来说很有意义,但使用它意味着以某种方式分销商将有 2 个责任:

Solution 1 makes a lot of sense to me, but using it would mean that somehow the distributor would have 2 responsabilities:

  1. 选择 ID.
  2. 将 ID 分发给工作人员.

但是当我查看 NSB 文档中的 ScaleOut 示例时,我不确定这是否可能,甚至是反模式.

But im not sure if this is possible or maybe even an antipattern, when I look at the ScaleOut example from the NSB documentation.

在再次阅读文档和 ScaleOut 示例后,我认为我应该采用解决方案 3,但我还不太确定.

Solution 3 is what I believe I should go for, after reading the docs and the ScaleOut example againg but im not quite sure yet.

我试图通过与 NSB 分销商进行横向扩展来解决管道问题,我更愿意自己托管,而不是使用 NServiceBus.Host.exe,但这不是严格要求.

Im trying to solve a plumbing issue by scaling out with the NSB distributor and I would prefer to do my own hosting, not using the NServiceBus.Host.exe, but this is not a strict requirement.

我最终使用了解决方案 3,因为它的优点是(在我看来)配置队列的任务比解决方案 2 中的要小,如果您使用默认的队列命名.

I ended up using solution 3 as it has the advantage (in my opinion) that the task of configuring queues is smaller than in solution 2, if you are use the default queue naming.

亲切的问候

推荐答案

我们在过去的版本中使用解决方案 2 完成了此操作.原因是我们使 Distributor 站起来并且高度可用.将来我们很可能会让分发服务器做一些工作,否则它只会相对闲置.这个解决方案对我们很有帮助.

We've done this in the past versions using solution 2. The reason being is that we made the Distributor stand along and highly available. In the future we'll most likely let the Distributor do some of the work as otherwise it will just be sitting relatively idle. This solution has served us pretty well.

这篇关于NServiceBus Distributor - 如何拆分应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆