本文介绍了NServiceBus处理失败的消息:请求的服务'NServiceBus.Impersonation.ExtractIncomingPrincipal'未登记的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用NServiceBus 4.0.3时,与NHibernate 3.3.1,当它试图处理邮件收到一个错误

 信息NServiceBus.Unicast.Transport.TransportReceiver [(NULL)]≤(空)> - 无法处理消息
Autofac.Core.Registration.ComponentNotRegisteredException:所请求的服务'NServiceBus.Impersonation.ExtractIncomingPrincipal'尚未注册。为了避免这种情况的例外,无论是注册一个组件提供服务,检查服务注册使用IsRegistered(),或使用ResolveOptional()方法来解决一个可选的依赖。
   在NServiceBus.Unicast.Transport.TransportReceiver.ProcessMessage(TransportMessage消息)在C:\ BuildAgent \工作\ d4de8921a0aabf04的\ src \ NServiceBus.Core \单播\传输\ TransportReceiver.cs:行353
   在NServiceBus.Unicast.Transport.TransportReceiver.TryProcess(TransportMessage消息)在C:\ BuildAgent \工作\ d4de8921a0aabf04的\ src \ NServiceBus.Core \单播\传输\ TransportReceiver.cs:行233
   在NServiceBus.Transports.Msmq.MsmqDequeueStrategy.ProcessMessage(TransportMessage消息)在C:\ BuildAgent \工作\ d4de8921a0aabf04的\ src \ NServiceBus.Core \交通服务\ MSMQ \ MsmqDequeueStrategy.cs:行262
   在NServiceBus.Transports.Msmq.MsmqDequeueStrategy.Action()在C:\ BuildAgent \工作\ d4de8921a0aabf04的\ src \ NServiceBus.Core \交通服务\ MSMQ \ MsmqDequeueStrategy.cs:行197
2013年8月30日09:35:02508 [9] WARN NServiceBus.Faults.Forwarder.FaultManager [(空)]≤(空)> - 消息已经失败FLR,将被移交给单反重试尝试:1,邮件ID = 8aaed043-b744-49c2-965d-a22a009deb32。
 

我认为这是很明显那是什么,我需要落实或注册一个ExtractIncomingPrincipal,但我似乎无法找到任何文件如何或是否有一个默认的,我可以使用。我也不会想通,我将不得不注册任何的,因为其中许多已被注册在我的IoC实​​施NServiceBus相关的服务。

根据要求,这里是EndpointConfig和支持code我目前有:

  [EndpointSLA(00:00:30)
公共类EndpointConfig:IConfigureThisEndpoint,AsA_Server,IWantCustomInitialization {
    公共无效的init(){
        Configure.With().ObjectBuilderAdapter().UseInMemoryTimeoutPersister().UseInMemoryGatewayPersister().InMemorySagaPersister().InMemorySubscriptionStorage();
   }
}

//公共类PrincipalExtractor:ExtractIncomingPrincipal {
//公众的IPrincipal GetPrincipal(TransportMessage消息){
//返回Thread.CurrentPrincipal中;
//}
//}

公共类ObjectBuilderAdapter:{的IContainer
    只读IDependencyInjector喷油器;

    公共ObjectBuilderAdapter(IDependencyInjectionBuilder dependencyInjectionBuilder){
        注射器= dependencyInjectionBuilder.Create(); //此方法完成了所有的常用服务注册,我想重新使用
        //injector.RegisterType<ExtractIncomingPrincipal,PrincipalExtractor&GT;();
    }

    公共无效的Dispose(){
        injector.Dispose();
    }

    公共对象生成(类型typeToBuild){
        返回injector.Resolve(typeToBuild);
    }

    公众的IContainer BuildChildContainer(){
        返回新ObjectBuilderAdapter(新DependencyInjectorBuilder());
    }

    公开的IEnumerable&LT;对象&gt; BuildAll(类型typeToBuild){
        返回injector.ResolveAll(typeToBuild);
    }

    公共无效配置(类型组件,DependencyLifecycle dependencyLifecycle){
        injector.RegisterType(组分);
    }

    公共无效配置及LT; T&GT;(Func键&LT; T&GT;组件,DependencyLifecycle dependencyLifecycle){
            injector.RegisterType(组分);
    }

    公共无效ConfigureProperty(类型组件,字符串属性,对象的值){
        如果(喷射器AutofacDependencyInjector){
          ((AutofacDependencyInjector)喷油器).ConfigureProperty(成分,属性,值);
        } 其他 {
            的Debug.WriteLine(配置{0}的属性{1},但我们不处理这种情况。,component.Name,财产);
        }
    }

    公共无效RegisterSingleton(类型lookupType,对象实例){
        injector.RegisterInstance(lookupType,实例);
    }

    公共BOOL HasComponent(类型组件类型){
        返回injector.IsRegistered(组件类型);
    }

    公共无效释放(对象实例){}
}

公共静态类扩展{
    公共静态配置ObjectBuilderAdapter(此配置的配置){
        ConfigureCommon.With(配置,新ObjectBuilderAdapter(新DependencyInjectorBuilder()));
        返回的配置;
    }
}
 

解决方案

我删除了IWantCustomInitialization(从别的我前面曾试图遗留)的类接口的实现,我的服务现在处理消息。有错误仍然(与尝试连接到乌鸦[即使我想我使用一切都在内存中),但它的处理消息。

I am receiving an error when using NServiceBus 4.0.3 with NHibernate 3.3.1 when it's trying to process a message

    INFO  NServiceBus.Unicast.Transport.TransportReceiver [(null)] <(null)> - Failed to process message
Autofac.Core.Registration.ComponentNotRegisteredException: The requested service 'NServiceBus.Impersonation.ExtractIncomingPrincipal' has not been registered. To avoid this exception, either register a component to provide the service, check for service registration using IsRegistered(), or use the ResolveOptional() method to resolve an optional dependency.
   at NServiceBus.Unicast.Transport.TransportReceiver.ProcessMessage(TransportMessage message) in c:\BuildAgent\work\d4de8921a0aabf04\src\NServiceBus.Core\Unicast\Transport\TransportReceiver.cs:line 353
   at NServiceBus.Unicast.Transport.TransportReceiver.TryProcess(TransportMessage message) in c:\BuildAgent\work\d4de8921a0aabf04\src\NServiceBus.Core\Unicast\Transport\TransportReceiver.cs:line 233
   at NServiceBus.Transports.Msmq.MsmqDequeueStrategy.ProcessMessage(TransportMessage message) in c:\BuildAgent\work\d4de8921a0aabf04\src\NServiceBus.Core\Transports\Msmq\MsmqDequeueStrategy.cs:line 262
   at NServiceBus.Transports.Msmq.MsmqDequeueStrategy.Action() in c:\BuildAgent\work\d4de8921a0aabf04\src\NServiceBus.Core\Transports\Msmq\MsmqDequeueStrategy.cs:line 197
2013-08-30 09:35:02,508 [9] WARN  NServiceBus.Faults.Forwarder.FaultManager [(null)] <(null)> - Message has failed FLR and will be handed over to SLR for retry attempt: 1, MessageID=8aaed043-b744-49c2-965d-a22a009deb32.

I think it's fairly obvious what that I need to implement or register an "ExtractIncomingPrincipal", but I can't seem to find any documentation on how or whether there is a default one that I can use. I wouldn't have figured that I would have had to register any of the NServiceBus-related services as many of them are already being registered in my IoC implementation.

As requested, here is the EndpointConfig and supporting code I have currently:

[EndpointSLA("00:00:30")]
public class EndpointConfig : IConfigureThisEndpoint, AsA_Server, IWantCustomInitialization {
    public void Init() {
        Configure.With().ObjectBuilderAdapter().UseInMemoryTimeoutPersister().UseInMemoryGatewayPersister().InMemorySagaPersister().InMemorySubscriptionStorage();
   }
}

//public class PrincipalExtractor : ExtractIncomingPrincipal {
//    public IPrincipal GetPrincipal(TransportMessage message) {
//        return Thread.CurrentPrincipal;
//    }
//}

public class ObjectBuilderAdapter : IContainer {
    readonly IDependencyInjector injector;

    public ObjectBuilderAdapter(IDependencyInjectionBuilder dependencyInjectionBuilder) {
        injector = dependencyInjectionBuilder.Create(); //This method does all the common service registrations that I am trying to re-use
        //injector.RegisterType<ExtractIncomingPrincipal, PrincipalExtractor>();
    }

    public void Dispose() {
        injector.Dispose();
    }

    public object Build(Type typeToBuild) {
        return injector.Resolve(typeToBuild);
    }

    public IContainer BuildChildContainer() {
        return new ObjectBuilderAdapter(new DependencyInjectorBuilder());
    }

    public IEnumerable<object> BuildAll(Type typeToBuild) {
        return injector.ResolveAll(typeToBuild);
    }

    public void Configure(Type component, DependencyLifecycle dependencyLifecycle) {
        injector.RegisterType(component);
    }

    public void Configure<T>(Func<T> component, DependencyLifecycle dependencyLifecycle) {
            injector.RegisterType(component);
    }

    public void ConfigureProperty(Type component, string property, object value) {
        if (injector is AutofacDependencyInjector) {
          ((AutofacDependencyInjector)injector).ConfigureProperty(component, property, value);
        } else {
            Debug.WriteLine("Configuring {0} for property {1} but we don't handle this scenario.", component.Name, property);
        }
    }

    public void RegisterSingleton(Type lookupType, object instance) {
        injector.RegisterInstance(lookupType, instance);
    }

    public bool HasComponent(Type componentType) {
        return injector.IsRegistered(componentType);
    }

    public void Release(object instance) { }
}

public static class Extensions {
    public static Configure ObjectBuilderAdapter(this Configure config) {
        ConfigureCommon.With(config, new ObjectBuilderAdapter(new DependencyInjectorBuilder()));
        return config;
    }
}
解决方案

I removed the IWantCustomInitialization (left over from something else I had tried earlier) interface implementation on the class and my service now processes the message. There are errors still (relating to trying to connect to Raven [even though I thought I am using everything in-memory), but it's processing the message.

这篇关于NServiceBus处理失败的消息:请求的服务'NServiceBus.Impersonation.ExtractIncomingPrincipal'未登记的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-22 16:28