I have questions on Rebus retry policy below:
Configure.With(...)
.Options(b => b.SimpleRetryStrategy(maxDeliveryAttempts: 2))
.(...)
https://github.com/rebus-org/Rebus/wiki/Automatic-retries-and-error-handling#customizing-retries
1 Can it be used for both Publiser (enqueue messages) and Subscriber (dequeue messages)?
2 I have a subscriber that is unable to dequeue the message. Thus the message is sent to error queue.
Below is error for when putting the message to error queue. But I cannot see the loggings for the retry.
[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.
Is it possible to define and store custom logging for each retry, not within IErrorHandler?
3 How long does each retry wait in between be default?
4 Is it possible to define custom wait time for each retry (not within IErrorHandler)? If so, is Polly supported for this scanario? like below:
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))
);
Update
How can I test the retry policy?
Below is what I tried based on the code below:
public class StringMessageHandler : IHandleMessages<String>
{
public async Task Handle(String message)
{
//retry logic with Polly here
}
}
I sent an invalid message of string type to the string topic, however, the Handle(String message) is not invoked at all.
(...) I sent an invalid message of string type to the string topic (...)
? Did you publish it? Did you remember to subscribe to it? – mookid8000rbs2-message-id
header – that header is the bare minimum required for Rebus to even try to handle a message, as it's necessary for the retry mechanism to work. – mookid8000Handle
method and verify that your Polly policy works :) – mookid8000