Replacing _error queue with logging

396 views
Skip to first unread message

BDyke

unread,
Feb 23, 2017, 11:37:20 AM2/23/17
to masstransit-discuss

Using MassTransit 3.5 with RabbitMQ as the transport.

 

We have no need for the _error queues created when a message consumer throws an exception. We try to make sure our consumers don't throw, but if something slips through in production we prefer to log and throw away the message without the error queue filling up.


I have tried:


1. Custom middleware, much like the one from the example page here, to catch and log the exception and then not rethrow. The problem with that is that the message doesn't get marked as "consumed", which leads to it being placed in the _skipped queue instead.

 

2. Created a custom filter much like ConsumerMessageFilter, which would similarly catch and log the exception and then call "context.NotifyConsumed" in the exception handler. I realize NotifyConsumed is meant for internal use. The problem there is that I can't find a way to easily hook up a filter taking a ConsumeContext with the generic type parameter from client code.


Additional ideas:


- Configure a retry policy to retry once, but call a special handler on the retry. Don't think this is possible.

The mysterious (to me) configuration method "UseRescue" pipe configurator that says to "rescue exception via the alternate pipe". I'm not sure if this could achieve what I'm looking for.

 

Any guidance on how this may be possible?

Chris Patterson

unread,
Feb 23, 2017, 1:25:52 PM2/23/17
to masstrans...@googlegroups.com
Writing your own rescue pipe would be ideal, since that is how the message is moved to _error internally. Adding your own would give you the exception, and let you log it. And feel free to call NotifyConsumed() at that point - it just signals the infrastructure so that the message isn't written to _skipped.

This shows how it's done for the receive endpoint: 


--
You received this message because you are subscribed to the Google Groups "masstransit-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to masstransit-discuss+unsub...@googlegroups.com.
To post to this group, send email to masstransit-discuss@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/masstransit-discuss/085ffe41-cfd2-47fb-a1ae-f37b02833e9a%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

BDyke

unread,
Feb 23, 2017, 4:19:47 PM2/23/17
to masstransit-discuss
Thank you Chris, much appreciated.

I've tried doing this but am running into the same issue as described under my attempt #2: In my custom exception rescue pipe I don't have access to the actual message and message type, which I need to "Notify Consumed":

public class CustomExceptionRescuePipe :

IFilter<ExceptionConsumeContext>

{

public Task Send(ExceptionConsumeContext context, IPipe<ExceptionConsumeContext> next)

{

// Log here…

Console.WriteLine("Error occured");

 

context.NotifyConsumed(context,         // Context needs to be of type CosumeContext<T>

TimeSpan.Zero,

TypeMetadataCache<TConsumer>.ShortName); // Type is also needed here

 

 

return Task.CompletedTask;

}

}


So a new question then, can I get the type from the context object here somehow? I can't register a generic type in the "AddPipeSpecification".


On Thursday, 23 February 2017 13:25:52 UTC-5, Chris Patterson wrote:
Writing your own rescue pipe would be ideal, since that is how the message is moved to _error internally. Adding your own would give you the exception, and let you log it. And feel free to call NotifyConsumed() at that point - it just signals the infrastructure so that the message isn't written to _skipped.

This shows how it's done for the receive endpoint: 

On Thu, Feb 23, 2017 at 8:37 AM, BDyke  wrote:

Using MassTransit 3.5 with RabbitMQ as the transport.

 

We have no need for the _error queues created when a message consumer throws an exception. We try to make sure our consumers don't throw, but if something slips through in production we prefer to log and throw away the message without the error queue filling up.


I have tried:


1. Custom middleware, much like the one from the example page here, to catch and log the exception and then not rethrow. The problem with that is that the message doesn't get marked as "consumed", which leads to it being placed in the _skipped queue instead.

 

2. Created a custom filter much like ConsumerMessageFilter, which would similarly catch and log the exception and then call "context.NotifyConsumed" in the exception handler. I realize NotifyConsumed is meant for internal use. The problem there is that I can't find a way to easily hook up a filter taking a ConsumeContext with the generic type parameter from client code.


Additional ideas:


- Configure a retry policy to retry once, but call a special handler on the retry. Don't think this is possible.

The mysterious (to me) configuration method "UseRescue" pipe configurator that says to "rescue exception via the alternate pipe". I'm not sure if this could achieve what I'm looking for.

 

Any guidance on how this may be possible?

--
You received this message because you are subscribed to the Google Groups "masstransit-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to masstransit-discuss+unsub...@googlegroups.com.
To post to this group, send email to masstrans...@googlegroups.com.

Stanislav Nedeljkovic

unread,
May 16, 2017, 2:47:57 AM5/16/17
to masstransit-discuss
Hi

any luck with implementig NotifyConsumed?

Chris Patterson

unread,
May 16, 2017, 10:07:21 AM5/16/17
to masstrans...@googlegroups.com
There is another version of it on the ReceiveContext if I recall correctly, which doesn't require the generic type.

Hi

To unsubscribe from this group and stop receiving emails from it, send an email to masstransit-discuss+unsubscribe...@googlegroups.com.

--
You received this message because you are subscribed to the Google Groups "masstransit-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to masstransit-discuss+unsub...@googlegroups.com.

Stanislav Nedeljkovic

unread,
May 16, 2017, 4:21:53 PM5/16/17
to masstransit-discuss
Hi

To unsubscribe from this group and stop receiving emails from it, send an email to masstransit-discuss+unsub...@googlegroups.com.
To post to this group, send email to masstrans...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/masstransit-discuss/085ffe41-cfd2-47fb-a1ae-f37b02833e9a%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "masstransit-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to masstransit-discuss+unsub...@googlegroups.com.
To post to this group, send email to masstrans...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages