Header API changes Version 6

Component: NServiceBus

Setting headers on outgoing messages

Headers are now set using the new Send/Reply or Publish options. Bus.SetMessageHeader is no longer available.

See also Header Manipulation.

Setting outgoing headers for the entire endpoint

NServiceBus allows setting headers that are applied to all outgoing messages for the entire endpoint. In Version 6 this can be done using:

6.x NServiceBus
endpointConfiguration.AddHeaderToAllOutgoingMessages("MyGlobalHeader", "some static value");

Setting headers on the outgoing pipeline

Headers for outgoing messages can now be set using context.Headers on pipelines like shown below:

6.x NServiceBus
public class OutgoingBehavior :
    Behavior<IOutgoingLogicalMessageContext>
{
    public override Task Invoke(IOutgoingLogicalMessageContext context, Func<Task> next)
    {
        var headers = context.Headers;
        headers["MyCustomHeader"] = "My custom value";
        return next();
    }
}
5.x NServiceBus
public class OutgoingBehavior :
    IBehavior<OutgoingContext>
{
    public void Invoke(OutgoingContext context, Action next)
    {
        var headers = context.OutgoingMessage.Headers;
        headers["MyCustomHeader"] = "My custom value";
        next();
    }
}

Also note that headers can only be set on the outgoing pipeline.


Last modified