Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Sign in / Register
Toggle navigation
S
spring-boot
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
DEMO
spring-boot
Commits
8b35d06c
Commit
8b35d06c
authored
Jun 20, 2018
by
Stephane Nicoll
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Share RetryTemplate infrastructure for Rabbit listener and template
Closes gh-13529
parent
65cc7c72
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
54 additions
and
23 deletions
+54
-23
AbstractRabbitListenerContainerFactoryConfigurer.java
...mqp/AbstractRabbitListenerContainerFactoryConfigurer.java
+2
-3
RabbitAutoConfiguration.java
...work/boot/autoconfigure/amqp/RabbitAutoConfiguration.java
+2
-20
RetryTemplateFactory.java
...amework/boot/autoconfigure/amqp/RetryTemplateFactory.java
+50
-0
No files found.
spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/amqp/AbstractRabbitListenerContainerFactoryConfigurer.java
View file @
8b35d06c
...
...
@@ -107,9 +107,8 @@ public abstract class AbstractRabbitListenerContainerFactoryConfigurer<T extends
RetryInterceptorBuilder
<?>
builder
=
(
retryConfig
.
isStateless
()
?
RetryInterceptorBuilder
.
stateless
()
:
RetryInterceptorBuilder
.
stateful
());
builder
.
maxAttempts
(
retryConfig
.
getMaxAttempts
());
builder
.
backOffOptions
(
retryConfig
.
getInitialInterval
().
toMillis
(),
retryConfig
.
getMultiplier
(),
retryConfig
.
getMaxInterval
().
toMillis
());
builder
.
retryOperations
(
new
RetryTemplateFactory
().
createRetryTemplate
(
retryConfig
));
MessageRecoverer
recoverer
=
(
this
.
messageRecoverer
!=
null
?
this
.
messageRecoverer
:
new
RejectAndDontRequeueRecoverer
());
builder
.
recoverer
(
recoverer
);
...
...
spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/amqp/RabbitAutoConfiguration.java
View file @
8b35d06c
...
...
@@ -40,9 +40,6 @@ import org.springframework.boot.context.properties.PropertyMapper;
import
org.springframework.context.annotation.Bean
;
import
org.springframework.context.annotation.Configuration
;
import
org.springframework.context.annotation.Import
;
import
org.springframework.retry.backoff.ExponentialBackOffPolicy
;
import
org.springframework.retry.policy.SimpleRetryPolicy
;
import
org.springframework.retry.support.RetryTemplate
;
/**
* {@link EnableAutoConfiguration Auto-configuration} for {@link RabbitTemplate}.
...
...
@@ -178,7 +175,8 @@ public class RabbitAutoConfiguration {
template
.
setMandatory
(
determineMandatoryFlag
());
RabbitProperties
.
Template
properties
=
this
.
properties
.
getTemplate
();
if
(
properties
.
getRetry
().
isEnabled
())
{
template
.
setRetryTemplate
(
createRetryTemplate
(
properties
.
getRetry
()));
template
.
setRetryTemplate
(
new
RetryTemplateFactory
()
.
createRetryTemplate
(
properties
.
getRetry
()));
}
map
.
from
(
properties:
:
getReceiveTimeout
).
whenNonNull
().
as
(
Duration:
:
toMillis
)
.
to
(
template:
:
setReceiveTimeout
);
...
...
@@ -194,22 +192,6 @@ public class RabbitAutoConfiguration {
return
(
mandatory
!=
null
?
mandatory
:
this
.
properties
.
isPublisherReturns
());
}
private
RetryTemplate
createRetryTemplate
(
RabbitProperties
.
Retry
properties
)
{
PropertyMapper
map
=
PropertyMapper
.
get
();
RetryTemplate
template
=
new
RetryTemplate
();
SimpleRetryPolicy
policy
=
new
SimpleRetryPolicy
();
map
.
from
(
properties:
:
getMaxAttempts
).
to
(
policy:
:
setMaxAttempts
);
template
.
setRetryPolicy
(
policy
);
ExponentialBackOffPolicy
backOffPolicy
=
new
ExponentialBackOffPolicy
();
map
.
from
(
properties:
:
getInitialInterval
).
whenNonNull
().
as
(
Duration:
:
toMillis
)
.
to
(
backOffPolicy:
:
setInitialInterval
);
map
.
from
(
properties:
:
getMultiplier
).
to
(
backOffPolicy:
:
setMultiplier
);
map
.
from
(
properties:
:
getMaxInterval
).
whenNonNull
().
as
(
Duration:
:
toMillis
)
.
to
(
backOffPolicy:
:
setMaxInterval
);
template
.
setBackOffPolicy
(
backOffPolicy
);
return
template
;
}
@Bean
@ConditionalOnSingleCandidate
(
ConnectionFactory
.
class
)
@ConditionalOnProperty
(
prefix
=
"spring.rabbitmq"
,
name
=
"dynamic"
,
matchIfMissing
=
true
)
...
...
spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/amqp/RetryTemplateFactory.java
0 → 100644
View file @
8b35d06c
/*
* 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
java.time.Duration
;
import
org.springframework.boot.context.properties.PropertyMapper
;
import
org.springframework.retry.backoff.ExponentialBackOffPolicy
;
import
org.springframework.retry.policy.SimpleRetryPolicy
;
import
org.springframework.retry.support.RetryTemplate
;
/**
* Factory to create {@link RetryTemplate} instance from properties defined in
* {@link RabbitProperties}.
*
* @author Stephane Nicoll
*/
class
RetryTemplateFactory
{
public
RetryTemplate
createRetryTemplate
(
RabbitProperties
.
Retry
properties
)
{
PropertyMapper
map
=
PropertyMapper
.
get
();
RetryTemplate
template
=
new
RetryTemplate
();
SimpleRetryPolicy
policy
=
new
SimpleRetryPolicy
();
map
.
from
(
properties:
:
getMaxAttempts
).
to
(
policy:
:
setMaxAttempts
);
template
.
setRetryPolicy
(
policy
);
ExponentialBackOffPolicy
backOffPolicy
=
new
ExponentialBackOffPolicy
();
map
.
from
(
properties:
:
getInitialInterval
).
whenNonNull
().
as
(
Duration:
:
toMillis
)
.
to
(
backOffPolicy:
:
setInitialInterval
);
map
.
from
(
properties:
:
getMultiplier
).
to
(
backOffPolicy:
:
setMultiplier
);
map
.
from
(
properties:
:
getMaxInterval
).
whenNonNull
().
as
(
Duration:
:
toMillis
)
.
to
(
backOffPolicy:
:
setMaxInterval
);
template
.
setBackOffPolicy
(
backOffPolicy
);
return
template
;
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment