سؤال

لدي نظام مقسم إلى قسمين.يتواصل كلا الجزأين مع بعضهما البعض باستخدام حافلة خدمة الكدنين.لا توجد مشكلة في 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)

هنا جزء من سجل الربيع:

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
هل كانت مفيدة؟

المحلول

تم حل المشكلة:في الإصدار 3 من MSMQ أو أقل (على أنظمة مثل Windows XP وWindows Server 2003)، لا يتم دعم قوائم الانتظار الفرعية، ولذلك يستخدم Rhino SB FlatQueueStrategy لإدارة قوائم الانتظار.تحدث المشاكل عند تكوين حاوية كائن Spring.يوجد بشكل ملموس مكانان في الفصل Rhino.ServiceBus.Spring.SpringBuilder حيث يجب إجراء التعديلات.

1) الطريقة سجلMsmqTransport:

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:

    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);
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top