NServiceBus消息类型和思维过程

发布于 2024-12-17 22:52:27 字数 687 浏览 3 评论 0原文

在我们的场景中,我正在考虑使用 pub sub 技术。但我不知道哪个是更好的选择。

1 ########

我们的一个Web服务,在外部调用的时候,会发布一条发生了事情的消息,ExternalPersonCreatedMessage!

该消息将包含一个字段,该字段表示将消息处理到的目的地(允许多个)。

各种订阅者都会订阅。这些订阅者将通过检查目标字段来过滤消息,以查看是否需要执行任何操作。

2 ########

我们的 Web 服务将解析传入呼叫并根据字段中提供的目的地发布特定类型的消息。即会创建许多 Destination[n]PersonCreatedMessage 消息。

订阅者将仅订阅他们关心的特定消息。即不必过滤任何消息

问题

以上哪一个是更好的选择,为什么?我该如何阻止自己发出 RequestMessages。从我读过/看到的内容来看,我应该尝试以 PersonCreated、PersonDeleted 的方式来构建它,即在“请求某事发生”表单中发生了一些事情,并且没有,例如 CreatePerson 或 DeletePerson

是我的想法正确的?我一直在寻找有关如何构建消息并确保我不会走上错误道路的指导,但没有找到关于该做什么和不该做什么的指导。任何人都可以提供帮助和指导吗?我想尝试从一开始就正确地做到这一点:)

In our scenario I'm thinking of using the pub sub technique. However I don't know which is the better option.

1 ########

A web service of ours will publish a message that something has happened when it is called externally, ExternalPersonCreatedMessage!

This message will contain a field that represents the destinations to process the message into (multiple allowed).

Various subscribers will subscribe. These subscribers will filter the message to see if any action is required by checking the destination field.

2 ########

A web service of ours will parse the incoming call and publish specific types of messages depending on the destinations supplied in the field. i.e. many Destination[n]PersonCreatedMessage messages would be created.

Subscribers will subscribe to only the specific message they care for. i.e. not having to filter any messages

QUESTIONS

Which of the above is the better option and why? And how do I stop myself from making RequestMessages. From what I've read/seen I should be trying to structure this in a way of PersonCreated, PersonDeleted i.e. SOMETHING HAS HAPPENED and NOT in the REQUEST SOMETHING TO HAPPEN form such as CreatePerson or DeletePerson

Are my thoughts correct? I've been looking for guidance on how to structure messages and making sure I don't go down a wrong path but have found no guidance out there on do's and dont's. Can any one help and guide? I want to try and get this correct from the off :)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

ま昔日黯然 2024-12-24 22:52:27

根据参考文章中的集成场景,在我看来,您可能需要一个 Saga 来完成接受消息 -> 的工作流程。对消息进行操作->发送确认。在操作后立即发送确认的情况下,您可以使用 NSB 消息处理程序管道功能,该功能允许您按指定顺序链接处理程序,例如...

First<FilterHandler>.Then<DoWorkHandler>().AndThen<SendConfirmationHandler>();

在内容过滤方面,您可以执行此操作,尽管您会产生一些传输开销,这意味着队列必须接受消息,并且进程将始终调用每条消息的第一个处理程序(您可以随时短路上述管道)。可能的情况是,您真正想要的是一个分发者/工作人员设置,其中所有工作人员都是相同的,并且您可以处理一些负载。

如果您确实有具有完全不同逻辑的不同端点,那么我会让发布者进程(仅接受和发布消息)完成将入站消息转换为订阅者可以感兴趣的其他内容的工作。如果您发现给定的 Published 消息只有 1 个订阅者,那么您根本不需要 Publish,您只需 Bus.Send() 到正确的端点。

Based on the integration scenario in the referenced article, it appears to me that you may need a Saga to complete the workflow of accept message -> operate on message -> send confirmation. In the case that the confirmation is sent immediately after the operation, you could use NSBs message handler pipeline feature which allows you to chain handlers in a specified sequence such as...

First<FilterHandler>.Then<DoWorkHandler>().AndThen<SendConfirmationHandler>();

In terms of the content filtering, you can do this although you incur some transport overhead, meaning the queue will have to accept the message and the process will always call the first handler on every message(you can short-circuit the above pipeline at any point). It may be the case that what you really want is a Distributor/Worker setup where all Workers are the same and you can handle some load.

If you truly have different endpoints with completely different logic, then I would have the Publisher process(only accepts and Publishes message) do the work of translating the inbound message to something else a Subscriber can then be interested in. If then you find that a given Published message only ever has 1 Subscriber, then you don't need to Publish at all, you need to just Bus.Send() to the correct endpoint.

动听の歌 2024-12-24 22:52:27

NServiceBus 处理发布-订阅的方式更像是您的选项二。

  1. 发布者服务具有输入队列和订阅存储。
  2. 订阅者服务有一个输入队列
  3. 订阅者在启动时会向发布者的输入队列发送订阅消息
  4. 订阅消息包含订阅者感兴趣的消息类型和订阅者队列地址
  5. 发布者将订阅记录在订阅商店。
  6. 发布者收到一条消息。
  7. 发布者根据订阅列表评估消息类型
  8. 对于找到的每个匹配项,发布者将消息发送到队列地址。

在我看来,你应该停止考虑目的地。消息就是消息。它们不应包含任何固有的目的地信息。订阅机制定义了解决方案的寻址/路由要求。

The way NServiceBus handles pub-sub is more like your option two.

  1. A publisher service has an input queue and a subscription store.
  2. A subscriber service has an input queue
  3. The subscriber, on start-up will send a subscription message to the input queue of the publisher
  4. The subscription message contains the type of message subscriber is interested in and the subscribers queue address
  5. The publisher records the subscription in the subscription store.
  6. The publisher receives a message.
  7. The publisher evaluates the message type against the list of subscriptions
  8. For each match found the publisher sends the message to the queue address.

In my opinion, you should stop thinking about destinations. Messages are messages. They should not have any inherent destination information in them. The subscription mechanism defines the addressing/routing requirements for the solution.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文