Prevent Starting Message from trying to find matching saga?


Based on IAmStartedByMessage should require a mapping · Issue #2442 · Particular/NServiceBus · GitHub, it seems that all messages need a mapping in ConfigureHowToFindSaga. This includes starting messages.

My starting messages will always create new sagas, and actually don’t include any properties in the message that are even capable of finding an existing saga.

I currently need to add a dummy property to my starting messages, and add a dummy mapping that will never match an existing saga.

This does work around the issue, however, every time a starting message comes in, nservicebus queries Azure Table Storage to see if the saga exists (which obviously it never does).


This is causing 404s to appear in application insights.

Why am I forced to create a mapping on a starting message? And is there any way to prevent nservicebus from trying to look up a saga that will never exist?


Welcome to the Particular discussion group, @ChrisAlmondRws.

The primary reason for requiring a mapping even for messages marked as IAmStartedByMessages<T> is that a saga could be started by multiple messages (e.g., have more than one message type associated with the saga using the IAmStartByMessages interface). If that’s the case, you want the saga to be created once, and all other messages are mapped to the created saga and not create a new one.

Sounds like, in your scenario, you were looking for something like IAmOnlyStartedByMessages<>, which is not supported. Thinking out loud, it seems reasonable to me, and it might be beneficial from the costs perspective. It’s one less query.

Thanks @mauroservienti

I’m not sure what the “only” implies in the IAmOnlyStartedByMessages you’re thinking about:

  1. Allow for a saga with only one starting message, which therefore does not need a mapping.
  2. Allow for multiple starting messages, but those messages only start a new saga (i.e. never map to or update an existing saga), which therefore do not need a mapping.

In my case I do have multiple starting messages, but all of them always create new sagas, so the first would not work for me, but the second would be ideal.

On the original issue (2442), a couple of other ideas were raised:

mapper.DontRequireMappingForStartMessage(); //was this intended as a blanket solution?
mapper.CreateNewSagaInstanceForEach<T>();  //targeted solution using generics.

but it appears that these were either discarded or forgotten.

I think either of the more explicit methods (IAmOnlyStartedBy, or CreateNewSagaForEach) would be more in keeping with the intent to make sure that mappings are not accidentally missed.

I raised a new issue to track this, @ChrisAlmondRws. Sagas that can be started by a single message may cause unexpected costs · Issue #6562 · Particular/NServiceBus · GitHub