Why should I keep Saga?

I am struggling with the error message I get from NServiceBus.Host during startup and am not sure where I am going wrong. I first ran into the problem on a large project, but it looks like I was able to reproduce this from scratch.

In VS2012, start with a new C # Class Library project installed for .NET 4.6.2. Then add NuGet packages - NServiceBus (6.0.0), NServiceBus.Host (7.0.1) and NServiceBus.NHibernate (7.2.0).

Then edit the class EndpointConfiguration

like this:

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");
    }
  }
}

      

Then compile (in this case a debug build) and on the command line try running NServiceBus.Host.exe

in the directory bin\Debug

. In my case, I get this output, most of it in Red:

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

      

And the bit I'm focusing on is here:

To use NServiceBus with NHibernate, you need to provide at least one connection string. You can do it via (in order of priority):

  • specifying the NServiceBus / Persistence / NHibernate / Saga connection string for the Saga predicate

I checked the NServiceBus code - this is not a generic post. If the problem was a lack of configuration for Timeouts 1 I'm sure this will talk about this and not about Saga, as this part of the error message is parameterized.

But I don't want to use Sagas on this particular project. I would think it DisableFeature<Sagas>

would be enough to tell NServiceBus that I don't want to use sagas here, but apparently not.

So why is NServiceBus trying to set up the Saga store and more importantly, how do I stop it?


1 Of course I am expecting such an error to appear since I didnโ€™t do anything, even adding app.config

to the class library. So even when the Saga problem is solved, I expect this code to still contain bugs. I hope that I can work out how to fix myself.

(The rationale for my wanting to avoid setting up any storage is that the real work is to update some of the existing endpoints that have dedicated databases for each feature (timeouts / subscriptions / sagas), and although I recommended at the time how are we supposed to merge these databases and thus just set up a database NServiceBus/Persistence

for each endpoint that has not been approved. But I don't want to add another database for some of these endpoints when they only use timeouts at the moment)

+3


source to share


3 answers


I have to admit that I have little knowledge of NServiceBus, I just feel obligated to help people with high reputations when they ask questions :) So I have no explanation why it works like this, only where it fails. the stack you can see NHibernateStorageSession.Setup

, and NHibernateStorageSession

- one of the functions. So when trying to activate this feature it doesn't work. Setup

starts like this:

protected override void Setup(FeatureConfigurationContext context)
{
  NHibernateConfiguration config = new NHibernateConfigurationBuilder(context.Settings, "Saga", new string[1]
  {
    "StorageConfiguration"
  }).Build();
  // the rest
}

      

Where the second parameter is the connection string suffix. In this case, it is tightly tied to the Saga, and as you can see, there is no check that the feature is Sagas

enabled or not. NHibernateConfigurationBuilder

then tries to find the connection string for the saga (or any other generic connection string) and fails with the exception message you are seeing.



So a simple solution is to disable this feature with

endpointConfiguration.DisableFeature<NHibernateStorageSessioโ€Œโ€‹n>();

      

However, you should take care to provide you with functionality that does not depend on this feature. It's not entirely clear to me what this function is for, and I haven't found any documentation for it (although, of course, its name tells us its purpose).

+1


source


I'm Dennis van der Stealth, a custom software developer, creator of NServiceBus. I already answered your support statement, but wanted to update this question as well so others can find it. Evk mentioned this the most, I just wanted to mention the GH issue and the complete code.

The following code configuration ensures that it doesn't complain about the saga connection string.

    endpointConfiguration.DisableFeature<NHibernateStorageSession>();
    endpointConfiguration.DisableFeature<MessageDrivenSubscriptions>();
    endpointConfiguration.DisableFeature<Sagas>();
    endpointConfiguration.UsePersistence<NHibernatePersistence, StorageType.Timeouts>();

      

Then just provide the connection string for the timeouts



<add name="NServiceBus/Persistence/NHibernate/Timeout" connectionString="server=.\sqlexpress;database=nservicebus; Trusted_Connection=True;" />

      

This will do the job as expected and as expected.

The reason to disable NHibernateStorageSession is necessary because it is a function inside the included one. More details can be found in the GitHub release I created based on this case, which can be found here .

+1


source


You can do it via (in order of priority):

It just means that the first point will take precedence over the other if you need to install Saga, but otherwise just do one of the other points:

  • specifying the NServiceBus / Persistence connection string that applies to all persian
  • specifying "NServiceBus / Persistence / connection.connection_string" or "NServiceBus / Persistence / connection.connection_string_name" in AppSettings or in NHibernate configuration file.

For most scenarios, the NServiceBus / Persistence connection string is the best choice.

This way you don't have to configure Saga, but it looks like you don't want to set up a connection string anywhere.

0


source







All Articles