2012-01-15 27 views
0

我將我的系統分爲兩部分。兩部分都與使用Rhino Service Bus的其他每個 進行通信。 有在Windows 7上沒有問題,但如果我啓動其他地方 (操作系統,服務器2003,...),我得到下面的異常 當我打電話Rhino.ServiceBus.Hosting.DefaultHost.Start(..)當Rhino ServiceBus啓動時得到例外

System.NullReferenceException: Object reference not set to an instance of an object. 
    at Spring.Objects.Factory.Support.AbstractObjectFactory.GetObjectFromFactoryObject(IFactoryObject factory, String objectName, RootObjectDefinition rod) 
    at Spring.Objects.Factory.Support.AbstractObjectFactory.GetObjectForInstance(Object instance, String name, String canonicalName, RootObjectDefinition rod) 
    at Spring.Objects.Factory.Support.AbstractObjectFactory.GetObjectInternal(String name, Type requiredType, Object[] arguments, Boolean suppressConfigure) 
    at Spring.Objects.Factory.Support.AbstractObjectFactory.GetObject(String name) 
    at Spring.Context.Support.AbstractApplicationContext.GetObject(String name) 
    at Rhino.ServiceBus.Spring.ApplicationContextExtensions.Get(IApplicationContext context, Type type) 
    at Rhino.ServiceBus.Spring.ApplicationContextExtensions.Get[T](IConfigurableApplicationContext context) 
    at Rhino.ServiceBus.Spring.SpringBootStrapper.GetInstance[T]() 
    at Rhino.ServiceBus.Hosting.DefaultHost.InitailizeBus(String asmName) 
    at Rhino.ServiceBus.Hosting.DefaultHost.Start(String asmName) 

這裏是片段形式春天日誌:

2012-01-14 13:25:01,084 DEBUG Spring.Objects.Factory.Support.DefaultListableObjectFactory - Invoking IObjectPostProcessors after initialization of object '351a5f07-e33d-4be0-84cf-1738a8feba24' 
2012-01-14 13:25:01,084 DEBUG Spring.Objects.Factory.Support.DefaultListableObjectFactory -   GetObjectInternal: returning instance for objectname 351a5f07-e33d-4be0-84cf-1738a8feba24 
2012-01-14 13:25:01,084 ERROR Spring.Objects.Factory.Support.DefaultListableObjectFactory -  GetObjectInternal: error obtaining object Rhino.ServiceBus.Msmq.FlatQueueStrategy 
2012-01-14 13:25:01,084 ERROR Spring.Objects.Factory.Support.DefaultListableObjectFactory - GetObjectInternal: error obtaining object Rhino.ServiceBus.Msmq.MsmqTransport 
2012-01-14 13:25:01,084 ERROR Spring.Objects.Factory.Support.DefaultListableObjectFactory - GetObjectInternal: error obtaining object 1a769f24-5410-4cee-8d7a-76c3a91b1ce1 

回答

1

問題解決了: 在MSMQ版本3或更低(在諸如Windows XP,Windows Server 2003系統),子隊列中,不支持,因此犀牛SB採用FlatQueueStrategy爲manageing隊列。 配置Spring對象容器時發生問題。具體來說,類Rhino.ServiceBus.Spring.SpringBuilder中有兩個地方需要完成修改。

1)方法RegisterMsmqTransport

if (queueStrategyType.GetConstructor(new[] { typeof(IQueueStrategy), typeof(Uri) }) != null) 
{ 
    applicationContext.RegisterSingleton(queueStrategyType, typeof (IQueueStrategy).FullName, applicationContext.Get<IEndpointRouter>(), config.Endpoint); 
} 
else 
{ 
    // use default 
    applicationContext.RegisterSingleton(queueStrategyType); 
} 

的if語句總是被稱爲第二部分,因爲FlatQueueStrategy沒有與類型IQueueStrategy和URI參數的構造函數。 但它甚至沒有沒有參數的構造函數。因此,FlatQueueStrategy未在對象容器中正確註冊。 對於這一部分的變形將是:

if (queueStrategyType.GetConstructor(new[] { typeof(IEndpointRouter), typeof(Uri) }) != null) 
{ 
    applicationContext.RegisterSingleton(queueStrategyType, typeof (IQueueStrategy).FullName, applicationContext.Get<IEndpointRouter>(), config.Endpoint); 
} 
else 
{ 
    // use default 
    applicationContext.RegisterSingleton(queueStrategyType); 
} 

2)方法RegisterDefaultServices

接下來的問題是在該方法中RegisterDefaultServices:

applicationContext.RegisterSingleton<IServiceLocator>(() => new SpringServiceLocator(applicationContext)); 
    applicationContext.RegisterSingletons<IBusConfigurationAware>(typeof(IServiceBus).Assembly); 

    foreach (var busConfigurationAware in applicationContext.GetAll<IBusConfigurationAware>()) 
    { 
     busConfigurationAware.Configure(config, this); // here is the method RegisterMsmqTransport called 
    } 

    foreach (var module in config.MessageModules) 
    { 
     applicationContext.RegisterSingleton(module, module.FullName); 
    } 

    applicationContext.RegisterSingleton<IReflection>(() => new DefaultReflection()); 
    applicationContext.RegisterSingleton(config.SerializerType); 
    applicationContext.RegisterSingleton<IEndpointRouter>(() => new EndpointRouter()); 

方法RegisterMsmqTransport IEndpointRouter被註冊之前被稱爲在對象容器中。 IEndpointRouter在方法RegisterMsmqTransport使用(參見圖1),因此方法調用

applicationContext.Get<IEndpointRouter>() 

產生一個例外。 這裏的修改應該是:

applicationContext.RegisterSingleton<IServiceLocator>(() => new SpringServiceLocator(applicationContext)); 
    applicationContext.RegisterSingletons<IBusConfigurationAware>(typeof(IServiceBus).Assembly); 
    applicationContext.RegisterSingleton<IReflection>(() => new DefaultReflection()); 
    applicationContext.RegisterSingleton<IEndpointRouter>(() => new EndpointRouter()); 

    foreach (var busConfigurationAware in applicationContext.GetAll<IBusConfigurationAware>()) 
    { 
     busConfigurationAware.Configure(config, this); 
    } 

    foreach (var module in config.MessageModules) 
    { 
     applicationContext.RegisterSingleton(module, module.FullName); 
    } 

    applicationContext.RegisterSingleton(config.SerializerType); 
+0

偉大的你發佈你的答案回來了!請接受它,以便大家都知道你的問題解決了。 – Marijn 2012-05-24 10:10:07