NServiceBus Saga 没有注册 IPersistTimeouts 组件
NServiceBus Saga has no IPersistTimeouts component registered
我有一个自热 WCF 主机 (IIS),我在 NServiceBus 配置期间遇到此异常:
Exception thrown: 'Autofac.Core.Registration.ComponentNotRegisteredException' in NServiceBus.Core.dll
Additional information: The requested service 'NServiceBus.Timeout.Core.IPersistTimeouts' 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.
我正在使用具有 内存持久性 和 MSMQ 传输.
的 NSB 5.2.9
这是我对自承载 WCF 主机 (IIS) 的配置。 没有App.config!
**这是在 global.asax:
中的 Autofac 注册后调用的
public static void CreateSelfHost( string endpointName, ILifetimeScope container )
{
if ( Bus != null )
return;
lock ( syncLock )
{
var config = new BusConfiguration();
config.UseContainer<AutofacBuilder>( c => c.ExistingLifetimeScope( container ) );
var includesBuilder = AllAssemblies.Matching( "Company.App." );
config.AssembliesToScan( includesBuilder );
config.UseSerialization<JsonSerializer>();
config.UseTransport<MsmqTransport>();
config.UsePersistence<InMemoryPersistence>();
config.DisableFeature<SecondLevelRetries>(); //turn off for in-mem persistence, otherwise could lose messages
config.EndpointName( endpointName );
config.EnableInstallers(); //ensures msmq is created
config.PurgeOnStartup( true ); //only for self-hosted
config.Transactions().Disable();
config.DisableFeature<StorageDrivenPublishing>();
Bus = NServiceBus.Bus.CreateSendOnly( config ); //create SendOnlyBus here
}
}
所有端点上的配置仅通过 IProvideConfiguration<>
完成。
在项目的属性中设置了 NServiceBus.Lite 配置文件,但这没有任何区别。
我是 NSB 的新手,我无法解释为什么会这样。
我一直在寻找启用 IPersistsTimeouts
的方法,但我发现的任何方法都被标记为过时且不起作用。
编辑#1:
@DavidBoike 请求的功能转储
------------- FEATURES ----------------
Name: CriticalErrorHandling
Version: 5.2.9
Enabled by Default: Yes
Status: Enabled
Dependencies: None
Startup Tasks: None
Name: CustomIDataBus
Version: 5.2.9
Enabled by Default: No
Status: Disabled
Deactivation reason: Did not meet one of the dependencies: [DataBus]
Name: DataBus
Version: 5.2.9
Enabled by Default: Yes
Status: Disabled
Deactivation reason: Did not fulfill its Prerequisites:
-No databus properties was found in available messages
Name: Encryptor
Version: 5.2.9
Enabled by Default: Yes
Status: Disabled
Deactivation reason: Did not fulfill its Prerequisites:
-No encryption properties was found in available messages
Name: ErrorSubscribers
Version: 5.2.9
Enabled by Default: Yes
Status: Enabled
Dependencies: None
Startup Tasks: None
Name: ForwarderFaultManager
Version: 5.2.9
Enabled by Default: Yes
Status: Enabled
Dependencies: None
Startup Tasks: None
Name: InMemoryFaultManager
Version: 5.2.9
Enabled by Default: No
Status: Disabled
Deactivation reason: Did not meet one of the dependencies:
Name: InstallationSupport
Version: 5.2.9
Enabled by Default: Yes
Status: Enabled
Dependencies: None
Startup Tasks: None
Name: CriticalTimeMonitoring
Version: 5.2.9
Enabled by Default: No
Status: Disabled
Deactivation reason: Did not meet one of the dependencies:
Name: Audit
Version: 5.2.9
Enabled by Default: Yes
Status: Enabled
Dependencies: None
Startup Tasks: None
Name: AutoSubscribe
Version: 5.2.9
Enabled by Default: Yes
Status: Enabled
Dependencies: None
Startup Tasks: ApplySubscriptions
Name: MsmqSubscriptionPersistence
Version: 5.2.9
Enabled by Default: No
Status: Enabled
Dependencies: None
Startup Tasks: None
Name: Scheduler
Version: 5.2.9
Enabled by Default: Yes
Status: Enabled
Dependencies: None
Startup Tasks: None
Name: CustomSerialization
Version: 5.2.9
Enabled by Default: Yes
Status: Disabled
Deactivation reason: Did not fulfill its Prerequisites:
-CustomSerialization not enable since serialization definition not detected.
Name: ForwardReceivedMessages
Version: 5.2.9
Enabled by Default: Yes
Status: Disabled
Deactivation reason: Did not fulfill its Prerequisites:
-No forwarding address was defined in the unicastbus config
Name: RegisterHandlersInOrder
Version: 5.2.9
Enabled by Default: Yes
Status: Enabled
Dependencies: None
Startup Tasks: None
Name: SLAMonitoring
Version: 5.2.9
Enabled by Default: No
Status: Disabled
Deactivation reason: Did not meet one of the dependencies:
Name: LicenseReminder
Version: 5.2.9
Enabled by Default: Yes
Status: Enabled
Dependencies: None
Startup Tasks: None
Name: Outbox
Version: 5.2.9
Enabled by Default: No
Status: Disabled
Deactivation reason: Did not meet one of the dependencies:
Name: InMemoryGatewayPersistence
Version: 5.2.9
Enabled by Default: No
Status: Disabled
Deactivation reason: Did not meet one of the dependencies: [Gateway]
Name: InMemoryOutboxPersistence
Version: 5.2.9
Enabled by Default: No
Status: Disabled
Deactivation reason: Did not meet one of the dependencies: [Outbox]
Name: InMemorySagaPersistence
Version: 5.2.9
Enabled by Default: No
Status: Disabled
Deactivation reason: Did not meet one of the dependencies: [Sagas]
Name: InMemorySubscriptionPersistence
Version: 5.2.9
Enabled by Default: No
Status: Disabled
Deactivation reason: Did not meet one of the dependencies: [MessageDrivenSubscriptions]
Name: InMemoryTimeoutPersistence
Version: 5.2.9
Enabled by Default: No
Status: Disabled
Deactivation reason: Did not meet one of the dependencies: [TimeoutManager]
Name: TimeoutManagerBasedDeferral
Version: 5.2.9
Enabled by Default: No
Status: Enabled
Dependencies: None
Startup Tasks: None
Name: UnicastBus
Version: 5.2.9
Enabled by Default: Yes
Status: Enabled
Dependencies: None
Startup Tasks: None
Name: BinarySerialization
Version: 5.2.9
Enabled by Default: Yes
Status: Disabled
Deactivation reason: Did not fulfill its Prerequisites:
-BinarySerialization not enable since serialization definition not detected.
Name: BsonSerialization
Version: 5.2.9
Enabled by Default: Yes
Status: Disabled
Deactivation reason: Did not fulfill its Prerequisites:
-BsonSerialization not enable since serialization definition not detected.
Name: JsonSerialization
Version: 5.2.9
Enabled by Default: Yes
Status: Enabled
Dependencies: None
Startup Tasks: None
Name: XmlSerialization
Version: 5.2.9
Enabled by Default: Yes
Status: Disabled
Deactivation reason: Did not fulfill its Prerequisites:
-XmlSerialization not enable since serialization definition not detected.
Name: MsmqTransportConfigurator
Version: 5.2.9
Enabled by Default: No
Status: Enabled
Dependencies: None
Startup Tasks: None
Name: TimeoutManager
Version: 5.2.9
Enabled by Default: No
Status: Enabled
Dependencies: [TimeoutManagerBasedDeferral]
Startup Tasks: None
Name: Sagas
Version: 5.2.9
Enabled by Default: Yes
Status: Disabled
Deactivation reason: Did not fulfill its Prerequisites:
-No sagas was found in scanned types
Name: SecondLevelRetries
Version: 5.2.9
Enabled by Default: Yes
Status: Enabled
Dependencies: [ForwarderFaultManager]
Startup Tasks: None
Name: DataBusFileBased
Version: 5.2.9
Enabled by Default: No
Status: Disabled
Deactivation reason: Did not meet one of the dependencies: [DataBus]
Name: StorageDrivenPublishing
Version: 5.2.9
Enabled by Default: No
Status: Enabled
Dependencies: None
Startup Tasks: None
Name: MessageDrivenSubscriptions
Version: 5.2.9
Enabled by Default: No
Status: Enabled
Dependencies: None
Startup Tasks: None
编辑#2:
在应用了 David 的建议并将配置保持在最低限度之后,我仍然仅在使用 MsmqPersistence 而不是 InMemoryPersistence 时遇到异常。我没有尝试过其他持久性存储。
此异常由具有完整总线(不是 SendOnlyBus)的 MVC 应用程序抛出,配置如下:
public void ConfigureServiceBus( IContainer container, IAppBuilder app )
{
var busConfiguration = new BusConfiguration();
busConfiguration.UseContainer<AutofacBuilder>( c => c.ExistingLifetimeScope( container ) );
busConfiguration.EnableInstallers();
var inc = AllAssemblies.Matching( "Company." )
.And( "NServiceBus" )
.And( "ServiceControl" );
config.AssembliesToScan( inc );
config.UsePersistence<MsmqPersistence>();
config.UseSerialization<JsonSerializer>();
config.UseTransport<MsmqTransport>();
config.EndpointName( endpointName );
var startableBus = NServiceBus.Bus.Create( busConfiguration );
startableBus.Start();
}
Exception thrown: 'System.NullReferenceException' in
NServiceBus.Core.dll Additional information: Object reference not set
to an instance of an object.
调用堆栈:
ServiceBus.Core.dll!NServiceBus.Timeout.Hosting.Windows.TimeoutPersisterReceiver.Poll(object obj) Line 90 C#
MVC 中的 Autofac 配置:
public static IContainer ConfigureAutofac( IAppBuilder app )
{
ContainerBuilder builder = new ContainerBuilder();
// Register your MVC controllers.
builder.RegisterControllers( typeof( MvcApplication ).Assembly );
builder.RegisterType<...>().AsImplementedInterfaces();
//...
// Set the dependency resolver to be Autofac.
IContainer container = builder.Build();
var resolver = new Autofac.Integration.Mvc.AutofacDependencyResolver( container );
DependencyResolver.SetResolver( resolver );
return container;
}
同样,这发生在具有 MsmqPersistence 的 MVC 应用程序中,该应用程序订阅了 Some_Endpoint 发布的 events。上面提到的 WCF 主机最初向 Some_Endpoint.
发送 命令
这里似乎发生了几件事,所以我将解决一些可能导致问题的要点。
程序集扫描
这段代码控制扫描哪些程序集以获得对 NServiceBus 重要的类型:
var includesBuilder = AllAssemblies.Matching( "Company.App." );
config.AssembliesToScan( includesBuilder );
如果您不小心排除了重要的程序集,这可能会导致奇怪的事情发生。使用 AllAssemblies
尝试添加 NServiceBus 程序集,但可以肯定的是您排除了任何 ServiceControl 插件。
如果可能,省略此部分并允许端点扫描目录中的所有程序集会更容易。
更好的是:
config.AssembliesToScan(AllAssemblies.Matching("Company.App.")
.And("NServiceBus")
.And("ServiceControl"));
或者更好的是,不要列入白名单,但如果绝对必要,请使用黑名单,因为您有一些疯狂的程序集,其中包含数千种您不想打扰扫描的不相关类型:
config.AssembliesToScan(AllAssemblies.Except("CrazyAssemblies"));
仅发送
在您的 WCF 代码片段中,您正在创建一个只发送总线,但您在其上方有一些奇怪的配置选择:
config.EnableInstallers(); //ensures msmq is created
config.PurgeOnStartup( true ); //only for self-hosted
config.Transactions().Disable();
config.DisableFeature<StorageDrivenPublishing>();
Bus = NServiceBus.Bus.CreateSendOnly( config ); //create SendOnlyBus here
根据定义,只发送端点不接收消息,因此它不创建队列。 EnableInstallers()
不需要,因为不需要设置队列。 PurgeOnStartup(true)
没有多大意义,因为没有要清除的队列。
此外,您在谈论 sagas 和超时队列,但仅发送端点无法处理消息,这意味着也没有 sagas。这些事情的组合可能会导致奇怪的边缘情况。
Enabling/Disabling 特点
我看到一些调用禁用了某些功能:
config.DisableFeature<SecondLevelRetries>(); //turn off for in-mem persistence, otherwise could lose messages
config.DisableFeature<StorageDrivenPublishing>();
SecondLevelRetries 是需要超时的事情之一,所以如果你禁用它并且没有传奇,我可以看到哪里可能有一个独特的设置组合会导致 InMemory 超时持续器没有被注册,这会是一个错误。
请注意,在您的功能输出中:
- InMemoryTimeoutPersistence 由于 TimeoutManager
而被禁用
- 但是,TiemoutManager 已启用。这可能可能是一个错误。
你总是可以尝试强制这个问题:
config.EnableFeature<InMemoryTimeoutPersistence>();
但通常最好让这些功能自己解决问题,而不是 enable/disable 他们单独解决问题。
夫妇相关笔记:
- 为了不丢失消息而禁用 SecondLevelRetries 有点倒退。使用内存中的持久性,您将丢失消息。只适合开发。对于生产,您应该使用其他持久性选项之一。但是,我可以看到在开发中跳过 SLR 以避免在调试时重复异常跟踪是多么有价值。
- 为什么要禁用 StorageDrivenPublishing? MSMQ 没有内置 Pub/Sub(就像 RabbitMQ 或 Azure Service Bus 那样)所以没有这个功能你将根本无法发布事件。
其他
这可能与将 Autofac 容器传递到 NServiceBus 之前的配置方式有关。很难推测,因为我看不到该代码。
我已尝试使用您提供的代码进行重现,但一直未能成功。如果上面的 none 最终可以正常工作并且可以进行简单的重现(例如,在基本的 Windows 控制台应用程序项目中创建总线)那么它应该很容易修复,或者至少确保提供更好的错误消息。
编辑:MsmqPersistence
使用 MsmqPersistence 时出现 NullReferenceException 是有道理的。 MsmqPersistence 仅包括订阅存储。它不提供其他持久化类型的实现,包括 Timeouts、Sagas、Gateway 和 Outbox。 (我可能漏掉了一个?)
无论如何,MsmqPersistence 都是遗物。不要使用它!
对于开发,您可以使用内存。对于其他环境,您应该使用 NHibernate 或 RavenDB。
我有一个自热 WCF 主机 (IIS),我在 NServiceBus 配置期间遇到此异常:
Exception thrown: 'Autofac.Core.Registration.ComponentNotRegisteredException' in NServiceBus.Core.dll
Additional information: The requested service 'NServiceBus.Timeout.Core.IPersistTimeouts' 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.
我正在使用具有 内存持久性 和 MSMQ 传输.
的 NSB 5.2.9这是我对自承载 WCF 主机 (IIS) 的配置。 没有App.config! **这是在 global.asax:
中的 Autofac 注册后调用的 public static void CreateSelfHost( string endpointName, ILifetimeScope container )
{
if ( Bus != null )
return;
lock ( syncLock )
{
var config = new BusConfiguration();
config.UseContainer<AutofacBuilder>( c => c.ExistingLifetimeScope( container ) );
var includesBuilder = AllAssemblies.Matching( "Company.App." );
config.AssembliesToScan( includesBuilder );
config.UseSerialization<JsonSerializer>();
config.UseTransport<MsmqTransport>();
config.UsePersistence<InMemoryPersistence>();
config.DisableFeature<SecondLevelRetries>(); //turn off for in-mem persistence, otherwise could lose messages
config.EndpointName( endpointName );
config.EnableInstallers(); //ensures msmq is created
config.PurgeOnStartup( true ); //only for self-hosted
config.Transactions().Disable();
config.DisableFeature<StorageDrivenPublishing>();
Bus = NServiceBus.Bus.CreateSendOnly( config ); //create SendOnlyBus here
}
}
所有端点上的配置仅通过 IProvideConfiguration<>
完成。
在项目的属性中设置了 NServiceBus.Lite 配置文件,但这没有任何区别。
我是 NSB 的新手,我无法解释为什么会这样。
我一直在寻找启用 IPersistsTimeouts
的方法,但我发现的任何方法都被标记为过时且不起作用。
编辑#1: @DavidBoike 请求的功能转储
------------- FEATURES ----------------
Name: CriticalErrorHandling
Version: 5.2.9
Enabled by Default: Yes
Status: Enabled
Dependencies: None
Startup Tasks: None
Name: CustomIDataBus
Version: 5.2.9
Enabled by Default: No
Status: Disabled
Deactivation reason: Did not meet one of the dependencies: [DataBus]
Name: DataBus
Version: 5.2.9
Enabled by Default: Yes
Status: Disabled
Deactivation reason: Did not fulfill its Prerequisites:
-No databus properties was found in available messages
Name: Encryptor
Version: 5.2.9
Enabled by Default: Yes
Status: Disabled
Deactivation reason: Did not fulfill its Prerequisites:
-No encryption properties was found in available messages
Name: ErrorSubscribers
Version: 5.2.9
Enabled by Default: Yes
Status: Enabled
Dependencies: None
Startup Tasks: None
Name: ForwarderFaultManager
Version: 5.2.9
Enabled by Default: Yes
Status: Enabled
Dependencies: None
Startup Tasks: None
Name: InMemoryFaultManager
Version: 5.2.9
Enabled by Default: No
Status: Disabled
Deactivation reason: Did not meet one of the dependencies:
Name: InstallationSupport
Version: 5.2.9
Enabled by Default: Yes
Status: Enabled
Dependencies: None
Startup Tasks: None
Name: CriticalTimeMonitoring
Version: 5.2.9
Enabled by Default: No
Status: Disabled
Deactivation reason: Did not meet one of the dependencies:
Name: Audit
Version: 5.2.9
Enabled by Default: Yes
Status: Enabled
Dependencies: None
Startup Tasks: None
Name: AutoSubscribe
Version: 5.2.9
Enabled by Default: Yes
Status: Enabled
Dependencies: None
Startup Tasks: ApplySubscriptions
Name: MsmqSubscriptionPersistence
Version: 5.2.9
Enabled by Default: No
Status: Enabled
Dependencies: None
Startup Tasks: None
Name: Scheduler
Version: 5.2.9
Enabled by Default: Yes
Status: Enabled
Dependencies: None
Startup Tasks: None
Name: CustomSerialization
Version: 5.2.9
Enabled by Default: Yes
Status: Disabled
Deactivation reason: Did not fulfill its Prerequisites:
-CustomSerialization not enable since serialization definition not detected.
Name: ForwardReceivedMessages
Version: 5.2.9
Enabled by Default: Yes
Status: Disabled
Deactivation reason: Did not fulfill its Prerequisites:
-No forwarding address was defined in the unicastbus config
Name: RegisterHandlersInOrder
Version: 5.2.9
Enabled by Default: Yes
Status: Enabled
Dependencies: None
Startup Tasks: None
Name: SLAMonitoring
Version: 5.2.9
Enabled by Default: No
Status: Disabled
Deactivation reason: Did not meet one of the dependencies:
Name: LicenseReminder
Version: 5.2.9
Enabled by Default: Yes
Status: Enabled
Dependencies: None
Startup Tasks: None
Name: Outbox
Version: 5.2.9
Enabled by Default: No
Status: Disabled
Deactivation reason: Did not meet one of the dependencies:
Name: InMemoryGatewayPersistence
Version: 5.2.9
Enabled by Default: No
Status: Disabled
Deactivation reason: Did not meet one of the dependencies: [Gateway]
Name: InMemoryOutboxPersistence
Version: 5.2.9
Enabled by Default: No
Status: Disabled
Deactivation reason: Did not meet one of the dependencies: [Outbox]
Name: InMemorySagaPersistence
Version: 5.2.9
Enabled by Default: No
Status: Disabled
Deactivation reason: Did not meet one of the dependencies: [Sagas]
Name: InMemorySubscriptionPersistence
Version: 5.2.9
Enabled by Default: No
Status: Disabled
Deactivation reason: Did not meet one of the dependencies: [MessageDrivenSubscriptions]
Name: InMemoryTimeoutPersistence
Version: 5.2.9
Enabled by Default: No
Status: Disabled
Deactivation reason: Did not meet one of the dependencies: [TimeoutManager]
Name: TimeoutManagerBasedDeferral
Version: 5.2.9
Enabled by Default: No
Status: Enabled
Dependencies: None
Startup Tasks: None
Name: UnicastBus
Version: 5.2.9
Enabled by Default: Yes
Status: Enabled
Dependencies: None
Startup Tasks: None
Name: BinarySerialization
Version: 5.2.9
Enabled by Default: Yes
Status: Disabled
Deactivation reason: Did not fulfill its Prerequisites:
-BinarySerialization not enable since serialization definition not detected.
Name: BsonSerialization
Version: 5.2.9
Enabled by Default: Yes
Status: Disabled
Deactivation reason: Did not fulfill its Prerequisites:
-BsonSerialization not enable since serialization definition not detected.
Name: JsonSerialization
Version: 5.2.9
Enabled by Default: Yes
Status: Enabled
Dependencies: None
Startup Tasks: None
Name: XmlSerialization
Version: 5.2.9
Enabled by Default: Yes
Status: Disabled
Deactivation reason: Did not fulfill its Prerequisites:
-XmlSerialization not enable since serialization definition not detected.
Name: MsmqTransportConfigurator
Version: 5.2.9
Enabled by Default: No
Status: Enabled
Dependencies: None
Startup Tasks: None
Name: TimeoutManager
Version: 5.2.9
Enabled by Default: No
Status: Enabled
Dependencies: [TimeoutManagerBasedDeferral]
Startup Tasks: None
Name: Sagas
Version: 5.2.9
Enabled by Default: Yes
Status: Disabled
Deactivation reason: Did not fulfill its Prerequisites:
-No sagas was found in scanned types
Name: SecondLevelRetries
Version: 5.2.9
Enabled by Default: Yes
Status: Enabled
Dependencies: [ForwarderFaultManager]
Startup Tasks: None
Name: DataBusFileBased
Version: 5.2.9
Enabled by Default: No
Status: Disabled
Deactivation reason: Did not meet one of the dependencies: [DataBus]
Name: StorageDrivenPublishing
Version: 5.2.9
Enabled by Default: No
Status: Enabled
Dependencies: None
Startup Tasks: None
Name: MessageDrivenSubscriptions
Version: 5.2.9
Enabled by Default: No
Status: Enabled
Dependencies: None
Startup Tasks: None
编辑#2:
在应用了 David 的建议并将配置保持在最低限度之后,我仍然仅在使用 MsmqPersistence 而不是 InMemoryPersistence 时遇到异常。我没有尝试过其他持久性存储。
此异常由具有完整总线(不是 SendOnlyBus)的 MVC 应用程序抛出,配置如下:
public void ConfigureServiceBus( IContainer container, IAppBuilder app )
{
var busConfiguration = new BusConfiguration();
busConfiguration.UseContainer<AutofacBuilder>( c => c.ExistingLifetimeScope( container ) );
busConfiguration.EnableInstallers();
var inc = AllAssemblies.Matching( "Company." )
.And( "NServiceBus" )
.And( "ServiceControl" );
config.AssembliesToScan( inc );
config.UsePersistence<MsmqPersistence>();
config.UseSerialization<JsonSerializer>();
config.UseTransport<MsmqTransport>();
config.EndpointName( endpointName );
var startableBus = NServiceBus.Bus.Create( busConfiguration );
startableBus.Start();
}
Exception thrown: 'System.NullReferenceException' in NServiceBus.Core.dll Additional information: Object reference not set to an instance of an object.
调用堆栈:
ServiceBus.Core.dll!NServiceBus.Timeout.Hosting.Windows.TimeoutPersisterReceiver.Poll(object obj) Line 90 C#
MVC 中的 Autofac 配置:
public static IContainer ConfigureAutofac( IAppBuilder app )
{
ContainerBuilder builder = new ContainerBuilder();
// Register your MVC controllers.
builder.RegisterControllers( typeof( MvcApplication ).Assembly );
builder.RegisterType<...>().AsImplementedInterfaces();
//...
// Set the dependency resolver to be Autofac.
IContainer container = builder.Build();
var resolver = new Autofac.Integration.Mvc.AutofacDependencyResolver( container );
DependencyResolver.SetResolver( resolver );
return container;
}
同样,这发生在具有 MsmqPersistence 的 MVC 应用程序中,该应用程序订阅了 Some_Endpoint 发布的 events。上面提到的 WCF 主机最初向 Some_Endpoint.
发送 命令这里似乎发生了几件事,所以我将解决一些可能导致问题的要点。
程序集扫描
这段代码控制扫描哪些程序集以获得对 NServiceBus 重要的类型:
var includesBuilder = AllAssemblies.Matching( "Company.App." );
config.AssembliesToScan( includesBuilder );
如果您不小心排除了重要的程序集,这可能会导致奇怪的事情发生。使用 AllAssemblies
尝试添加 NServiceBus 程序集,但可以肯定的是您排除了任何 ServiceControl 插件。
如果可能,省略此部分并允许端点扫描目录中的所有程序集会更容易。
更好的是:
config.AssembliesToScan(AllAssemblies.Matching("Company.App.")
.And("NServiceBus")
.And("ServiceControl"));
或者更好的是,不要列入白名单,但如果绝对必要,请使用黑名单,因为您有一些疯狂的程序集,其中包含数千种您不想打扰扫描的不相关类型:
config.AssembliesToScan(AllAssemblies.Except("CrazyAssemblies"));
仅发送
在您的 WCF 代码片段中,您正在创建一个只发送总线,但您在其上方有一些奇怪的配置选择:
config.EnableInstallers(); //ensures msmq is created
config.PurgeOnStartup( true ); //only for self-hosted
config.Transactions().Disable();
config.DisableFeature<StorageDrivenPublishing>();
Bus = NServiceBus.Bus.CreateSendOnly( config ); //create SendOnlyBus here
根据定义,只发送端点不接收消息,因此它不创建队列。 EnableInstallers()
不需要,因为不需要设置队列。 PurgeOnStartup(true)
没有多大意义,因为没有要清除的队列。
此外,您在谈论 sagas 和超时队列,但仅发送端点无法处理消息,这意味着也没有 sagas。这些事情的组合可能会导致奇怪的边缘情况。
Enabling/Disabling 特点
我看到一些调用禁用了某些功能:
config.DisableFeature<SecondLevelRetries>(); //turn off for in-mem persistence, otherwise could lose messages
config.DisableFeature<StorageDrivenPublishing>();
SecondLevelRetries 是需要超时的事情之一,所以如果你禁用它并且没有传奇,我可以看到哪里可能有一个独特的设置组合会导致 InMemory 超时持续器没有被注册,这会是一个错误。
请注意,在您的功能输出中:
- InMemoryTimeoutPersistence 由于 TimeoutManager 而被禁用
- 但是,TiemoutManager 已启用。这可能可能是一个错误。
你总是可以尝试强制这个问题:
config.EnableFeature<InMemoryTimeoutPersistence>();
但通常最好让这些功能自己解决问题,而不是 enable/disable 他们单独解决问题。
夫妇相关笔记:
- 为了不丢失消息而禁用 SecondLevelRetries 有点倒退。使用内存中的持久性,您将丢失消息。只适合开发。对于生产,您应该使用其他持久性选项之一。但是,我可以看到在开发中跳过 SLR 以避免在调试时重复异常跟踪是多么有价值。
- 为什么要禁用 StorageDrivenPublishing? MSMQ 没有内置 Pub/Sub(就像 RabbitMQ 或 Azure Service Bus 那样)所以没有这个功能你将根本无法发布事件。
其他
这可能与将 Autofac 容器传递到 NServiceBus 之前的配置方式有关。很难推测,因为我看不到该代码。
我已尝试使用您提供的代码进行重现,但一直未能成功。如果上面的 none 最终可以正常工作并且可以进行简单的重现(例如,在基本的 Windows 控制台应用程序项目中创建总线)那么它应该很容易修复,或者至少确保提供更好的错误消息。
编辑:MsmqPersistence
使用 MsmqPersistence 时出现 NullReferenceException 是有道理的。 MsmqPersistence 仅包括订阅存储。它不提供其他持久化类型的实现,包括 Timeouts、Sagas、Gateway 和 Outbox。 (我可能漏掉了一个?)
无论如何,MsmqPersistence 都是遗物。不要使用它!
对于开发,您可以使用内存。对于其他环境,您应该使用 NHibernate 或 RavenDB。