I have a particular header that I'd like to attach to all messages that I publish. I can attach this header on a case-by-case basis by specifying it in the Publish
call:
_bus.Publish(myMessage, context => context.SetHeader("my key", "my value"));
This works fine but it becomes a chore to maintain this SetHeader
call for every publish. Is there a way, during bus configuration or anywhere else, to specify a header that will be attached to all messages? That is, is there a way to do something like the following?
ServiceBusFactory.New(sbc =>
{
sbc.UseRabbitMq();
sbc.ReceiveFrom(hdoQueue);
// This is what I'd like to be able to do:
sbc.BeforePublish(context => context.SetHeader("my key", "my value"));
});
I believe there is a solution that involves implementing IOutboundMessageInterceptor
but I can't find a way to attach my interceptor. There is a ServiceBusConfigurator.AddInboundInterceptor
method but not a ServiceBusConfigurator.AddOutboundInterceptor
method.