Migrate remaining duration-based properties for Rabbit

Closes gh-12192
pull/12202/head
Stephane Nicoll 7 years ago
parent 48656d0d53
commit 13b736b1cd

@ -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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -108,8 +108,8 @@ public abstract class AbstractRabbitListenerContainerFactoryConfigurer<T extends
? RetryInterceptorBuilder.stateless() ? RetryInterceptorBuilder.stateless()
: RetryInterceptorBuilder.stateful()); : RetryInterceptorBuilder.stateful());
builder.maxAttempts(retryConfig.getMaxAttempts()); builder.maxAttempts(retryConfig.getMaxAttempts());
builder.backOffOptions(retryConfig.getInitialInterval(), builder.backOffOptions(retryConfig.getInitialInterval().toMillis(),
retryConfig.getMultiplier(), retryConfig.getMaxInterval()); retryConfig.getMultiplier(), retryConfig.getMaxInterval().toMillis());
MessageRecoverer recoverer = (this.messageRecoverer != null MessageRecoverer recoverer = (this.messageRecoverer != null
? this.messageRecoverer : new RejectAndDontRequeueRecoverer()); ? this.messageRecoverer : new RejectAndDontRequeueRecoverer());
builder.recoverer(recoverer); builder.recoverer(recoverer);

@ -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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -102,7 +102,7 @@ public class RabbitAutoConfiguration {
map.from(properties::isPublisherReturns).to(factory::setPublisherReturns); map.from(properties::isPublisherReturns).to(factory::setPublisherReturns);
RabbitProperties.Cache.Channel channel = properties.getCache().getChannel(); RabbitProperties.Cache.Channel channel = properties.getCache().getChannel();
map.from(channel::getSize).whenNonNull().to(factory::setChannelCacheSize); map.from(channel::getSize).whenNonNull().to(factory::setChannelCacheSize);
map.from(channel::getCheckoutTimeout).whenNonNull() map.from(channel::getCheckoutTimeout).whenNonNull().as(Duration::toMillis)
.to(factory::setChannelCheckoutTimeout); .to(factory::setChannelCheckoutTimeout);
RabbitProperties.Cache.Connection connection = properties.getCache() RabbitProperties.Cache.Connection connection = properties.getCache()
.getConnection(); .getConnection();
@ -175,9 +175,9 @@ public class RabbitAutoConfiguration {
if (properties.getRetry().isEnabled()) { if (properties.getRetry().isEnabled()) {
template.setRetryTemplate(createRetryTemplate(properties.getRetry())); template.setRetryTemplate(createRetryTemplate(properties.getRetry()));
} }
map.from(properties::getReceiveTimeout).whenNonNull() map.from(properties::getReceiveTimeout).whenNonNull().as(Duration::toMillis)
.to(template::setReceiveTimeout); .to(template::setReceiveTimeout);
map.from(properties::getReplyTimeout).whenNonNull() map.from(properties::getReplyTimeout).whenNonNull().as(Duration::toMillis)
.to(template::setReplyTimeout); .to(template::setReplyTimeout);
map.from(properties::getExchange).to(template::setExchange); map.from(properties::getExchange).to(template::setExchange);
map.from(properties::getRoutingKey).to(template::setRoutingKey); map.from(properties::getRoutingKey).to(template::setRoutingKey);
@ -196,10 +196,11 @@ public class RabbitAutoConfiguration {
map.from(properties::getMaxAttempts).to(policy::setMaxAttempts); map.from(properties::getMaxAttempts).to(policy::setMaxAttempts);
template.setRetryPolicy(policy); template.setRetryPolicy(policy);
ExponentialBackOffPolicy backOffPolicy = new ExponentialBackOffPolicy(); ExponentialBackOffPolicy backOffPolicy = new ExponentialBackOffPolicy();
map.from(properties::getInitialInterval) map.from(properties::getInitialInterval).whenNonNull().as(Duration::toMillis)
.to(backOffPolicy::setInitialInterval); .to(backOffPolicy::setInitialInterval);
map.from(properties::getMultiplier).to(backOffPolicy::setMultiplier); map.from(properties::getMultiplier).to(backOffPolicy::setMultiplier);
map.from(properties::getMaxInterval).to(backOffPolicy::setMaxInterval); map.from(properties::getMaxInterval).whenNonNull().as(Duration::toMillis)
.to(backOffPolicy::setMaxInterval);
template.setBackOffPolicy(backOffPolicy); template.setBackOffPolicy(backOffPolicy);
return template; return template;
} }

@ -438,10 +438,10 @@ public class RabbitProperties {
private Integer size; private Integer size;
/** /**
* Number of milliseconds to wait to obtain a channel if the cache size has * Duration to wait to obtain a channel if the cache size has been reached. If
* been reached. If 0, always create a new channel. * 0, always create a new channel.
*/ */
private Long checkoutTimeout; private Duration checkoutTimeout;
public Integer getSize() { public Integer getSize() {
return this.size; return this.size;
@ -451,14 +451,13 @@ public class RabbitProperties {
this.size = size; this.size = size;
} }
public Long getCheckoutTimeout() { public Duration getCheckoutTimeout() {
return this.checkoutTimeout; return this.checkoutTimeout;
} }
public void setCheckoutTimeout(Long checkoutTimeout) { public void setCheckoutTimeout(Duration checkoutTimeout) {
this.checkoutTimeout = checkoutTimeout; this.checkoutTimeout = checkoutTimeout;
} }
} }
public static class Connection { public static class Connection {
@ -696,12 +695,12 @@ public class RabbitProperties {
/** /**
* Timeout for `receive()` operations. * Timeout for `receive()` operations.
*/ */
private Long receiveTimeout; private Duration receiveTimeout;
/** /**
* Timeout for `sendAndReceive()` operations. * Timeout for `sendAndReceive()` operations.
*/ */
private Long replyTimeout; private Duration replyTimeout;
/** /**
* Name of the default exchange to use for send operations. * Name of the default exchange to use for send operations.
@ -725,19 +724,19 @@ public class RabbitProperties {
this.mandatory = mandatory; this.mandatory = mandatory;
} }
public Long getReceiveTimeout() { public Duration getReceiveTimeout() {
return this.receiveTimeout; return this.receiveTimeout;
} }
public void setReceiveTimeout(Long receiveTimeout) { public void setReceiveTimeout(Duration receiveTimeout) {
this.receiveTimeout = receiveTimeout; this.receiveTimeout = receiveTimeout;
} }
public Long getReplyTimeout() { public Duration getReplyTimeout() {
return this.replyTimeout; return this.replyTimeout;
} }
public void setReplyTimeout(Long replyTimeout) { public void setReplyTimeout(Duration replyTimeout) {
this.replyTimeout = replyTimeout; this.replyTimeout = replyTimeout;
} }
@ -772,9 +771,9 @@ public class RabbitProperties {
private int maxAttempts = 3; private int maxAttempts = 3;
/** /**
* Interval, in milliseconds, between the first and second attempt to deliver a message. * Duration between the first and second attempt to deliver a message.
*/ */
private long initialInterval = 1000L; private Duration initialInterval = Duration.ofMillis(1000);
/** /**
* Multiplier to apply to the previous retry interval. * Multiplier to apply to the previous retry interval.
@ -782,9 +781,9 @@ public class RabbitProperties {
private double multiplier = 1.0; private double multiplier = 1.0;
/** /**
* Maximum interval, in milliseconds, between attempts. * Maximum duration between attempts.
*/ */
private long maxInterval = 10000L; private Duration maxInterval = Duration.ofMillis(10000);
public boolean isEnabled() { public boolean isEnabled() {
return this.enabled; return this.enabled;
@ -802,14 +801,18 @@ public class RabbitProperties {
this.maxAttempts = maxAttempts; this.maxAttempts = maxAttempts;
} }
public long getInitialInterval() { public Duration getInitialInterval() {
return this.initialInterval; return this.initialInterval;
} }
public void setInitialInterval(long initialInterval) { public void setInitialInterval(Duration initialInterval) {
this.initialInterval = initialInterval; this.initialInterval = initialInterval;
} }
public void setMaxInterval(Duration maxInterval) {
this.maxInterval = maxInterval;
}
public double getMultiplier() { public double getMultiplier() {
return this.multiplier; return this.multiplier;
} }
@ -818,14 +821,10 @@ public class RabbitProperties {
this.multiplier = multiplier; this.multiplier = multiplier;
} }
public long getMaxInterval() { public Duration getMaxInterval() {
return this.maxInterval; return this.maxInterval;
} }
public void setMaxInterval(long maxInterval) {
this.maxInterval = maxInterval;
}
} }
public static class ListenerRetry extends Retry { public static class ListenerRetry extends Retry {

@ -1071,9 +1071,9 @@ content into your application. Rather, pick only the properties that you need.
spring.rabbitmq.listener.direct.idle-event-interval= # How often idle container events should be published. spring.rabbitmq.listener.direct.idle-event-interval= # How often idle container events should be published.
spring.rabbitmq.listener.direct.prefetch= # Number of messages to be handled in a single request. It should be greater than or equal to the transaction size (if used). spring.rabbitmq.listener.direct.prefetch= # Number of messages to be handled in a single request. It should be greater than or equal to the transaction size (if used).
spring.rabbitmq.listener.direct.retry.enabled=false # Whether publishing retries are enabled. spring.rabbitmq.listener.direct.retry.enabled=false # Whether publishing retries are enabled.
spring.rabbitmq.listener.direct.retry.initial-interval=1000ms # Interval, in milliseconds, between the first and second attempt to deliver a message. spring.rabbitmq.listener.direct.retry.initial-interval=1000ms # Duration between the first and second attempt to deliver a message.
spring.rabbitmq.listener.direct.retry.max-attempts=3 # Maximum number of attempts to deliver a message. spring.rabbitmq.listener.direct.retry.max-attempts=3 # Maximum number of attempts to deliver a message.
spring.rabbitmq.listener.direct.retry.max-interval=10000ms # Maximum interval, in milliseconds, between attempts. spring.rabbitmq.listener.direct.retry.max-interval=10000ms # Maximum duration between attempts.
spring.rabbitmq.listener.direct.retry.multiplier=1 # Multiplier to apply to the previous retry interval. spring.rabbitmq.listener.direct.retry.multiplier=1 # Multiplier to apply to the previous retry interval.
spring.rabbitmq.listener.direct.retry.stateless=true # Whether retries are stateless or stateful. spring.rabbitmq.listener.direct.retry.stateless=true # Whether retries are stateless or stateful.
spring.rabbitmq.listener.simple.acknowledge-mode= # Acknowledge mode of container. spring.rabbitmq.listener.simple.acknowledge-mode= # Acknowledge mode of container.
@ -1084,9 +1084,9 @@ content into your application. Rather, pick only the properties that you need.
spring.rabbitmq.listener.simple.max-concurrency= # Maximum number of listener invoker threads. spring.rabbitmq.listener.simple.max-concurrency= # Maximum number of listener invoker threads.
spring.rabbitmq.listener.simple.prefetch= # Number of messages to be handled in a single request. It should be greater than or equal to the transaction size (if used). spring.rabbitmq.listener.simple.prefetch= # Number of messages to be handled in a single request. It should be greater than or equal to the transaction size (if used).
spring.rabbitmq.listener.simple.retry.enabled=false # Whether publishing retries are enabled. spring.rabbitmq.listener.simple.retry.enabled=false # Whether publishing retries are enabled.
spring.rabbitmq.listener.simple.retry.initial-interval=1000 # Interval, in milliseconds, between the first and second attempt to deliver a message. spring.rabbitmq.listener.simple.retry.initial-interval=1000ms # Duration between the first and second attempt to deliver a message.
spring.rabbitmq.listener.simple.retry.max-attempts=3 # Maximum number of attempts to deliver a message. spring.rabbitmq.listener.simple.retry.max-attempts=3 # Maximum number of attempts to deliver a message.
spring.rabbitmq.listener.simple.retry.max-interval=10000 # Maximum interval, in milliseconds, between attempts. spring.rabbitmq.listener.simple.retry.max-interval=10000ms # Maximum duration between attempts.
spring.rabbitmq.listener.simple.retry.multiplier=1 # Multiplier to apply to the previous retry interval. spring.rabbitmq.listener.simple.retry.multiplier=1 # Multiplier to apply to the previous retry interval.
spring.rabbitmq.listener.simple.retry.stateless=true # Whether retries are stateless or stateful. spring.rabbitmq.listener.simple.retry.stateless=true # Whether retries are stateless or stateful.
spring.rabbitmq.listener.simple.transaction-size= # Number of messages to be processed in a transaction. That is, the number of messages between acks. For best results, it should be less than or equal to the prefetch count. spring.rabbitmq.listener.simple.transaction-size= # Number of messages to be processed in a transaction. That is, the number of messages between acks. For best results, it should be less than or equal to the prefetch count.
@ -1109,9 +1109,9 @@ content into your application. Rather, pick only the properties that you need.
spring.rabbitmq.template.receive-timeout= # Timeout for `receive()` operations. spring.rabbitmq.template.receive-timeout= # Timeout for `receive()` operations.
spring.rabbitmq.template.reply-timeout= # Timeout for `sendAndReceive()` operations. spring.rabbitmq.template.reply-timeout= # Timeout for `sendAndReceive()` operations.
spring.rabbitmq.template.retry.enabled=false # Whether publishing retries are enabled. spring.rabbitmq.template.retry.enabled=false # Whether publishing retries are enabled.
spring.rabbitmq.template.retry.initial-interval=1000 # Interval, in milliseconds, between the first and second attempt to deliver a message. spring.rabbitmq.template.retry.initial-interval=1000ms # Duration between the first and second attempt to deliver a message.
spring.rabbitmq.template.retry.max-attempts=3 # Maximum number of attempts to deliver a message. spring.rabbitmq.template.retry.max-attempts=3 # Maximum number of attempts to deliver a message.
spring.rabbitmq.template.retry.max-interval=10000 # Maximum interval, in milliseconds, between attempts. spring.rabbitmq.template.retry.max-interval=10000ms # Maximum duration between attempts.
spring.rabbitmq.template.retry.multiplier=1 # Multiplier to apply to the previous retry interval. spring.rabbitmq.template.retry.multiplier=1 # Multiplier to apply to the previous retry interval.
spring.rabbitmq.template.routing-key= # Value of a default routing key to use for send operations. spring.rabbitmq.template.routing-key= # Value of a default routing key to use for send operations.
spring.rabbitmq.username=guest # Login user to authenticate to the broker. spring.rabbitmq.username=guest # Login user to authenticate to the broker.

Loading…
Cancel
Save