RavenDB.SagaPersister.Save中的例外情况,“Guid应该包含带有4个破折号的32位数字”。 Raven里的Guid是空的

时间:2014-11-06 19:32:21

标签: nservicebus nservicebus-sagas

NServiceBus 5.1,RavenDB持久性,AutoFac容器,log4net,发布时NuGet中的所有最新版本。

EndpointConfig:

            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. 使用Bus.Send()
  2. 的NServiceBus时间表
  3. ACommand开始传奇 2A。处理ACommand,在处理程序内调用RequestTimeout(InvoiceCreationTimeout)
  4. ACommand处理程序似乎恢复正常。
  5. 在我的ACommand处理程序代码之后的某个时刻,我在日志中得到了一个FormatException。
  6. 我检查了数据库并且没有存储传单,只有TimeoutDatas,f.ex:

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

    修改 日志输出(现在使用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
    

1 个答案:

答案 0 :(得分:0)

我明白了。这是

freightDataStore.Conventions.IdentityPartsSeparator = "-";

愚弄了Raven,因为生成的id可能看起来像InvoiceSaga-cdd0b4ed-d310-41fa-a8dd-a3dc00b3942f。

编辑这可以通过使用DocumentStore.Conventions.IdentityProviders为Guid注册自定义Raven.Client.Converters.ITypeConverter来解决。有关详细信息,请参阅submitted Raven issuethis SO question

但为什么NSB使用freightDataStore而不是nsbDataStore来持久保存这些传奇,我还不知道。我可能误解了如何使用容器中注册的两个不同的IDataStore配置NSB?对此有何指导?

编辑我为此创建了一个单独的问题:How to configure NServiceBus with two RavenDB IDocumentStores?