MassTransit: Adding Headers to Publish Pipeline

£可爱£侵袭症+ 提交于 2019-12-01 04:08:37

问题


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?


回答1:


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");
    }));
}


来源:https://stackoverflow.com/questions/37008671/masstransit-adding-headers-to-publish-pipeline

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!