0
votes

I'm new to nServiceBus.

nServiceBus version: 2.6.0.1505

I want to persist saga in database. Why this doesn't work:

public class MessageEndpoint : IConfigureThisEndpoint, AsA_Server, IWantCustomInitialization
{
    public void Init()
    {
        Configure.With().DefaultBuilder().Sagas().NHibernateSagaPersister();
    }
}

It throws an error:

Exception occurred in Topshelf.Internal.ServiceController`1[[NServiceBus.Host.Internal.GenericHost, NServiceBus.Host, Version=2.6.0.1505, Culture=neutral, PublicKeyToken=9fc386479f8a226c]] during state Initial while handling OnStart

Is it possible to configure an endpoint in this way in this version of nServiceBus?

Edit:

Endpoint configuration changed to:

public class MessageEndpoint : IConfigureThisEndpoint, 
    AsA_Server, 
    IWantCustomInitialization
{
    public void Init()
    {
        Configure.With()
            .DefaultBuilder()
            .XmlSerializer()
            .Sagas()
            .NHibernateSagaPersister();
    }
}

Saga executes, but an exception is thrown:

2012-07-30 16:36:12,229 [Worker.5] INFO NServiceBus.Unicast.UnicastBus [(null)] <(null)> - Received message Messages.StartCmd, Messages, Version=1.0.0.0, Cultu re=neutral, PublicKeyToken=null with ID 0adbb2fd-4a7d-4fa2-ae09-70bbcbbc8241\206 9 from sender MyWebClient@USER-PC 2012-07-30 16:36:12,232 [Worker.5] INFO NServiceBus.Unicast.UnicastBus [(null)] <(null)> - Can't impersonate because no windows identity specified in incoming message. This is common in interop scenarios.

2012-07-30 16:36:12,294 [Worker.5] WARN NServiceBus.Unicast.Transport.Msmq.Msmq Transport [(null)] <(null)> - Failed raising 'transport message received' event for message with ID=0adbb2fd-4a7d-4fa2-ae09-70bbcbbc8241\2069 Spring.Objects.Factory.UnsatisfiedDependencyException: Error creating object wit h name 'NServiceBus.Sagas.Impl.SagaMessageHandler' : Unsatisfied dependency expr essed through object property 'Persister': There are 2 objects of Type [NService Bus.Saga.ISagaPersister] for autowire by type, when there should have been just 1 to be able to autowire property 'Persister' of object 'NServiceBus.Sagas.Impl. SagaMessageHandler'. at Spring.Objects.Factory.Support.AbstractAutowireCapableObjectFactory.Autowi reByType(String name, RootObjectDefinition definition, IObjectWrapper wrapper, M utablePropertyValues properties) at Spring.Objects.Factory.Support.AbstractAutowireCapableObjectFactory.Popula teObject(String name, RootObjectDefinition definition, IObjectWrapper wrapper) at Spring.Objects.Factory.Support.AbstractAutowireCapableObjectFactory.Config ureObject(String name, RootObjectDefinition definition, IObjectWrapper wrapper) at Spring.Objects.Factory.Support.AbstractAutowireCapableObjectFactory.Instan tiateObject(String name, RootObjectDefinition definition, Object[] arguments, Bo olean allowEagerCaching, Boolean suppressConfigure)
at Spring.Objects.Factory.Support.AbstractObjectFactory.GetObjectInternal(Str ing name, Type requiredType, Object[] arguments, Boolean suppressConfigure) at Spring.Objects.Factory.Support.AbstractObjectFactory.GetObject(String name ) at Spring.Objects.Factory.Support.DefaultListableObjectFactory.GetObjectsOfTy pe(Type type, Boolean includePrototypes, Boolean includeFactoryObjects) at Spring.Context.Support.AbstractApplicationContext.GetObjectsOfType(Type ty pe, Boolean includePrototypes, Boolean includeFactoryObjects) at NServiceBus.ObjectBuilder.Spring.SpringObjectBuilder.NServiceBus.ObjectBui lder.Common.IContainer.Build(Type typeToBuild) at NServiceBus.ObjectBuilder.Common.CommonObjectBuilder.NServiceBus.ObjectBui lder.IBuilder.BuildAndDispatch(Type typeToBuild, Action`1 action)
at NServiceBus.Unicast.UnicastBus.DispatchMessageToHandlersBasedOnType(IMessa ge toHandle, Type messageType) at NServiceBus.Unicast.UnicastBus.HandleMessage(TransportMessage m) at NServiceBus.Unicast.UnicastBus.TransportMessageReceived(Object sender, Tra nsportMessageReceivedEventArgs e) at NServiceBus.Unicast.Transport.Msmq.MsmqTransport.OnTransportMessageReceive d(TransportMessage msg)

Looks like this is the reason why it fails:

There are 2 objects of Type [NService Bus.Saga.ISagaPersister] for autowire by type, when there should have been just 1 to be able to autowire property 'Persister' of object 'NServiceBus.Sagas.Impl. SagaMessageHandler'

1
Did you check out the Saga example that ships with NSB? Do you have the Saga configuration set?Davin Tryon
I have NHibernateSagaPersisterConfig section in config file.denis_n

1 Answers

1
votes

Here is how to persist saga using NHibernate.

Endpoint configuration (doesn't require IWantCustomInitialization):

public class MessageEndpoint : IConfigureThisEndpoint, AsA_Server
{
}

The trick is to tell the host to use Production profile - http://docs.particular.net/nservicebus/hosting/nservicebus-host/profiles

enter image description here