在代码中定义 NServiceBus 实例映射



我正在编写一个 asp.net 核心应用程序,并希望向NServiceBus端点发送消息。

由于我们有不同的环境,我需要为每个环境配置一个端点地址。我在应用程序设置中执行此操作。环境.json.

我喜欢对实例映射做同样的事情。我知道的唯一方法是为每个环境创建一个不同的instance-mapping.xml文件,或者将其添加到我没有的 app.config 中。有没有办法在代码中设置实例机器?我不想有不同的XML文件。

我使用 NServiceBus 6.3.4

我在端点配置中添加了一个功能:

endpointConfiguration.EnableFeature<MyFeature>();
public class MyFeature : Feature
{
protected override void Setup(FeatureConfigurationContext context)
{
var endpointInstances = context.Settings.Get<EndpointInstances>();
endpointInstances.AddOrReplaceInstances("InstanceMapping",
new List<EndpointInstance>
{
new EndpointInstance("MyEndpoint").AtMachine("VM-1")
});
}
}

在此处和此处查看文档

最新更新