-
Notifications
You must be signed in to change notification settings - Fork 41.7k
RabbitMQ - RetryTemplate customization hook #11697
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Provide a mechanism so that users can customize `RetryTemplate`s used in `RabbitTemplate` and listeners. An example would be to add a retry listener so the user can monitor/log retry attempts. https://stackoverflow.com/questions/48331502/logging-exceptions-thrown-by-message-listeners-for-spring-amqp/48332001#48332001 Or, to set a custom `RetryContextCache`. temp
snicoll
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@garyrussell I am not super keen to expand the surface area of Spring Boot for such specific requirement. I am guessing there are other areas where we want to customize things and I'd very much prefer if the API would allow us to do this with a broader scope (i.e. a single callback to tune everything RabbitTemplate related for instance).
For the listener we can have something on AbstractRabbitListenerContainerFactoryConfigurer where we can "consume" a RetryTemplate. This would allow for customizations without creating a separate contract. This is a different approach so I've started a separate issue to discuss this.
As for the retry template for the RabbitTemplate, I wished there was a way to customize the template rather than this individual piece. Perhaps we should start looking at RetryTemplate with a very specifc name? I am not a huge fan of that approach either but having two customizer interfaces with a base class isn't great either IMO.
| builder.maxAttempts(retryConfig.getMaxAttempts()); | ||
| builder.backOffOptions(retryConfig.getInitialInterval(), | ||
| retryConfig.getMultiplier(), retryConfig.getMaxInterval()); | ||
| RetryTemplate template = RabbitAutoConfiguration.createRetryTemplate(retryConfig, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It looks like this PR offers a way to customize the retry template and to set it at all. To me, these are two separate features that deserve a separate commit. I've just done that in #13529 (calling the auto-config that way isn't something we do, see the commit for more details).
| * Set the {@link RabbitListenerRetryTemplateCustomizer} to use. | ||
| * @param retryTemplateCustomizer the customizer | ||
| */ | ||
| public void setRetryTemplateCustomizer(RabbitListenerRetryTemplateCustomizer retryTemplateCustomizer) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've started a separate discussion (#13530) but I wonder if a Consumer<RetryTemplate> wouldn't be enough here.
| @Test | ||
| public void testRabbitMessagingTemplateBackOff() { | ||
| this.contextRunner.withUserConfiguration(TestConfiguration4.class) | ||
| .withPropertyValues("spring.rabbitmq.listener.simple.retry.enabled=true", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am not sure I understand the purpose of that test. We're creating a messaging template to show that it's taken into account. Why is retry processing added there?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am testing that the customizer injected a listener into the listener container's retry template; in order to test that, we need to enable retry.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I got that. But why are you testing that as part of testRabbitMessagingTemplateBackOff ?
|
I concur with the general comment about using Perhaps another alternative would be for the And for the listener, we could have |
I thought of that but I think we should do that only if that makes sense generally speaking and not to ease that particular case. I don't know if exposing the My proposal of using Or perhaps having two interfaces for this is fine? It just doesn't seem right to me but I can't put my fingers on why exactly. Flagging for team attention to get more feedback. |
|
We've discussed this at the call and we're now leaning towards a unique @garyrussell if you want to give it a try, please let me know. |
|
@snicoll Sorry; mis-read; it's probably best for you to hack at it, to avoid a bunch of round trips 😄 |
|
@garyrussell alright I hacked something and I've opened #13793 to track it. Thanks for the PR and the help on this issue. |
Provide a mechanism so that users can customize
RetryTemplatesused in
RabbitTemplateand listeners.An example would be to add a retry listener so the user can monitor/log
retry attempts.
https://stackoverflow.com/questions/48331502/logging-exceptions-thrown-by-message-listeners-for-spring-amqp/48332001#48332001
Or, to set a custom
RetryContextCache.temp