使用TypesToScan后为什么NServiceBus配置损坏() [英] Why is NServiceBus configuration broken after using TypesToScan()

查看:258
本文介绍了使用TypesToScan后为什么NServiceBus配置损坏()的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个控制台应用程序中,你可以根据不同的指定处理程序将加载的参数指定参数。例如:

  prgm.exe NYSE 
prgm.exe纳斯达克

我们的目标是,我的代码中我有 INyseHandlers INasdaqHandlers 并且在第一情况下,只有延伸前者任何处理程序被加载,同样为后者的情况。该目标是有一个节目其可以收听各种或所有来源取决于它是如何运行的。要做到这一点,我已经建立了我的接口如上所述。然后在我的配置设置:

  VAR配置=新BusConfiguration(); 
configuration.InitializeStepBusConventions(); //扩展方法,而不是问题

//装载如果命令行参数中指定
的所有处理程序(Args.Contains(任何)及!&安培; Args.Length! = 0)
{
名单,LT;类型> handlersToLoad =新的List<类型和GT;();

的foreach(在args VAR参数)
{
Console.WriteLine(添加{0}订户装处理。argument.ToUpper());

开关(参数)
{
案NYSE:
AddToHandlerList(handlersToLoad的typeof(INyseProcessor));
中断;
案纳斯达克:
AddToHandlerList(handlersToLoad的typeof(INasdaqProcessor));
中断;
}
}

configuration.TypesToScan(handlersToLoad);
}

configuration.UseContainer< NinjectBuilder>(C => c.ExistingKernel(内核));
configuration.EndpointName(ConfigurationManager.AppSettings [Defaults.Project.DefaultEndPointName]);
NServiceBus.Logging.LogManager.Use< NLogFactory>();

Bus.Create(配置)。开始();

和其中:

 私人无效AddToHandlerList(列表<类型> handlersToLoad,类型interfaceType)
{
名单,LT;类型> classesWhichExtendInterface = Assembly.GetExecutingAssembly()GetTypes()式(T => interfaceType.IsAssignableFrom(T))。了ToList()。
classesWhichExtendInterface.Remove(interfaceType);

handlersToLoad.AddRange(classesWhichExtendInterface);
}



类型加载预期,即列表的罚款。但是,当我运行此,并获得了 Bus.Start 行,我得到以下错误:

 给出的关键字(NServiceBus.LocalAddress)是不存在的字典。 



如果没有装载类型,默认行为工作正常,并装配内的所有处理器都加载。为什么我收到此错误运行 TypesToScan()行之后?



编辑:这里是扩展方法:

  config.UseSerialization< ; JsonSerializer>(); 
config.UseTransport< RabbitMQTransport>();

config.UsePersistence< InMemoryPersistence>();
config.EnableInstallers();

返回配置;


解决方案

您的例外发生在这里。



 将localAddress = Address.Parse(Settings.Get<串GT(NServiceBus.LocalAddress)); 



设置获得NServiceBus.LocalAddressKVP通过传输设置。既然你不使用核心运输(MSMQ),我可能会怀疑你的运输装置类型的需要,因为这是包含在TypesToScan,:

  ForAllTypes<特征>(TypesToScan,T => featureActivator.Add(t.Construct<特征>())); 



我曾与使用SQL Server的运输,当我发送组件的列表,以一个类似的问题(组件),并没有包括NServiceBus组件存在,传输初始化失败。当我加入NServiceBus *组件,一切都开始工作。


I have a Console app within which you can specify parameters, based on the parameters specified various handlers will be loaded. For instance:

prgm.exe nyse 
prgm.exe nasdaq

The goal is that within my code I have INyseHandlers and INasdaqHandlers and in the first case only any handlers extending the former are loaded, similarly for the case of the latter. The goal is to have one program which can listen to various or all sources depending on how it is run. To achieve this, I have set up my interfaces as mentioned above. Then in my configuration set up:

var configuration = new BusConfiguration();
configuration.InitializeStepBusConventions(); // extension method, not the problem

// Load all the handlers specified in command line arguments
if (!Args.Contains("any") && Args.Length != 0)
{
    List<Type> handlersToLoad = new List<Type>();

    foreach (var argument in Args)
    {
        Console.WriteLine("Adding {0} subscribers to loaded handlers. . .", argument.ToUpper());

        switch (argument)
        {
            case "nyse":
                AddToHandlerList(handlersToLoad, typeof(INyseProcessor));
                break;
            case "nasdaq":
                AddToHandlerList(handlersToLoad, typeof(INasdaqProcessor));
                break;        
        }
    }

    configuration.TypesToScan(handlersToLoad);
}

configuration.UseContainer<NinjectBuilder>(c => c.ExistingKernel(Kernel));
configuration.EndpointName(ConfigurationManager.AppSettings[Defaults.Project.DefaultEndPointName]);
NServiceBus.Logging.LogManager.Use<NLogFactory>();

Bus.Create(configuration).Start();  

And where:

private void AddToHandlerList(List<Type> handlersToLoad, Type interfaceType)
{
    List<Type> classesWhichExtendInterface = Assembly.GetExecutingAssembly().GetTypes().Where(t => interfaceType.IsAssignableFrom(t)).ToList();
    classesWhichExtendInterface.Remove(interfaceType);

    handlersToLoad.AddRange(classesWhichExtendInterface);
} 

Types are loaded as expected, that List is fine. But when I run this and get to the Bus.Start line I get the following error:

The given key (NServiceBus.LocalAddress) was not present in the dictionary.

Without the type loading, default behavior works fine and all the processors within the assembly are loaded. Why am I getting this error after running the TypesToScan() line?

EDIT: Here is the extension method:

config.UseSerialization<JsonSerializer>();
config.UseTransport<RabbitMQTransport>();

config.UsePersistence<InMemoryPersistence>();
config.EnableInstallers();

return config;

解决方案

Your exception happens here

localAddress = Address.Parse(Settings.Get<string>("NServiceBus.LocalAddress"));

Settings get the "NServiceBus.LocalAddress" kvp set by a transport. Since you are not using the "Core" transport (MSMQ), I might suspect that your transport assembly types need to be included in TypesToScan, because of this:

ForAllTypes<Feature>(TypesToScan, t => featureActivator.Add(t.Construct<Feature>()));

I had a similar issue with using SQL Server transport, when I send a list of assemblies to With(assemblies) and did not include NServiceBus assemblies there, the transport failed to initialize. As soon as I added NServiceBus.* assemblies, everything started to work.

这篇关于使用TypesToScan后为什么NServiceBus配置损坏()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆