Search code examples
rabbitmqmasstransit

Masstransit ConsumerCanceledException


Sometimes I got MassTransit.ConsumerCanceledException in my consumers.

MT-Fault-ExceptionType: MassTransit.ConsumerCanceledException
MT-Fault-Message: The operation was canceled by the consumer

Why and when does Masstransit occur this exception? how can I resolve that?
for testing, I wrote the below code. but I didn't get this exception. and the message was consumed without a problem.

public async Task Consume(ConsumeContext context)
      {
        await Task.Delay(TimeSpan.FromMinutes(10));
      }

Solution

  • The ConsumerCanceledException is thrown when a consumer throws an OperationCanceledException (or TaskCanceledException since it's a subclass). This represents a consumer-induced cancellation, vs. being canceled by MassTransit itself.

    It's likely a method call in your consumer or dependency is throwing either of the above exceptions.