Azure中基于NServiceBus 4代码的配置不工作
我正在使用Nservicebus 4的RC2和从以下位置下载的PubSub示例: 我正在尝试进行基于代码的配置(而不是示例中所示的azure csfg文件)。这适用于早期版本的NServiceBus,因此我不确定这里缺少什么。未拾取自定义配置。这是虫子吗 以下是我所做的更改,这些更改应该与问题重复Azure中基于NServiceBus 4代码的配置不工作,azure,nservicebus,Azure,Nservicebus,我正在使用Nservicebus 4的RC2和从以下位置下载的PubSub示例: 我正在尝试进行基于代码的配置(而不是示例中所示的azure csfg文件)。这适用于早期版本的NServiceBus,因此我不确定这里缺少什么。未拾取自定义配置。这是虫子吗 以下是我所做的更改,这些更改应该与问题重复 已从webrole设置中删除nservicebus配置 替换了自定义IConfigurationSource中的相同配置设置,并从总线引导代码中删除了AzureConfigurationSource
var bus = Configure.With()
.DefaultBuilder()
.CustomConfigurationSource(new CustomConfig())
.MessageForwardingInCaseOfFault()
.AzureMessageQueue()
.QueuePerInstance()
.UnicastBus()
.CreateBus()
.Start();
internal class CustomConfig : IConfigurationSource
{
public T GetConfiguration<T>() where T : class, new()
{
// the part you are overriding
if (typeof(T) == typeof(AzureQueueConfig))
return new AzureQueueConfig { ConnectionString = "storage key here", QueueName = "orderwebsiteinputqueue" } as T;
if (typeof(T) == typeof(MessageForwardingInCaseOfFaultConfig))
return new MessageForwardingInCaseOfFaultConfig { ErrorQueue = "errorqueue"} as T;
if (typeof(T) == typeof(TransportConfig))
return new TransportConfig() { MaxRetries = 5, MaximumConcurrencyLevel = 1} as T;
// leaving the rest of the configuration as is:
return ConfigurationManager.GetSection(typeof(T).Name) as T;
}
}
这是CustomConfig类:
var bus = Configure.With()
.DefaultBuilder()
.CustomConfigurationSource(new CustomConfig())
.MessageForwardingInCaseOfFault()
.AzureMessageQueue()
.QueuePerInstance()
.UnicastBus()
.CreateBus()
.Start();
internal class CustomConfig : IConfigurationSource
{
public T GetConfiguration<T>() where T : class, new()
{
// the part you are overriding
if (typeof(T) == typeof(AzureQueueConfig))
return new AzureQueueConfig { ConnectionString = "storage key here", QueueName = "orderwebsiteinputqueue" } as T;
if (typeof(T) == typeof(MessageForwardingInCaseOfFaultConfig))
return new MessageForwardingInCaseOfFaultConfig { ErrorQueue = "errorqueue"} as T;
if (typeof(T) == typeof(TransportConfig))
return new TransportConfig() { MaxRetries = 5, MaximumConcurrencyLevel = 1} as T;
// leaving the rest of the configuration as is:
return ConfigurationManager.GetSection(typeof(T).Name) as T;
}
}
内部类CustomConfig:IConfigurationSource
{
public T GetConfiguration(),其中T:class,new()
{
//您要覆盖的部分
if(typeof(T)=typeof(AzureQueueConfig))
返回新的AzureQueueConfig{ConnectionString=“此处存储密钥”,QueueName=“orderwebsiteinputqueue”}作为T;
if(typeof(T)=typeof(MessageForwardingCaseofFaultConfig))
将新的MessageForwardingCaseofFaultConfig{ErrorQueue=“ErrorQueue”}返回为T;
如果(类型(T)=类型(传输配置))
将新的TransportConfig(){MaxRetries=5,MaximumConcurrencyLevel=1}返回为T;
//将其余配置保持原样:
将ConfigurationManager.GetSection(typeof(T).Name)返回为T;
}
}
定制配置的推荐方法是实施IProvidConfiguration,而不是替换配置源,您能试试吗
亲切问候,,
Yves谢谢!这确实有效。但是,问题是,这以前是有效的,因此我需要更改现有端点以使用此方法,而不是IConfigurationSource。我建议更改文档以表明这不是首选方法,或者将其标记为过时,这样用户就不会遇到与我相同的问题。大多数用户在尝试超越本地仿真器之前(至少对于队列配置凭据而言)不会捕捉到这一点,因为您知道,默认连接是dev storage,使用自定义配置源似乎可以在本地工作,但不能。我刚刚发现ICustomconfigurationSource适用于使用azure传输的控制台项目。因此,问题似乎只存在于azure托管的项目中。为了测试这一点,我启动了一个控制台项目作为客户端,并注册了一个AzureQueueConfig配置源,它成功了。找到了罪魁祸首,看起来第29行需要额外检查以查看是否已经配置了自定义源。太好了!谢谢你的快速工作。我注意到的另一件可能与配置无关但与配置相关的事情是,azure配置中必须至少有AzureProfileConfig.Profiles,否则它会抱怨。仅供参考,我将发布另一个与DataBus配置相关的类似问题。