Untitled
unknown
csharp
a year ago
1.2 kB
20
Indexable
public class ExceptionHandlingFilter<T> : IFilter<ConsumeContext<T>> where T : class
{
public async Task Send(ConsumeContext<T> context, IPipe<ConsumeContext<T>> next)
{
try
{
// Proceed with normal message processing
await next.Send(context);
}
catch (Exception ex)
{
if (IsUnrecoverable(ex))
{
Console.WriteLine($"Unrecoverable exception: {ex.Message}. Skipping retries.");
// Notify that this message has failed without retrying further
await context.NotifyFaulted(ex);
}
else
{
Console.WriteLine($"Recoverable exception: {ex.Message}. Applying retry policy.");
// Re-throw for the retry policy to handle
throw;
}
}
}
private bool IsUnrecoverable(Exception exception)
{
// Define logic for unrecoverable exceptions
return exception is UnrecoverableException;
}
public void Probe(ProbeContext context)
{
context.CreateScope("ExceptionHandlingFilter");
}
}
Editor is loading...
Leave a Comment