-
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,5 @@ | ||
| /* | ||
| * Copyright 2012-2017 the original author or authors. | ||
| * Copyright 2012-2018 the original author or authors. | ||
| * | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. | ||
|
|
@@ -24,6 +24,7 @@ | |
| import org.springframework.amqp.rabbit.retry.RejectAndDontRequeueRecoverer; | ||
| import org.springframework.amqp.support.converter.MessageConverter; | ||
| import org.springframework.boot.autoconfigure.amqp.RabbitProperties.ListenerRetry; | ||
| import org.springframework.retry.support.RetryTemplate; | ||
| import org.springframework.util.Assert; | ||
|
|
||
| /** | ||
|
|
@@ -42,6 +43,8 @@ public abstract class AbstractRabbitListenerContainerFactoryConfigurer<T extends | |
|
|
||
| private RabbitProperties rabbitProperties; | ||
|
|
||
| private RabbitListenerRetryTemplateCustomizer retryTemplateCustomizer; | ||
|
|
||
| /** | ||
| * Set the {@link MessageConverter} to use or {@code null} if the out-of-the-box | ||
| * converter should be used. | ||
|
|
@@ -59,6 +62,14 @@ protected void setMessageRecoverer(MessageRecoverer messageRecoverer) { | |
| this.messageRecoverer = messageRecoverer; | ||
| } | ||
|
|
||
| /** | ||
| * Set the {@link RabbitListenerRetryTemplateCustomizer} to use. | ||
| * @param retryTemplateCustomizer the customizer | ||
| */ | ||
| public void setRetryTemplateCustomizer(RabbitListenerRetryTemplateCustomizer retryTemplateCustomizer) { | ||
| this.retryTemplateCustomizer = retryTemplateCustomizer; | ||
| } | ||
|
|
||
| /** | ||
| * Set the {@link RabbitProperties} to use. | ||
| * @param rabbitProperties the {@link RabbitProperties} | ||
|
|
@@ -107,9 +118,9 @@ protected void configure(T factory, ConnectionFactory connectionFactory, | |
| RetryInterceptorBuilder<?> builder = (retryConfig.isStateless() | ||
| ? RetryInterceptorBuilder.stateless() | ||
| : RetryInterceptorBuilder.stateful()); | ||
| builder.maxAttempts(retryConfig.getMaxAttempts()); | ||
| builder.backOffOptions(retryConfig.getInitialInterval(), | ||
| retryConfig.getMultiplier(), retryConfig.getMaxInterval()); | ||
| RetryTemplate template = RabbitAutoConfiguration.createRetryTemplate(retryConfig, | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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). |
||
| this.retryTemplateCustomizer); | ||
| builder.retryOperations(template); | ||
| MessageRecoverer recoverer = (this.messageRecoverer != null | ||
| ? this.messageRecoverer : new RejectAndDontRequeueRecoverer()); | ||
| builder.recoverer(recoverer); | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,30 @@ | ||
| /* | ||
| * Copyright 2012-2018 the original author or authors. | ||
| * | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
|
|
||
| package org.springframework.boot.autoconfigure.amqp; | ||
|
|
||
| import org.springframework.boot.autoconfigure.retry.RetryTemplateCustomizer; | ||
|
|
||
| /** | ||
| * A marker interface for a {@link RetryTemplateCustomizer} for RabbitMQ listeners. | ||
| * | ||
| * @author Gary Russell | ||
| * @since 2.0 | ||
| * | ||
| */ | ||
| public interface RabbitListenerRetryTemplateCustomizer extends RetryTemplateCustomizer { | ||
|
|
||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,30 @@ | ||
| /* | ||
| * Copyright 2012-2018 the original author or authors. | ||
| * | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
|
|
||
| package org.springframework.boot.autoconfigure.amqp; | ||
|
|
||
| import org.springframework.boot.autoconfigure.retry.RetryTemplateCustomizer; | ||
|
|
||
| /** | ||
| * A marker interface for a {@link RetryTemplateCustomizer} for RabbitMQ templates. | ||
| * | ||
| * @author Gary Russell | ||
| * @since 2.0 | ||
| * | ||
| */ | ||
| public interface RabbitTemplateRetryTemplateCustomizer extends RetryTemplateCustomizer { | ||
|
|
||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,37 @@ | ||
| /* | ||
| * Copyright 2012-2018 the original author or authors. | ||
| * | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
|
|
||
| package org.springframework.boot.autoconfigure.retry; | ||
|
|
||
| import org.springframework.retry.support.RetryTemplate; | ||
|
|
||
| /** | ||
| * A customizer for a {@link RetryTemplate}, for example, to add a RetryListener. | ||
| * | ||
| * @author Gary Russell | ||
| * @since 2.0 | ||
| * | ||
| */ | ||
| public interface RetryTemplateCustomizer { | ||
|
|
||
| /** | ||
| * Customize the template. | ||
| * @param template the template. | ||
| * @param properties the properties. | ||
| */ | ||
| void customize(RetryTemplate template); | ||
|
|
||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| /* | ||
| * Copyright 2012-2018 the original author or authors. | ||
| * | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
|
|
||
| /** | ||
| * Auto-configuration for Spring Retry. | ||
| */ | ||
| package org.springframework.boot.autoconfigure.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've started a separate discussion (#13530) but I wonder if a
Consumer<RetryTemplate>wouldn't be enough here.