【发布时间】:2014-09-30 15:44:16
【问题描述】:
我在我的 ASP.net Web api 项目中使用 NServicebus(版本 4.6.3)和 SQLTransport。对于不同环境(Dev、QA 等)的队列,我有不同的连接字符串。我的配置如下:
public class BusConfigurator
{
public static IStartableBus Bus { get; private set; }
public static void DisposeBus()
{
if (Bus == null)
return;
Bus.Shutdown();
Bus.Dispose();
Bus = null;
}
public static void InitializeServiceBus(string connectionString)
{
var configure = Configure.With()
.DefineEndpointName("MyEndPoint")
.Log4Net(new DebugAppender { Threshold = Level.Warn })
.UseTransport<SqlServer>(connectionString)
.PurgeOnStartup(false)
.SetDefaultTransactionLevel()
.UnicastBus(); // Error is thrown here on second call
configure.MyCustomSQLServerPersistence();
Bus = configure.CreateBus();
}
public static void StartBus()
{
Bus.Start(() => Configure.Instance.ForInstallationOn<NServiceBus.Installation.Environments.Windows>().Install());
}
}
我在应用中有一个下拉菜单,以便用户可以选择环境。根据选择,我想重新配置总线。因此,我调用 DisposeBus,然后将连接字符串传递给 IntializeServiceBus 方法,然后是 startBus。它第一次工作,但在使用不同的连接字符串再次调用时会在下面抛出错误:
无法设置键值:NServiceBus.Transport.ConnectionString。设置已被锁定以进行修改。请在配置管道中更早地移动任何配置代码 源=NServiceBus.Core 线=0 BareMessage=无法设置键值:NServiceBus.Transport.ConnectionString。设置已被锁定以进行修改。请在配置管道中移动任何配置代码
NServicebus 是否打算以这种方式使用/配置? (我猜可能不是)如果没有,那么是否有解决方法/不同的方法?
【问题讨论】:
-
Id' 说在 NServiceBus v4.x 中,除了回收 Web 应用程序之外,没有办法使配置无效/重新创建,还不知道(我正在设置一个示例)如果在 v5 中有什么可以实现的
标签: c# asp.net asp.net-web-api nservicebus