[英]MassTransit - Getting response from request-response ok but message added and deleted from skipped queue?
[英]MassTransit - prevent a message going to the RMQ skipped queue, when a filter is used
我正在將 MassTransit 與 RabbitMQ 一起使用。 按照自定義中間件官方文檔頁面上的示例,我嘗試在消息消費管道上創建一個過濾器,該過濾器將根據特定條件過濾掉一些消息。 我的過濾器看起來像這樣:
public class MyCustomFilter<T> : IFilter<T>
where T : class, ConsumeContext
{
public void Probe(ProbeContext context) { }
public async Task Send(T context, IPipe<T> next)
{
if (/* certain condition */)
{
await next.Send(context);
}
}
}
問題是當消息沒有通過管道傳遞時(即沒有調用await next.Send(context)
),消息在 _skipped 消費者 RabbitMQ 隊列中結束。 有沒有辦法阻止消息進入該隊列?
skipped
(死信)隊列通過DeadLetterFilter
調用獲取消息。 這是代碼:
async Task IFilter<ReceiveContext>.Send(ReceiveContext context, IPipe<ReceiveContext> next)
{
await next.Send(context).ConfigureAwait(false);
if (context.IsDelivered || context.IsFaulted)
return;
context.LogSkipped();
await _deadLetterPipe.Send(context).ConfigureAwait(false);
}
因此,您可以想象,如果上下文將IsDelivered
或IsFaulted
設置為true
,您的消息將不會最終出現在死信隊列中。
如果你加入過濾器,你的消息最終會進入毒葯( error
)隊列,所以我想這不是一個選擇。
您可以通過對過濾器中已過濾的消息執行以下操作來模擬正在傳遞的消息:
public Task Send(T context, IPipe<T> next)
=> condition
? next.Send(context)
: context.NotifyConsumed(context as ConsumeContext<MyMessage>, TimeSpan.Zero, "Filtered");
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.