【问题标题】:Exclude specific nservicebus host handlers (classes) in version 3.x在版本 3.x 中排除特定的 nservicebus 主机处理程序(类)
【发布时间】:2016-08-30 11:41:13
【问题描述】:

我有一个 NServiceBus 主机,它订阅了某个事件并有自己的处理程序 (#1)。此主机还具有对包含同一事件的另一个处理程序 (#2) 的程序集的引用。我想从 NServiceBus 配置中排除处理程序 #2,但我无法删除引用的程序集。

重要

1) 我尝试使用此设置扫描:http://docs.particular.net/nservicebus/hosting/assembly-scanning

2) 我使用 NServiceBus 版本 3.x

【问题讨论】:

  • 程序集名称是什么,您可以添加您尝试过的代码吗?
  • 我不需要排除整个程序集,我只需要从它的程序集中排除一些处理程序。

标签: nservicebus nservicebus3


【解决方案1】:

移除组件

NServiceBus v3 扫描程序集。如果在运行时不需要该程序集,则只需将其删除,这样就不会被扫描。

仅仅因为它被引用并不意味着它需要被部署。

排除程序集(黑名单)

排除文档中提到的程序集:

var allAssemblies = AllAssemblies
    .Except("MyAssembly1.dll")
    .And("MyAssembly2.dll");
Configure.With(allAssemblies);

http://docs.particular.net/nservicebus/hosting/assembly-scanning#exclude-a-list-approach

包括程序集或类型(白名单)

只允许扫描一组特定的程序集或类型。基本上解析白名单范围内的程序集或类型。

组件:

IEnumerable<Assembly> allowedAssembliesToScanForTypes;
Configure.With(allowedAssembliesToScanForTypes);
// or
Configure.With(assembly1, assembly2);

类型:

IEnumerable<Type> allowedTypesToScan;
Configure.With(allowedTypesToScan);

排除特定类型

// Results in the same assembly scanning as used by NServiceBus internally
var allTypes = from a in AllAssemblies.Except("Dummy") 
               from t in a.GetTypes()
               select t;

// Exclude handlers that you do not want to be registered
var allowedTypesToScan = allTypes
    .Where(t => t != typeof(EventMessageHandler)) 
    .ToList();

Configure.With(allowedTypesToScan);

http://docs.particular.net/nservicebus/hosting/assembly-scanning#include-a-list-approach-including-assemblies

【讨论】:

  • 谢谢,但请您阅读我问题中的重要说明
  • 丹尼斯,我添加了一个额外的 sn-p 排除特定类型,如果这对你有用,请告诉我。
  • 谢谢,但我的代码已经投入生产。但你的答案是正确的
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2017-03-02
  • 2023-03-16
  • 2023-03-30
  • 2020-12-02
  • 1970-01-01
  • 2013-09-06
  • 1970-01-01
相关资源
最近更新 更多