Saga ReplyToOriginator using Headers impossible?

I am trying to pass some headers along with a ReplyToOriginator call.
The Saga implementation doesn’t offer this so I tried reimplementing the ReplyToOriginator method, but that results in a SagaNotFound on the recipients side.

private Task ReplyToOriginator(IMessageHandlerContext context, object message, ReplyOptions options)
    options.SetHeader(Headers.SagaType, null);
    options.SetHeader(Headers.SagaId, null);
    options.SetHeader(Headers.CorrelationId, Entity.OriginalMessageId);
    return context.Reply(message, options);

The header I need to set is generated when the message is sent, so I think I cannot use a simple Mutator, I might be wrong though

Hi Luca

Unfortunately, it is currently only possible to do it with this hack I think

        protected Task ReplyToOriginatorCustom(IMessageHandlerContext context, object message)
            if (string.IsNullOrEmpty(Entity.Originator))
                throw new Exception("Entity.Originator cannot be null. Perhaps the sender is a SendOnly endpoint.");

            var options = new ReplyOptions();

            dynamic correlationIdState = Activator.CreateInstance(Type.GetType("NServiceBus.AttachCorrelationIdBehavior+State"), true);
            correlationIdState.CustomCorrelationId = Entity.OriginalMessageId;

            var correlationHeaderState = Activator.CreateInstance(Type.GetType("NServiceBus.PopulateAutoCorrelationHeadersForRepliesBehavior+State"), true);

            return context.Reply(message, options);

I’ve raised a feature proposal PR to address this


1 Like