我正在努力解决我在启动时从NServiceBus.Host获取的错误消息,并且不确定我哪里出错了。我最初在一个大型项目中遇到了这个问题,但我似乎能够从头开始重现这个问题。
在VS2012中,从为.NET 4.6.2设置的新C#类库项目开始。然后添加NuGet包 - NServiceBus(6.0.0),NServiceBus.Host(7.0.1)和NServiceBus.NHibernate(7.2.0)。
然后编辑EndpointConfiguration
类如下:
using NServiceBus.Features;
using NServiceBus.Persistence;
namespace NSB6_Pure
{
using NServiceBus;
public class EndpointConfig : IConfigureThisEndpoint
{
public void Customize(EndpointConfiguration endpointConfiguration)
{
//TODO: NServiceBus provides multiple durable storage options, including SQL Server, RavenDB, and Azure Storage Persistence.
// Refer to the documentation for more details on specific options.
endpointConfiguration.UsePersistence<NHibernatePersistence, StorageType.Timeouts>();
endpointConfiguration.DisableFeature<MessageDrivenSubscriptions>();
endpointConfiguration.DisableFeature<Sagas>();
// NServiceBus will move messages that fail repeatedly to a separate "error" queue. We recommend
// that you start with a shared error queue for all your endpoints for easy integration with ServiceControl.
endpointConfiguration.SendFailedMessagesTo("error");
// NServiceBus will store a copy of each successfully process message in a separate "audit" queue. We recommend
// that you start with a shared audit queue for all your endpoints for easy integration with ServiceControl.
endpointConfiguration.AuditProcessedMessagesTo("audit");
}
}
}
然后编译(在本例中为调试版本),并从命令提示符尝试在NServiceBus.Host.exe
目录中运行bin\Debug
。就我而言,我得到了这个输出,其中大部分都是红色的:
2017-04-28 12:46:11.876 INFO DefaultFactory Logging to 'C:\blah\bin\Debug\' with level Info
2017-04-28 12:46:13.446 FATAL NServiceBus.LicenseManager Your license has expire
d! You can renew it at https://particular.net/licensing.
2017-04-28 12:46:13.561 ERROR NServiceBus.GenericHost Exception when starting en
dpoint.
System.InvalidOperationException: In order to use NServiceBus with NHibernate yo
u need to provide at least one connection string. You can do it via (in order of
precedence):
* specifying 'NServiceBus/Persistence/NHibernate/Saga' connection string for th
e Saga persister
* specifying 'NServiceBus/Persistence' connection string that applies to all pe
rsisters
* specifying 'NServiceBus/Persistence/connection.connection_string' or 'NServic
eBus/Persistence/connection.connection_string_name' value in AppSettings or your
NHibernate configuration file.
For most scenarios the 'NServiceBus/Persistence' connection string is the best o
ption.
at NServiceBus.Persistence.NHibernate.NHibernateConfigurationBuilder.Validate
ConfigurationViaConfigFile(Configuration configuration, String configPrefix) in
C:\BuildAgent\work\5135de308b2f3016\src\NServiceBus.NHibernate\Internal\NHiberna
teConfigurationBuilder.cs:line 130
at NServiceBus.Features.NHibernateStorageSession.Setup(FeatureConfigurationCo
ntext context) in C:\BuildAgent\work\5135de308b2f3016\src\NServiceBus.NHibernate
\SynchronizedStorage\NHibernateStorageSession.cs:line 45
at NServiceBus.Features.FeatureActivator.ActivateFeature(FeatureInfo featureI
nfo, List`1 featuresToActivate, IConfigureComponents container, PipelineSettings
pipelineSettings) in C:\Build\src\NServiceBus.Core\Features\FeatureActivator.cs
:line 194
at NServiceBus.Features.FeatureActivator.SetupFeatures(IConfigureComponents c
ontainer, PipelineSettings pipelineSettings) in C:\Build\src\NServiceBus.Core\Fe
atures\FeatureActivator.cs:line 57
at NServiceBus.InitializableEndpoint.<Initialize>d__1.MoveNext() in C:\Build\
src\NServiceBus.Core\InitializableEndpoint.cs:line 50
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNot
ification(Task task)
at NServiceBus.GenericHost.<Start>d__1.MoveNext() in C:\BuildAgent\work\fc89e
968acb99302\src\NServiceBus.Hosting.Windows\GenericHost.cs:line 48
2017-04-28 12:46:13.582 ERROR NServiceBus.Hosting.Windows.WindowsHost Start fail
ure
System.InvalidOperationException: In order to use NServiceBus with NHibernate yo
u need to provide at least one connection string. You can do it via (in order of
precedence):
* specifying 'NServiceBus/Persistence/NHibernate/Saga' connection string for th
e Saga persister
* specifying 'NServiceBus/Persistence' connection string that applies to all pe
rsisters
* specifying 'NServiceBus/Persistence/connection.connection_string' or 'NServic
eBus/Persistence/connection.connection_string_name' value in AppSettings or your
NHibernate configuration file.
For most scenarios the 'NServiceBus/Persistence' connection string is the best o
ption.
at NServiceBus.Persistence.NHibernate.NHibernateConfigurationBuilder.Validate
ConfigurationViaConfigFile(Configuration configuration, String configPrefix) in
C:\BuildAgent\work\5135de308b2f3016\src\NServiceBus.NHibernate\Internal\NHiberna
teConfigurationBuilder.cs:line 130
at NServiceBus.Features.NHibernateStorageSession.Setup(FeatureConfigurationCo
ntext context) in C:\BuildAgent\work\5135de308b2f3016\src\NServiceBus.NHibernate
\SynchronizedStorage\NHibernateStorageSession.cs:line 45
at NServiceBus.Features.FeatureActivator.ActivateFeature(FeatureInfo featureI
nfo, List`1 featuresToActivate, IConfigureComponents container, PipelineSettings
pipelineSettings) in C:\Build\src\NServiceBus.Core\Features\FeatureActivator.cs
:line 194
at NServiceBus.Features.FeatureActivator.SetupFeatures(IConfigureComponents c
ontainer, PipelineSettings pipelineSettings) in C:\Build\src\NServiceBus.Core\Fe
atures\FeatureActivator.cs:line 57
at NServiceBus.InitializableEndpoint.<Initialize>d__1.MoveNext() in C:\Build\
src\NServiceBus.Core\InitializableEndpoint.cs:line 50
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNot
ification(Task task)
at NServiceBus.GenericHost.<Start>d__1.MoveNext() in C:\BuildAgent\work\fc89e
968acb99302\src\NServiceBus.Hosting.Windows\GenericHost.cs:line 54
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNot
ification(Task task)
at NServiceBus.Hosting.Windows.WindowsHost.Start() in C:\BuildAgent\work\fc89
e968acb99302\src\NServiceBus.Hosting.Windows\WindowsHost.cs:line 33
我关注的一点就是:
为了将NServiceBus与NHibernate一起使用,您需要提供至少一个连接字符串。您可以通过(按优先顺序)来完成:
- 指定&#39; NServiceBus / Persistence / NHibernate / Saga&#39; Saga persister的连接字符串
我已检查过NServiceBus代码 - 这不是通用消息。如果问题是缺少Timeouts 1 的配置,我确定它会讨论它而不是Saga,因为错误消息的那部分是参数化的。
但我不想在这个特定的项目中使用Sagas。我以为DisableFeature<Sagas>
足以向NServiceBus表明我不想在这里使用传奇,但显然不是。
那么为什么NServiceBus尝试配置Saga存储,更重要的是,我该如何阻止它呢?
1 当然,我期待发生这样的错误,因为我还没有做过任何事情,比如甚至添加app.config
班级图书馆。因此,即使Saga问题得到解决,我也希望这段代码仍能产生错误。希望我可以找出如何解决自己的问题。
(我想避免配置任何存储的基本原理是,真正的工作是升级一些现有的端点,这些端点为每个功能(超时/订阅/ Sagas)提供专用数据库,尽管我一直在推荐有一段时间我们应该合并这些数据库,因此可以为每个端点配置一个NServiceBus/Persistence
数据库,但这还没有被批准。但是我不愿意添加另一个< / em>这些端点的数据库,当它们目前只使用超时时)
答案 0 :(得分:1)
我必须承认我对NServiceBus知之甚少,我只是觉得有必要在他们提问时帮助那些声誉很高的人:)所以我没有解释为什么它会像这样工作,只有在它失败的地方。在堆栈跟踪中,您可以看到NHibernateStorageSession.Setup
,NHibernateStorageSession
是其中一项功能。因此在尝试激活该功能时失败。 Setup
就像这样开始:
protected override void Setup(FeatureConfigurationContext context)
{
NHibernateConfiguration config = new NHibernateConfigurationBuilder(context.Settings, "Saga", new string[1]
{
"StorageConfiguration"
}).Build();
// the rest
}
其中第二个参数是连接字符串后缀。在这种情况下,它被硬编码为“Saga”,如您所见 - 没有检查Sagas
功能是否已启用。 NHibernateConfigurationBuilder
然后尝试为saga(或任何更一般的连接字符串)找到连接字符串,但是没有使用您观察到的异常消息这样做。
如此简单的解决方案是通过
禁用该功能endpointConfiguration.DisableFeature<NHibernateStorageSession>();
但是,您应该注意并确保您需要的功能不依赖于该功能。对我来说这个功能的用途并不完全清楚,我没有找到任何相关的文档(当然它的名字告诉我们它的用途)。
答案 1 :(得分:1)
我是特别软件的开发人员,NServiceBus的制造商Dennis van der Stelt。我已经回复了你的支持案例,但也希望更新这个问题,以便其他人也可以找到这个问题。 Evk已经提到了大部分内容,我只是想提一下GH问题和完整的代码。
以下代码配置确保它不会抱怨saga连接字符串。
endpointConfiguration.DisableFeature<NHibernateStorageSession>();
endpointConfiguration.DisableFeature<MessageDrivenSubscriptions>();
endpointConfiguration.DisableFeature<Sagas>();
endpointConfiguration.UsePersistence<NHibernatePersistence, StorageType.Timeouts>();
然后只提供超时的连接字符串
<add name="NServiceBus/Persistence/NHibernate/Timeout" connectionString="server=.\sqlexpress;database=nservicebus; Trusted_Connection=True;" />
这将使其正常运作并符合预期。
禁用NHibernateStorageSession是必要的原因是因为它是启用的持久性内部的一个功能。更多信息可以在我根据此案例which can be found here创建的GitHub问题中找到。
答案 2 :(得分:0)
你可以通过(按优先顺序):
这只是意味着第一个点优先于另一个,如果你需要设置Saga,否则只需要做其中一个点:
- 指定&#39; NServiceBus / Persistence&#39;适用于所有持久性的连接字符串
- 指定&#39; NServiceBus / Persistence / connection.connection_string&#39;或者&#39; NServiceBus / Persistence / connection.connection_string_name&#39; AppSettings或NHibernate配置文件中的值。
对于大多数情况,&nbsp; NServiceBus / Persistence&#39;连接字符串是最佳选择。
因此您不需要设置Saga,但看起来您不会避免在某处设置连接字符串。