[FA-misc] Initial MassTransit implementation seems to work
This commit is contained in:
@@ -0,0 +1,33 @@
|
||||
using MassTransit;
|
||||
using Microsoft.Extensions.Logging;
|
||||
|
||||
namespace FictionArchive.Service.Shared.Services.Filters;
|
||||
|
||||
public class LoggingConsumeFilter<T> : IFilter<ConsumeContext<T>> where T : class
|
||||
{
|
||||
private readonly ILogger<LoggingConsumeFilter<T>> _logger;
|
||||
|
||||
public LoggingConsumeFilter(ILogger<LoggingConsumeFilter<T>> logger)
|
||||
{
|
||||
_logger = logger;
|
||||
}
|
||||
|
||||
public async Task Send(ConsumeContext<T> context, IPipe<ConsumeContext<T>> next)
|
||||
{
|
||||
try
|
||||
{
|
||||
await next.Send(context);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex,
|
||||
"Message {MessageType} failed after all retries. MessageId: {MessageId}, ConversationId: {ConversationId}",
|
||||
typeof(T).Name,
|
||||
context.MessageId,
|
||||
context.ConversationId);
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
public void Probe(ProbeContext context) => context.CreateFilterScope("logging");
|
||||
}
|
||||
Reference in New Issue
Block a user