NServiceBus PubSub - 如何打破 pub'r 和 sub'r 之间的二进制依赖关系?

发布于 2024-11-09 14:46:18 字数 663 浏览 5 评论 0原文

我需要构建一个 NSB 订阅者,它将订阅由已上线的服务发布的消息。该服务是使用包含我想要订阅的 NSB IMessage 实现的消息程序集构建的。因此,为了构建我的订阅者,我需要对该程序集的严格依赖。

当我的订阅者启动时,它会向发布者输入队列发送一些消息,这会导致发布者在数据库中记录我的订阅。我的订阅之一如下所示:

MyNamespace.MyMessageType, MyNamespace, Version=1.0.0.0, Culture=neutral, PublicKeyToken=MyPublicKeyToken

不幸的是,发布者正在从名称不强的程序集发布消息。因此,在发布时,订阅评估过程无法根据我的订阅成功评估,因为正在发布的消息的公钥令牌(值 = null)与我的订阅不匹配。

我的问题是:我可以不只按类型和版本订阅消息吗?更好的是 - 我可以不订阅基于某些外部合约(如 XSD)的消息并完全打破这种依赖关系吗?

非常感谢。

更新:NSB 文档在这里暗示了类似的内容:

http://www.nservicebus.com/MessagesAsInterfaces.aspx

I have a requirement to build a NSB subscriber which will subscribe to messages being published by a service which is already live. This service was built with a messages assembly containing the NSB IMessage implementations which I want to subscribe to. So to build my subscriber I need a hard dependency on this assembly.

When my subscriber starts up it sends some messages to the publisher input queue which results in the publisher recording my subscriptions in the database. One of my subscriptions looks like this:

MyNamespace.MyMessageType, MyNamespace, Version=1.0.0.0, Culture=neutral, PublicKeyToken=MyPublicKeyToken

Unfortunately the publisher is publishing messages from an assembly which is not strong named. So when publishing, the subscription evaluation process fails to evaluate successfully against my subscription, because the public key token of the message being published (value = null) does not match my subscription.

My question is: Can I not subscribe to messages by Type and version only? Even better - can I not subscribe to messages based on some external contract (like an XSD) and break this dependency altogether?

Many thanks in advance.

UPDATE: The NSB docs hint at something like this here:

http://www.nservicebus.com/MessagesAsInterfaces.aspx

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

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

发布评论

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

评论(1

终难遇 2024-11-16 14:46:18

对于您创建的常规消息,您可以使用 NSB 工具目录中的 XsdGenerator 工具来生成可传递到其他端点的架构。您将需要使用此工具而不是 .NET Framework 工具,因为它不支持接口。从那里您可以使用架构来处理消息。

对于订阅消息,如果您不想使用程序集,您可以告诉 NSB DoNotAutoSubscribe() 并手动订阅(Bus.Subscribe(Type)),并根据需要传递消息的类型。这可能与架构或某些其他配置无关。

For regular messages you create you can use the XsdGenerator tool in the tools directory of NSB to generate a schema that you can pass along to other endpoints. You will want to use this tool instead of the .NET Framework tool as it does not support interfaces. From there you can use the schema to handle messages.

For subscription messages, if you don't want to use the assembly you could tell NSB to DoNotAutoSubscribe() and subscribe manually(Bus.Subscribe(Type)) passing along the Type of the message however you wish. This could be off the schema or some other configuration.

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