NService Bus - 基于内容的路由和服务审计——我的方法可以吗?
在我们的系统中设计消息流时,我在决定采用哪种方式时遇到了一些困难。
由于我们的业务流程(即计算运费)的波动性,我们使用工作流程框架来动态更改流程。
一般流程应如下所示
该接口是一种服务,通过客户提供的任何接口(Web 服务、TCP 端点、数据库轮询、文件,等等)连接到客户系统。然后,命令被发送到执行器,其中包含接收到的数据和要执行的工作流的 id。
第一个问题出现在我们想要在多个工作服务上分配负载的时候。
假设我们有不同的流程,例如打印包裹标签、计算价格、发送通知邮件。打印标签永远不应该因为执行大量的邮件工作流程而延迟。因此,我们希望能够根据不同的工作人员所做的工作将命令发送给他们。
因为所有命令都类似于“执行工作流 XY”,所以我们需要实现我们自己的基于内容的路由。 NServicebus 不支持这种开箱即用的方式,大多数时候是因为它是一种反模式。
当您无法使用不同的消息类型来路由消息时,是否有更好的方法来做到这一点?
第二个问题出现在我们想要添加监控时。由于端点只能为每种消息类型订阅一个队列,因此我们不能让所有执行器只发布“我完成了工作流程”消息。当前的解决方案是将消息Bus.Send
发送到预先配置的审核端点。这对我来说有点像作弊;)
有没有更好的方法可以将多个工作人员的已发布消息再次合并到一个队列中?如果不会出现问题#1,我认为所有工作人员都可以使用相同的输入队列,但在这种情况下这是不可能的。
I have a little trouble deciding which way to go for while designing the message flow in our system.
Because the volatile nature of our business processes (i.e. calculating freight costs) we use a workflow framework to be able to change the process on the fly.
The general process should look something like this
The interface is a service which connects to the customers system via whatever interface the customer provides (webservices, tcp endpoints, database polling, files, you name it). Then a command is sent to the executor containing the received data and the id of the workflow to be executed.
The first problem comes at the point where we want to distribute load on multiple worker services.
Say we have different processes like printing parcel labels, calculating prices, sending notification mails. Printing the labels should never be delayed because a ton of mailing workflows is executed. So we want to be able to route commands to different workers based on the work they do.
Because all commands are like "execute workflow XY" we would be required to implement our own content based routing. NServicebus does not support this out of the box, most times because it's an anti pattern.
Is there a better way to do this, when you are not able to use different message types to route your messages?
The second problem comes when we want to add a monitoring. Because an endpoint can only subscribe to one queue for each message type we can not let all executors just publish a "I completed a workflow" message. The current solution would be to Bus.Send
the message to a pre configured auditing endpoint. This feels a little like cheating to me ;)
Is there a better way to consolidate published messages of multiple workers into one queue again? If there would not be problem #1 I think all workers could use the same input queue however this is not possible in this scenario.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以尝试使您的路由不基于内容,而是基于标头,这应该更容易。您不感兴趣工作流程是否打印标签,您感兴趣的是该命令是否优先。因此,您可以将此信息添加到邮件标头中......
You can try to make your routing not content-based, but headers-based which should be much easier. You are not interested if the workflow is to print labels or not, you are interested in whether this command is priority or not. So you can probably add this information into the message header...