Luca
March 12, 2021, 7:36am
1
Hi
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.SetDestination(Entity.Originator);
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();
options.SetDestination(Entity.Originator);
dynamic correlationIdState = Activator.CreateInstance(Type.GetType("NServiceBus.AttachCorrelationIdBehavior+State"), true);
correlationIdState.CustomCorrelationId = Entity.OriginalMessageId;
context.Extensions.Set(correlationIdState);
var correlationHeaderState = Activator.CreateInstance(Type.GetType("NServiceBus.PopulateAutoCorrelationHeadersForRepliesBehavior+State"), true);
options.Context.Set(correlationHeaderState);
return context.Reply(message, options);
}
I’ve raised a feature proposal PR to address this
Regards
Daniel
1 Like