gpt4 book ai didi

c# - 为什么我需要任何 Saga 存储?

转载 作者:行者123 更新时间:2023-11-30 16:44:22 33 4
gpt4 key购买 nike

我正在努力处理在启动期间从 NServiceBus.Host 收到的错误消息,但我不确定我哪里出错了。我最初在一个大型项目中遇到了这个问题,但我似乎能够从头开始重现这个问题。

在 VS2012 中,从一个新的 C# 类库项目开始,为 .NET 4.6.2 设置。然后添加 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.exebin\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

我关注的是这里:

In order to use NServiceBus with NHibernate you 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 the Saga persister

我已经检查了 NServiceBus 代码 - 这不是一条通用消息。如果问题是缺少 Timeouts1 的配置,我确定它会谈论它而不是 Saga,因为错误消息的那部分是参数化的。

但我不想在这个特定项目中使用 Sagas。我本以为DisableFeature<Sagas>足以向 NServiceBus 表明我不想在这里使用 sagas,但显然不是。

那么为什么 NServiceBus 会尝试配置 Saga 存储,更重要的是,我该如何阻止它这样做呢?


1当然,我预计会发生这样的错误,因为我还没有做任何事情,比如添加 app.config。到类(class)图书馆了。因此,即使 Saga 问题得到解决,我预计这段代码仍会产生错误。只是希望我可以自己解决问题。

(我想避免配置任何存储背后的基本原理是,真正要做的是升级一些现有端点,这些端点为每个功能(超时/订阅/Sagas)提供专用数据库,尽管我一直在推荐虽然我们应该合并这些数据库,因此可以为每个端点配置一个 NServiceBus/Persistence 数据库,但尚未获得批准。但我不愿意为其中一些端点添加另一个数据库他们目前只使用超时)

最佳答案

我是 Dennis van der Stelt,是 Particular Software 的开发人员,NServiceBus 的制造商。我已经回复了你的支持案例,但也想更新这个问题,以便其他人也能找到它。 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 是必要的原因是因为它是启用的持久器中的一个功能。更多信息可以在我根据此案例创建的 GitHub 问题中找到,which can be found here .

关于c# - 为什么我需要任何 Saga 存储?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43680632/

33 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com