Azure中的NServiceBus 4基于代码的配置无法正常工作

时间:2013-07-08 00:15:59

标签: azure nservicebus

我正在使用Nservicebus 4的RC2和从以下位置下载的PubSub示例: http://particular.net/articles/windows-azure-transport

我正在尝试进行基于代码的配置(而不是如示例中所示的azure csfg文件)。这适用于早期版本的NServiceBus,所以我不确定我在这里缺少什么。自定义配置未被选中。这是一个错误吗?

以下是我应该复制问题的更改。

  1. 从webrole设置中删除了nservicebus配置
  2. 替换了自定义IConfigurationSource中的相同配置设置,并从总线引导代码中删除了AzureConfigurationSource。
  3. 以下是Global.asax.cs文件中更改的引导程序代码:

      var bus = Configure.With()
                    .DefaultBuilder()
                    .CustomConfigurationSource(new CustomConfig())
                    .MessageForwardingInCaseOfFault()
                    .AzureMessageQueue()
                        .QueuePerInstance()
                    .UnicastBus()
                    .CreateBus()
                .Start();
    

    以下是CustomConfig类:

    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;
        }
    }
    

1 个答案:

答案 0 :(得分:1)

自定义配置的推荐方法是实现IProvideConfiguration而不是替换配置源,你能试试吗?

亲切的问候, 伊夫