Исключение в RavenDB.SagaPersister.Save, Guid должен содержать 32 цифры с 4 дефисами. Гайд в Raven пуст

NServiceBus 5.1, постоянство RavenDB, контейнер AutoFac, log4net, все последние версии в NuGet на момент публикации.

Конечная точкаКонфигурация:

            log4net.Config.XmlConfigurator.Configure();
        LogManager.Use<Log4NetFactory>();

        // Raven DataStore for Freight system
        var freightDataStore = new DocumentStore { 
            ConnectionStringName = "RavenDB",
            DefaultDatabase = "ProTeria.Freight"
        };
        freightDataStore.Initialize();
        freightDataStore.Conventions.IdentityPartsSeparator = "-";
        Raven.Client.Indexes.IndexCreation.CreateIndexes(typeof(ProTeria.NET.RavenDB.BringInvoiceIndexes.BringInvoiceIndexBringIdAndStatus).Assembly, freightDataStore);

        // Raven DataStore for NServiceBus
        var nsbDataStore = new DocumentStore
        {
            ConnectionStringName = "NServiceBus.Persistence",
            DefaultDatabase = "Freight.BookingProcessing"
        };
        nsbDataStore.Initialize();

        // Set up and build AutoFac container
        var builder = new ContainerBuilder();
        builder.RegisterInstance<DocumentStore>(freightDataStore).As<IDocumentStore>().SingleInstance();
        builder.Register(c => 
        {
            var reportsService = new ReportsService();
            return reportsService;
        })
            .As<IReportsService>()
            .SingleInstance();
        builder.Register(c =>
        {
            var getCalcShippingTask = new GetCalculatedShippingReportTask(c.Resolve<IReportsService>(), c.Resolve<IBus>(), c.Resolve<IDocumentStore>());
            return getCalcShippingTask;
        });
        var container = builder.Build();

        // Set up NServiceBus
        configuration.UseContainer<AutofacBuilder>(customizations => customizations.ExistingLifetimeScope(container));
        configuration.Conventions()
            .DefiningCommandsAs(t => t.Namespace != null && t.Namespace.EndsWith("Commands"))
            .DefiningEventsAs(t => t.Namespace != null && t.Namespace.EndsWith("Events"))
            .DefiningMessagesAs(t => t.Namespace != null && t.Namespace.EndsWith("Messages"));
        configuration.UsePersistence<RavenDBPersistence>().SetDefaultDocumentStore(nsbDataStore);
    }
  1. Расписание NServiceBus с помощью Bus.Send()
  2. ACommand запускает Saga 2a. ACommand обрабатывается, внутри обработчика вызов RequestTimeout(InvoiceCreationTimeout)
  3. Обработчик ACommand, кажется, возвращается нормально.
  4. В какой-то момент после моего кода в обработчике ACommand я получаю FormatException в журналах.

Я проверил базу данных, и саги не хранятся, только TimeoutDatas, например:

  "Destination": {
    "Queue": "Freight.BookingProcessing",
    "Machine": "TRYGVEXISHAN"
  },
  "SagaId": "00000000-0000-0000-0000-000000000000",
  "State": "PD94bWwgdmVyc2lvbj0iMS4wIiA/Pg0KPFNjaGVkdWxlZFRhc2sgeG1sbnM6eHNpPSJodHRwOi8vd3d3LnczLm9yZy8yMDAxL1hNTFNjaGVtYS1pbnN0YW5jZSIgeG1sbnM6eHNkPSJodHRwOi8vd3d3LnczLm9yZy8yMDAxL1hNTFNjaGVtYSIgeG1sbnM9Imh0dHA6Ly90ZW1wdXJpLm5ldC9OU2VydmljZUJ1cy5TY2hlZHVsaW5nLk1lc3NhZ2VzIj4KPFRhc2tJZD5kMjk0ZjJlNC0wNDNhLTQ2ZDctYWRlYy0zNGQ5YTRiMzA4N2E8L1Rhc2tJZD4KPE5hbWU+SW52b2ljZVJlcG9ydE9yZGVyU2NoZWR1bGVyPC9OYW1lPgo8RXZlcnk+UFQxSDwvRXZlcnk+CjwvU2NoZWR1bGVkVGFzaz4K",
  "Time": "2014-11-06T20:00:54.7501480Z",
  "OwningTimeoutManager": "Freight.BookingProcessing",
  "Headers": {
    "NServiceBus.MessageId": "04c57504-ef24-4c35-9808-a3db0149d727",
    "NServiceBus.CorrelationId": "04c57504-ef24-4c35-9808-a3db0149d727",
    "NServiceBus.MessageIntent": "Send",
    "NServiceBus.Version": "5.1.0",
    "NServiceBus.TimeSent": "2014-11-06 19:00:54:737148 Z",
    "NServiceBus.ContentType": "text/xml",
    "NServiceBus.EnclosedMessageTypes": "NServiceBus.Scheduling.Messages.ScheduledTask, NServiceBus.Core, Version=5.0.0.0, Culture=neutral, PublicKeyToken=9fc386479f8a226c",
    "CorrId": "04c57504-ef24-4c35-9808-a3db0149d727\\0",
    "NServiceBus.ConversationId": "fb886123-ef8b-49f0-a841-a3db0149d728",
    "WinIdName": "TrygveXishan\\Trygve",
    "NServiceBus.OriginatingMachine": "TRYGVEXISHAN",
    "NServiceBus.OriginatingEndpoint": "Freight.BookingProcessing",
    "$.diagnostics.originating.hostid": "5b9e6ee62b8ad8151326abdad567014e",
    "NServiceBus.IsDeferredMessage": "True",
    "NServiceBus.Timeout.RouteExpiredTimeoutTo": "Freight.BookingProcessing@TRYGVEXISHAN",
    "NServiceBus.Timeout.Expire": "2014-11-06 20:00:54:750148 Z"
  }

EDIT Вывод журнала (теперь с SagaId, зарегистрированным в обработчике ACommand (настоящее имя — OrderInvoiceCommand):

    2014-11-07 10:53:49,601 [22] DEBUG Freight.BookingProcessing.InvoiceReporting.InvoiceReportSaga [(null)] <(null)> - Handling OrderInvoiceCommand which starts saga. Saga data: Saga Id: cdd0b4ed-d310-41fa-a8dd-a3dc00b3942f
BringInvoiceId: 702542157
OriginalMessageId: 52a7b74d-5e7c-4e7b-bc03-a3dc00b2cd72
2014-11-07 10:53:49,844 [22] DEBUG Freight.BookingProcessing.InvoiceReporting.InvoiceReportSaga [(null)] <(null)> - Invoice with id 702542157 not found in DB, as Bring to generate and request a timeout for checking generation status
<removed some BehaviorChain entries>
2014-11-07 10:53:50,530 [22] DEBUG NServiceBus.BehaviorChain`1 [(null)] <(null)> - LogOutgoingMessageBehavior
2014-11-07 10:53:50,532 [22] DEBUG LogOutgoingMessage [(null)] <(null)> - Sending message 'Freight.BookingProcessing.InvoiceReporting.InvoiceCreationTimeout, Freight.BookingProcessing, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null' with id '226603e6-8b1e-4dec-ae94-a3dc00b39545' to destination 'Freight.BookingProcessing@TRYGVEXISHAN'.
ToString() of the message yields: Freight.BookingProcessing.InvoiceReporting.InvoiceCreationTimeout
Message headers:
NServiceBus.SagaId:cdd0b4ed-d310-41fa-a8dd-a3dc00b3942f, NServiceBus.IsSagaTimeoutMessage:True, NServiceBus.SagaType:Freight.BookingProcessing.InvoiceReporting.InvoiceReportSaga, Freight.BookingProcessing, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null, NServiceBus.OriginatingSagaId:cdd0b4ed-d310-41fa-a8dd-a3dc00b3942f, NServiceBus.OriginatingSagaType:Freight.BookingProcessing.InvoiceReporting.InvoiceReportSaga, Freight.BookingProcessing, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null
2014-11-07 10:53:50,535 [22] DEBUG NServiceBus.BehaviorChain`1 [(null)] <(null)> - DispatchMessageToTransportBehavior
2014-11-07 10:53:50,550 [22] DEBUG NServiceBus.BehaviorChain`1 [(null)] <(null)> - LicenseBehavior
2014-11-07 10:53:51,024 [22] INFO  NServiceBus.Unicast.Transport.TransportReceiver [(null)] <(null)> - Failed to process message
System.FormatException: Guid should contain 32 digits with 4 dashes (xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx).
   at System.Guid.GuidResult.SetFailure(ParseFailureKind failure, String failureMessageID, Object failureMessageFormatArgument, String failureArgumentName, Exception innerException)
   at System.Guid.TryParseGuidWithNoStyle(String guidString, GuidResult& result)
   at System.Guid.TryParseGuid(String g, GuidStyles flags, GuidResult& result)
   at System.Guid..ctor(String g)
   at Raven.Client.Converters.GuidConverter.ConvertTo(String value)
   at Raven.Client.Document.GenerateEntityIdOnTheClient.SetPropertyOrField(Type propertyOrFieldType, Object entity, Action`1 setIdentifier, String id)
   at Raven.Client.Document.GenerateEntityIdOnTheClient.TrySetIdentity(Object entity, String id)
   at Raven.Client.Document.GenerateEntityIdOnTheClient.GenerateDocumentKeyForStorage(Object entity)
   at Raven.Client.Document.InMemoryDocumentSessionOperations.StoreInternal(Object entity, Etag etag, String id, Boolean forceConcurrencyCheck)
   at Raven.Client.Document.InMemoryDocumentSessionOperations.Store(Object entity)
   at NServiceBus.SagaPersisters.RavenDB.SagaPersister.Save(IContainSagaData saga) in c:\BuildAgent\work\9b594c1b0f1d3bab\src\NServiceBus.RavenDB\SagaPersister\SagaPersister.cs:line 22
   at NServiceBus.SagaPersistenceBehavior.Invoke(IncomingContext context, Action next) in c:\BuildAgent\work\1b05a2fea6e4cd32\src\NServiceBus.Core\Sagas\SagaPersistenceBehavior.cs:line 116

person Trygve    schedule 06.11.2014    source источник
comment
Похоже, что sagaId имеет значение Guid.Empty, когда персистент пытается его сохранить. Можете ли вы зарегистрировать идентификатор саги в методе обработки, чтобы проверить, так ли это?   -  person Andreas Öhlund    schedule 07.11.2014
comment
SagaId не пуст в SagaData, я обновил вывод журнала.   -  person Trygve    schedule 07.11.2014


Ответы (1)


Я понял. Это было

freightDataStore.Conventions.IdentityPartsSeparator = "-";

это одурачило Рейвен, так как сгенерированный идентификатор, вероятно, выглядел бы примерно так: InvoiceSaga-cdd0b4ed-d310-41fa-a8dd-a3dc00b3942f.

EDIT Это можно решить, зарегистрировав пользовательский Raven.Client.Converters.ITypeConverter для Guid в DocumentStore.Conventions.IdentityProviders. См. отправленный вопрос Raven и этот вопрос SO для получения дополнительной информации

Но я пока не знаю, ПОЧЕМУ NSB использует фрахтдатастор, а не нсбдатасторе для сохранения саги. Возможно, я неправильно понял, как настроить NSB с двумя разными IDataStore, зарегистрированными в контейнере? Любое руководство по этому поводу?

EDIT Для этого я создал отдельный вопрос: Как настроить NServiceBus с двумя RavenDB IDocumentStore?

person Trygve    schedule 07.11.2014