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?
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");
}));
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With