【问题标题】:Get exception when Rhino ServiceBus is startingRhino ServiceBus 启动时出现异常
【发布时间】:2012-01-15 17:48:51
【问题描述】:

我的系统分为两部分。两个部分相互通信 其他使用 Rhino 服务总线。 在 Windows 7 上没有问题,但如果我在其他任何地方启动它 (WinXP,Server 2003,...)我得到以下异常 当我打电话给Rhino.ServiceBus.Hosting.DefaultHost.Start(..):

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)

这是 Spring 日志的片段形式:

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

【问题讨论】:

    标签: messaging spring.net servicebus rhino-servicebus


    【解决方案1】:

    问题已解决: 在 MSMQ 版本 3 或更低版本(在 Windows XP、Windows Server 2003 等系统上)中,不支持子队列,因此 Rhino SB 使用 FlatQueueStrategy 来管理队列。 配置 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);
    

    【讨论】:

    • 太好了,你把你的答案贴在这里了!请也接受它,这样每个人都知道你的问题已经解决了。
    猜你喜欢
    • 2014-03-07
    • 2016-02-23
    • 2011-08-30
    • 2013-07-25
    • 1970-01-01
    • 1970-01-01
    • 2015-08-02
    • 2011-10-14
    • 1970-01-01
    相关资源
    最近更新 更多