Polish contribution
Closes gh-5341
This commit is contained in:
@@ -107,7 +107,7 @@ public class RabbitAutoConfiguration {
|
||||
}
|
||||
Template template = config.getTemplate();
|
||||
Retry retry = template.getRetry();
|
||||
if (retry.isEnable()) {
|
||||
if (retry.isEnabled()) {
|
||||
RetryTemplate retryTemplate = new RetryTemplate();
|
||||
SimpleRetryPolicy retryPolicy = new SimpleRetryPolicy();
|
||||
retryPolicy.setMaxAttempts(retry.getMaxAttempts());
|
||||
|
||||
@@ -22,6 +22,7 @@ import java.util.Set;
|
||||
import org.springframework.amqp.core.AcknowledgeMode;
|
||||
import org.springframework.amqp.rabbit.connection.CachingConnectionFactory.CacheMode;
|
||||
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||
import org.springframework.boot.context.properties.NestedConfigurationProperty;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
/**
|
||||
@@ -396,6 +397,7 @@ public class RabbitProperties {
|
||||
/**
|
||||
* Optional properties for a retry interceptor.
|
||||
*/
|
||||
@NestedConfigurationProperty
|
||||
private final ListenerRetry retry = new ListenerRetry();
|
||||
|
||||
public boolean isAutoStartup() {
|
||||
@@ -462,6 +464,7 @@ public class RabbitProperties {
|
||||
|
||||
public static class Template {
|
||||
|
||||
@NestedConfigurationProperty
|
||||
private final Retry retry = new Retry();
|
||||
|
||||
/**
|
||||
@@ -501,16 +504,16 @@ public class RabbitProperties {
|
||||
/**
|
||||
* Whether or not publishing retries are enabled.
|
||||
*/
|
||||
private boolean enable;
|
||||
private boolean enabled;
|
||||
|
||||
/**
|
||||
* The maximum number of attempts to publish or deliver a message.
|
||||
* Maximum number of attempts to publish or deliver a message.
|
||||
*/
|
||||
private int maxAttempts = 3;
|
||||
|
||||
/**
|
||||
* The interval between the first and second attempt to publish
|
||||
* or deliver a message.
|
||||
* Interval between the first and second attempt to publish or deliver
|
||||
* a message.
|
||||
*/
|
||||
private long initialInterval = 1000L;
|
||||
|
||||
@@ -520,16 +523,16 @@ public class RabbitProperties {
|
||||
private double multiplier = 1.0;
|
||||
|
||||
/**
|
||||
* The maximum interval between attempts.
|
||||
* Maximum interval between attempts.
|
||||
*/
|
||||
private long maxInterval = 10000L;
|
||||
|
||||
public boolean isEnable() {
|
||||
return this.enable;
|
||||
public boolean isEnabled() {
|
||||
return this.enabled;
|
||||
}
|
||||
|
||||
public void setEnable(boolean enable) {
|
||||
this.enable = enable;
|
||||
public void setEnabled(boolean enabled) {
|
||||
this.enabled = enabled;
|
||||
}
|
||||
|
||||
public int getMaxAttempts() {
|
||||
|
||||
@@ -91,14 +91,9 @@ public final class SimpleRabbitListenerContainerFactoryConfigurer {
|
||||
factory.setDefaultRequeueRejected(listenerConfig.getDefaultRequeueRejected());
|
||||
}
|
||||
ListenerRetry retryConfig = listenerConfig.getRetry();
|
||||
if (retryConfig.isEnable()) {
|
||||
RetryInterceptorBuilder<?> builder;
|
||||
if (retryConfig.isStateless()) {
|
||||
builder = RetryInterceptorBuilder.stateless();
|
||||
}
|
||||
else {
|
||||
builder = RetryInterceptorBuilder.stateful();
|
||||
}
|
||||
if (retryConfig.isEnabled()) {
|
||||
RetryInterceptorBuilder<?> builder = (retryConfig.isStateless() ?
|
||||
RetryInterceptorBuilder.stateless() : RetryInterceptorBuilder.stateful());
|
||||
factory.setAdviceChain(builder
|
||||
.maxAttempts(retryConfig.getMaxAttempts())
|
||||
.backOffOptions(retryConfig.getInitialInterval(),
|
||||
@@ -106,6 +101,7 @@ public final class SimpleRabbitListenerContainerFactoryConfigurer {
|
||||
.recoverer(new RejectAndDontRequeueRecoverer())
|
||||
.build());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -147,11 +147,11 @@ public class RabbitAutoConfigurationTests {
|
||||
|
||||
@Test
|
||||
public void testRabbitTemplateRetry() {
|
||||
load(TestConfiguration.class, "spring.rabbitmq.template.retry.enable:true",
|
||||
"spring.rabbitmq.template.retry.max-attempts:4",
|
||||
"spring.rabbitmq.template.retry.initial-interval:2000",
|
||||
load(TestConfiguration.class, "spring.rabbitmq.template.retry.enabled:true",
|
||||
"spring.rabbitmq.template.retry.maxAttempts:4",
|
||||
"spring.rabbitmq.template.retry.initialInterval:2000",
|
||||
"spring.rabbitmq.template.retry.multiplier:1.5",
|
||||
"spring.rabbitmq.template.retry.max-interval:5000",
|
||||
"spring.rabbitmq.template.retry.maxInterval:5000",
|
||||
"spring.rabbitmq.template.receiveTimeout:123",
|
||||
"spring.rabbitmq.template.replyTimeout:456");
|
||||
RabbitTemplate rabbitTemplate = this.context.getBean(RabbitTemplate.class);
|
||||
@@ -248,17 +248,17 @@ public class RabbitAutoConfigurationTests {
|
||||
@Test
|
||||
public void testRabbitListenerContainerFactoryWithCustomSettings() {
|
||||
load(MessageConvertersConfiguration.class,
|
||||
"spring.rabbitmq.listener.retry.enable:true",
|
||||
"spring.rabbitmq.listener.retry.max-attempts:4",
|
||||
"spring.rabbitmq.listener.retry.initial-interval:2000",
|
||||
"spring.rabbitmq.listener.retry.enabled:true",
|
||||
"spring.rabbitmq.listener.retry.maxAttempts:4",
|
||||
"spring.rabbitmq.listener.retry.initialInterval:2000",
|
||||
"spring.rabbitmq.listener.retry.multiplier:1.5",
|
||||
"spring.rabbitmq.listener.retry.max-interval:5000",
|
||||
"spring.rabbitmq.listener.retry.maxInterval:5000",
|
||||
"spring.rabbitmq.listener.autoStartup:false",
|
||||
"spring.rabbitmq.listener.acknowledgeMode:manual",
|
||||
"spring.rabbitmq.listener.concurrency:5",
|
||||
"spring.rabbitmq.listener.maxConcurrency:10",
|
||||
"spring.rabbitmq.listener.prefetch:40",
|
||||
"spring.rabbitmq.listener.default-requeue-rejected:false",
|
||||
"spring.rabbitmq.listener.defaultRequeueRejected:false",
|
||||
"spring.rabbitmq.listener.transactionSize:20");
|
||||
SimpleRabbitListenerContainerFactory rabbitListenerContainerFactory = this.context
|
||||
.getBean("rabbitListenerContainerFactory",
|
||||
|
||||
Reference in New Issue
Block a user