Melvin DVaz
Melvin DVaz

Reputation: 1236

MassTransit : Trying to access MT-* headers for a ConsumeContext<Fault<T>>

I have been trying to use a Fault Consumer to process additional information, but the context for the Fault Consumer doesnt appear to have any of the MT-* headers that I can see in RabbitMq Management Tool when I manually get a message from the error queue there. Here is the code I was using

FaultConsumer:

public async Task Consume(ConsumeContext<Fault<TestDto>> context)
{
            
    try
        {
            var producingService = context.Message.Host.ProcessName;
                var consumerName = context.Headers.Get<string>("MT-Fault-ConsumerType", "Unknown");
    }
}

Consumer:

public async Task Consume(ConsumeContext<TestDto> context)
{
    throw new Exception("Test");
}

The only header I can see is MT-Fault-RetryCount (if I enable retries). I was expecting to see all the MT-* headers like MT-Fault-Message and so on. For the most part I can get all the fault details from the context.Message.Exceptions, but was hoping there was a way to grab the consumer name. Is there another way to grab the consumer name, or should it be there in the headers and I'm possibly doing something wrong?

Upvotes: 0

Views: 246

Answers (1)

Chris Patterson
Chris Patterson

Reputation: 33457

Those headers are only added when the message is moved to the _error queue. They are not added to the Fault<T> produced by the consumer pipeline.

Upvotes: 0

Related Questions