【发布时间】:2019-03-14 09:57:47
【问题描述】:
我想要针对特定消费者的两个单独的重试策略。一个用于HttpRequestException 和SocketException,另一个用于自定义DatabaseException 和未处理的SqlException。我想这样做是因为我希望两者都有单独的指数重试间隔。
我有以下配置:
cfg.ReceiveEndpoint(
host,
"ExampleQueueName",
ec =>
{
ec.Consumer<ExampleConsumer>(context);
ec.EnablePriority(5);
ec.UseRetry(retryConfig =>
{
// exponential backup in minutes
retryConfig.Intervals(new[] { 1, 2, 4, 8, 16, 32 }.Select(t => TimeSpan.FromSeconds(t)).ToArray());
retryConfig.Handle<HttpRequestException>(x => x.IsTransient());
retryConfig.Handle<SocketException>(x => x.IsTransient());
});
ec.UseRetry(retryConfig =>
{
// exponential backup in seconds
retryConfig.Intervals(new[] { 1, 2, 4, 8, 16, 32 }.Select(t => TimeSpan.FromSeconds(t)).ToArray());
retryConfig.Handle<DatabaseException>(x => x.IsTransient());
retryConfig.Handle<SqlException>(x => x.IsTransient());
});
});
目前,只使用第二个。第一个似乎被覆盖了。
我也尝试过像这样配置二级重试:
cfg.ReceiveEndpoint(
host,
"QueueName",
ec =>
{
ec.Consumer<ExampleConsumer>(context, factory =>
{
factory.UseRetry(retryConfig =>
{
// exponential backup in seconds for sql and concurrency exceptions
retryConfig.Intervals(new[] { 1, 2, 4, 8, 16, 32 }.Select(t => TimeSpan.FromSeconds(t)).ToArray());
retryConfig.Handle<DatabaseException>(x => x.IsTransient());
retryConfig.Handle<SqlException>(x => x.IsTransient());
});
});
ec.EnablePriority(5);
ec.UseRetry(retryConfig =>
{
// exponential backup in minutes for http request exceptions
retryConfig.Intervals(new[] { 1, 2, 4, 8, 16, 32 }.Select(t => TimeSpan.FromSeconds(t)).ToArray());
retryConfig.Handle<DatabaseException>(x => x.IsTransient());
retryConfig.Handle<SqlException>(x => x.IsTransient());
});
});
但这似乎也不起作用。有谁知道我如何为不同的异常类型应用不同的重试间隔?
【问题讨论】:
标签: rabbitmq masstransit