0

I have a saga data class with one property marked by Unique attribute. However, this didn't prevent NServiceBus from creating several sagas with identical values in this field.

Here is my data class:

public class ModuleAliveSagaData : ContainSagaData
{
    [Unique]
    public string ModuleId { get; set; }
    public string Endpoint { get; set; }
    public string Module { get; set; }
    public DateTime LastCheck { get; set; }
    public bool Warning { get; set; }
    public bool Error { get; set; }
}

Here is the mapping:

public override void ConfigureHowToFindSaga()
{
    ConfigureMapping<ModuleAliveMessage>(m => m.Id).ToSaga(s => s.ModuleId);
}

Here is how data gets its values:

    public void Handle(ModuleStartedMessage message)
    {
        Log.InfoFormat("Module {0} started on {1} at {2}", message.ModuleName, message.Endpoint, message.Timestamp);
        Data.ModuleId = message.Id;
        Data.Endpoint = message.Endpoint;
        Data.Module = message.ModuleName;
        Data.LastCheck = DateTime.Now;
        Data.Warning = false;
        Bus.SendLocal(new SendNotification
        {
            Subject = string.Format("Module {0} is online at {1}", Data.Module, Data.Endpoint)
        });
        RequestTimeout<ModuleCheckTimeout>(TimeSpan.FromMinutes(5));
        Bus.Publish(new ModuleActivated
        {
            Endpoint = message.Endpoint,
            Module = message.ModuleName
        });
    }

And here is what I see in the saga persistence table (Azure table storage):

Does it suppose to work like this or may be I am missing something?

enter image description here

Alexey Zimarev
  • 17,944
  • 2
  • 55
  • 83
  • Can you share you code somewhere (or a repro code)? – Sean Farmar Feb 14 '15 at 08:28
  • I created a repository here https://github.com/alexeyzimarev/SagaUniqueTest. It sends a message that triggers new saga every 30 seconds. Message unique attribute value is the same for all these messages, however new saga is created each time. – Alexey Zimarev Feb 14 '15 at 16:22
  • Alexey, azure storage cannot check for uniquess besides the partitionkey/rowkey pair, so that attribute is ignored. If you need uniqueness you will have to consider another storage techology. PS: this is a known limitation of the underlying storage: https://github.com/Particular/NServiceBus.Azure/issues/21 – Yves Goeleven Feb 16 '15 at 13:58
  • Thanks Yves, I started to suspect this when I as thinking about the underlying technology. I wanted to try RavenDb subscription storage but we use v3 for the application itself, which gets in conflict with v2 client that is embedded in NServiceBus 4.7 that we use. I managed to create a workaround for this problem that is OK for now. If you create an answer to this question I will mark it so if someone gets this issue, they know what the answer is :) – Alexey Zimarev Feb 16 '15 at 17:20

1 Answers1

0

Yves wrote this in comments, basically it is the proper answer:

Azure storage cannot check for uniquess besides the partitionkey/rowkey pair, so that attribute is ignored. If you need uniqueness you will have to consider another storage techology. PS: this is a known limitation of the underlying storage: http://github.com/Particular/NServiceBus.Azure/issues/21

Alexey Zimarev
  • 17,944
  • 2
  • 55
  • 83