如何以编程方式将映射添加到 UnicastBusConfig?
我希望能够在运行时向我的应用程序添加对可能位于不同服务器上的其他消息类型的订阅。我想要实现的是一个监控应用程序,我可以在运行时添加/删除订阅。这可能吗?如何获取当前 UnicastBus 映射的引用?
这是我到目前为止正在做的事情,但我相信这将覆盖当前存在的任何映射。
MessageEndpointMappingCollection mappings = new MessageEndpointMappingCollection();
mappings.Add(new MessageEndpointMapping()
{
Messages = m.MessageType.ToString(),
Endpoint = m.QueueName
});
IComponentConfig<UnicastBusConfig> busConfig = config.Configurer.ConfigureComponent<UnicastBusConfig>(ComponentCallModelEnum.None);
busConfig.ConfigureProperty(u => u.MessageEndpointMappings, mappings);
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
Yves 在他的 Azure 示例中使用了此代码(可在 NSB 示例集合中找到)
Yves used this code in his Azure samples (to be found in NSB samples collection)
解决此问题的最佳方法是实现 IConfigurationSource 并提供您自己的配置。然后,您可以挑选您想要从配置文件中加载的内容(如果有的话)以及您想要在运行时自己指定的内容。
我会反映
DefaultConfigurationSource
类或参考此要点获取指导。The best way to approach this would be to implement
IConfigurationSource
and provide your own configuration. Then you could cherry pick what you would like to load from the config file (if anything) and what you would like to specify yourself at runtime.I would reflect the
DefaultConfigurationSource
class or refer to this gist for guidance.在我目前参与的一个项目中,我们正在通过在我们自己的路由表中跟踪动态订阅/取消订阅代理来对它们进行一些基于内容的路由。
我们将此处 ),查看消息是否实现了特殊的
IBus
包装在装饰器中(通过使用 Windsor 对装饰器的支持,如IRoutableMessage
接口,该接口允许装饰器通过<代码>bus.Send(destinationEndpoint)。要做到这一点有点复杂,我建议尽可能使用 NServiceBus 的内置路由。但是是否可以将消息显式路由到任何端点。
In a project, I am currently involved with, we are doing some content-based routing to dynamically subscribed/unsubscribed agents by keeping track of them in our own routing table.
We have wrapped the
IBus
in a decorator (by using Windsor's support of decorators, as described <plug>here</plug>), that sees if the message implements a specialIRoutableMessage
interface, that allows the decorator to route the message by explicitly specifying the destination endpoint viabus.Send(destinationEndpoint)
.This was a little bit complex to get right, and I would recommend going with NServiceBus' built-in routing as far as possible. But is is possible to explicitly route messages to any endpoint.
如果您正在研究监控,请查看 NSBManager 存储库。这采用相反的方法,让端点向管理器注册。
If you are looking into monitoring, check out the NSBManager repository. This takes the opposite approach and lets the endpoints register with the manager.