Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MassTransit: Adding Headers to Publish Pipeline

Tags:

c#

masstransit

I'm using MassTransit 3.2.4 and I'm trying to add some header information for to my published messages but the code to set the header never seems to run. I'm not sure why this doesn't work.

var bus = Bus.Factory.CreateUsingRabbitMq(config =>
{
    var host = config.Host(new Uri("rabbitmq://localhost/"), h {});
    config.ReceiveEndpoint(host, "TestPublisher", e => 
    { 
        e.ConfigurePublish(x => x.UseSendExecute(context =>
            context.Headers.Set("HeaderKey", "HeaderValue")
        ));
    });
});

On the consumer end I'm trying to read the header

public Task Consume(ConsumeContext<IActionHappened> context)
{
    var headerValue = context.Headers.Get("HeaderKey", "Default Value");
}

Do I need to add an interceptor or something else in order to set header information?

like image 761
adam Avatar asked May 03 '16 15:05

adam


1 Answers

Figured it out after much guessing. Just had the ConfigurePublish in the wrong place

var bus = Bus.Factory.CreateUsingRabbitMq(config => 
{
    var host = config.Host(new Uri("rabbitmq://localhost/"), h => {});
    config.ConfigurePublish(x => x.UseSendExecute(context => 
    {
        context.Headers.Set("HeaderKey", "HeaderValue");
    }));
}
like image 86
adam Avatar answered Oct 14 '22 04:10

adam