Service Fabric Persistence Sagas

Component: Service Fabric Persistence | Nuget: NServiceBus.Persistence.ServiceFabric (Version: 1-pre)
Target NServiceBus Version: 6.x
This page targets a pre-release version and is subject to change prior to the final release.

Reliable collections

Saga data is stored in reliable dictionaries.

Saga data serialization

Saga data in stored in JSON format using Json.NET.

Saga data serialization can be configured by providing custom JsonSerializerSettings instance

Edit
var persistence = endpointConfiguration.UsePersistence<ServiceFabricPersistence>();

var sagaSettings = persistence.SagaSettings();
sagaSettings.JsonSettings(new JsonSerializerSettings
{
    TypeNameHandling = TypeNameHandling.Auto,
    Converters =
    {
        new IsoDateTimeConverter
        {
            DateTimeStyles = DateTimeStyles.RoundtripKind
        }
    }
});

custom JsonReader instance

Edit
var persistence = endpointConfiguration.UsePersistence<ServiceFabricPersistence>();

var sagaSettings = persistence.SagaSettings();
sagaSettings.ReaderCreator(
    readerCreator: textReader =>
    {
        return new JsonTextReader(textReader);
    });

or custom JsonWriter instance

Edit
var persistence = endpointConfiguration.UsePersistence<ServiceFabricPersistence>();

var sagaSettings = persistence.SagaSettings();
sagaSettings.WriterCreator(
    writerCreator: builder =>
    {
        var writer = new StringWriter(builder);
        return new JsonTextWriter(writer)
        {
            Formatting = Formatting.None
        };
    });

Saga data storage

By default saga data stored in multiple reliable collections - one per saga data type. Reliable collection name can be changed at the level of saga data type

Edit
[ServiceFabricSaga(CollectionName = "custom-collection-name")]
public class CustomCollectionNameSaga :
    Saga<CustomCollectionNameSaga.SagaData>,
    IHandleMessages<Message>
{
    public Task Handle(Message message, IMessageHandlerContext context)
    {
        return Task.FromResult(0);
    }

Saga data identifier used as a key in reliable dictionary gets calculated, among others, from saga data type name. As a result, renaming saga data class name changes storage identifier for every saga data instance. This is a problem especially when some saga data instances have already been stored for a given saga data type. In such scenarios it is necessary to provide stable saga data type name

Edit
[ServiceFabricSaga(SagaDataName = "saga-data-name")]
public class ExplicitSagaDataNameSaga :
    Saga<ExplicitSagaDataNameSaga.SagaData>,
    IHandleMessages<Message>
{
    public Task Handle(Message message, IMessageHandlerContext context)
    {
        return Task.FromResult(0);
    }

Last modified