MassTransit中是否有内置方式为接收端点中的所有使用者设置超时?我尝试使用IFilter实现(如下),但它似乎没有触发任务取消异常。
public class ConsumerTimeoutFilter<T> : IFilter<T> where T : class, PipeContext
{
private readonly TimeSpan timeout;
public ConsumerTimeoutFilter(TimeSpan timeout)
{
this.timeout = timeout;
}
public Task Send(T context, IPipe<T> next)
{
var source = new CancellationTokenSource();
var task = Task.Run(() => next.Send(context), source.Token);
source.CancelAfter(timeout);
return task;
}
public void Probe(ProbeContext context)
{
}
}