[英]How to set time to live for messages in _error queue with MassTransit?
是否可以為 _error 隊列中的消息設置生存時間? 或者甚至跳過這種將消息發送到錯誤隊列的機制,因為故障已經被消耗了?
我正在使用消費者和故障消費者來處理錯誤。 我不再需要錯誤隊列中的消息。
有可能,您可以創建一個過濾器來丟棄錯誤,然后配置錯誤管道以使用它。
首先,創建過濾器:
class DiscardExceptionFilter :
IFilter<ExceptionReceiveContext>
{
public async Task Send(ExceptionReceiveContext context, IPipe<ExceptionReceiveContext> next)
{
await context.NotifyFaulted(context.Exception).ConfigureAwait(false);
// not calling next.Send(), to end the pipe here.
}
public void Probe(ProbeContext context)
{
context.CreateScope("no-move-error");
}
}
創建后,在接收端點上配置錯誤管道以使用過濾器。
configurator.ConfigureError(x => x.UseFilter(new DiscardExceptionFilter()));
我在這里做錯了嗎? 無論異常類型如何,_error 隊列中都沒有任何內容。 但是,如果我完全刪除過濾器,如預期的那樣,所有消息最終都會出現在錯誤隊列中。
即使我嘗試x.UseContextFilter()
也會發生同樣的情況。
e.ConfigureError(x =>
{
x.UseFilter(new ExceptionLoggerAndFilter());
//x.UseContextFilter(ec =>
//{
// return Task.FromResult(!(ec.Exception is SqlException));
//});
});
#-----------------------------------------
public class ExceptionLoggerAndFilter : IFilter<ExceptionReceiveContext>
{
public async Task Send(ExceptionReceiveContext context, IPipe<ExceptionReceiveContext> next)
{
if (!(context.Exception is SqlException))
{
await context.NotifyFaulted(context.Exception).ConfigureAwait(false);
return;
}
await next.Send(context);
}
public void Probe(ProbeContext context)
{
context.CreateScope("no-move-error");
}
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.