【发布时间】:2019-05-21 19:47:28
【问题描述】:
我对以下 Rebus 重试政策有疑问:
Configure.With(...)
.Options(b => b.SimpleRetryStrategy(maxDeliveryAttempts: 2))
.(...)
https://github.com/rebus-org/Rebus/wiki/Automatic-retries-and-error-handling#customizing-retries
1 可以同时用于发布者(入队消息)和订阅者(出队消息)吗?
2 我有一个无法将消息出列的订阅者。因此消息被发送到错误队列。
以下是将消息放入错误队列时的错误。但是我看不到重试的日志。
[ERR] Rebus.Retry.PoisonQueues.PoisonQueueErrorHandler (Thread #9): Moving messa
ge with ID "<unknown>" to error queue "poison"
Rebus.Exceptions.RebusApplicationException: Received message with empty or absen
t 'rbs2-msg-id' header! All messages must be supplied with an ID . If no ID is p
resent, the message cannot be tracked between delivery attempts, and other stuff
would also be much harder to do - therefore, it is a requirement that messages
be supplied with an ID.
是否可以为每次重试定义和存储自定义日志记录,而不是在 IErrorHandler 中?
3 每次重试之间的默认等待时间是多久?
4 是否可以为每次重试定义自定义等待时间(不在 IErrorHandler 中)?如果是这样,此扫描仪是否支持 Polly?如下:
Random jitterer = new Random();
Policy
.Handle<HttpResponseException>() // etc
.WaitAndRetry(5, // exponential back-off plus some jitter
retryAttempt => TimeSpan.FromSeconds(Math.Pow(2, retryAttempt))
+ TimeSpan.FromMilliseconds(jitterer.Next(0, 100))
);
更新
如何测试重试策略?
以下是我根据以下代码尝试的:
public class StringMessageHandler : IHandleMessages<String>
{
public async Task Handle(String message)
{
//retry logic with Polly here
}
}
我向字符串主题发送了一个字符串类型的无效消息,但是根本没有调用 Handle(String message)。
【问题讨论】:
-
(...) I sent an invalid message of string type to the string topic (...)是什么意思?你发布了吗?你记得订阅吗? -
我使用 Azure 服务总线资源管理器发送了无效消息。消息只有正文,没有标题。我没有通过 Rebus 发布它。这只是为了测试重试逻辑,但不会调用 Handle()。但是,无效消息被 Rebus 移动到错误队列中。是否可以挂钩重试逻辑以便执行日志记录和 Polly 策略?我对 Handle 方法的理解可能与 Rebus 不同。
-
您的消息会立即移至死信队列,因为它没有
rbs2-message-id标头 - 该标头是 Rebus 甚至尝试处理消息所需的最低要求,因为它是重试机制工作所必需的。 -
抱歉没有说得更清楚。我的主要问题是如何在 StringMessageHandler.Handle(String message) 方法中通过 Polly 测试自定义重试逻辑?
-
你的类只是一个实现接口的类——它并不真正包含任何与 Rebus 相关的逻辑,所以我建议你只需调用
Handle方法并验证你的 Polly 策略是否有效: )
标签: rebus rebus-azureservicebus