c# – MassTransit:添加标题以发布管道
作者:互联网
我正在使用MassTransit 3.2.4,我正在尝试为我发布的消息添加一些标题信息,但设置标题的代码似乎永远不会运行.我不确定为什么这不起作用.
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")
));
});
});
在消费者端,我正在尝试阅读标题
public Task Consume(ConsumeContext<IActionHappened> context)
{
var headerValue = context.Headers.Get("HeaderKey", "Default Value");
}
我是否需要添加拦截器或其他东西才能设置标题信息?
解决方法:
经过多次猜测后想出来了.刚刚将ConfigurePublish放在错误的位置
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");
}));
}
标签:c,masstransit 来源: https://codeday.me/bug/20190623/1269204.html