Skip to content

Commit 13b736b

Browse files
committed
Migrate remaining duration-based properties for Rabbit
Closes gh-12192
1 parent 48656d0 commit 13b736b

File tree

4 files changed

+38
-38
lines changed

4 files changed

+38
-38
lines changed

spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/amqp/AbstractRabbitListenerContainerFactoryConfigurer.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2017 the original author or authors.
2+
* Copyright 2012-2018 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -108,8 +108,8 @@ protected void configure(T factory, ConnectionFactory connectionFactory,
108108
? RetryInterceptorBuilder.stateless()
109109
: RetryInterceptorBuilder.stateful());
110110
builder.maxAttempts(retryConfig.getMaxAttempts());
111-
builder.backOffOptions(retryConfig.getInitialInterval(),
112-
retryConfig.getMultiplier(), retryConfig.getMaxInterval());
111+
builder.backOffOptions(retryConfig.getInitialInterval().toMillis(),
112+
retryConfig.getMultiplier(), retryConfig.getMaxInterval().toMillis());
113113
MessageRecoverer recoverer = (this.messageRecoverer != null
114114
? this.messageRecoverer : new RejectAndDontRequeueRecoverer());
115115
builder.recoverer(recoverer);

spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/amqp/RabbitAutoConfiguration.java

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2017 the original author or authors.
2+
* Copyright 2012-2018 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -102,7 +102,7 @@ public CachingConnectionFactory rabbitConnectionFactory(
102102
map.from(properties::isPublisherReturns).to(factory::setPublisherReturns);
103103
RabbitProperties.Cache.Channel channel = properties.getCache().getChannel();
104104
map.from(channel::getSize).whenNonNull().to(factory::setChannelCacheSize);
105-
map.from(channel::getCheckoutTimeout).whenNonNull()
105+
map.from(channel::getCheckoutTimeout).whenNonNull().as(Duration::toMillis)
106106
.to(factory::setChannelCheckoutTimeout);
107107
RabbitProperties.Cache.Connection connection = properties.getCache()
108108
.getConnection();
@@ -175,9 +175,9 @@ public RabbitTemplate rabbitTemplate(ConnectionFactory connectionFactory) {
175175
if (properties.getRetry().isEnabled()) {
176176
template.setRetryTemplate(createRetryTemplate(properties.getRetry()));
177177
}
178-
map.from(properties::getReceiveTimeout).whenNonNull()
178+
map.from(properties::getReceiveTimeout).whenNonNull().as(Duration::toMillis)
179179
.to(template::setReceiveTimeout);
180-
map.from(properties::getReplyTimeout).whenNonNull()
180+
map.from(properties::getReplyTimeout).whenNonNull().as(Duration::toMillis)
181181
.to(template::setReplyTimeout);
182182
map.from(properties::getExchange).to(template::setExchange);
183183
map.from(properties::getRoutingKey).to(template::setRoutingKey);
@@ -196,10 +196,11 @@ private RetryTemplate createRetryTemplate(RabbitProperties.Retry properties) {
196196
map.from(properties::getMaxAttempts).to(policy::setMaxAttempts);
197197
template.setRetryPolicy(policy);
198198
ExponentialBackOffPolicy backOffPolicy = new ExponentialBackOffPolicy();
199-
map.from(properties::getInitialInterval)
199+
map.from(properties::getInitialInterval).whenNonNull().as(Duration::toMillis)
200200
.to(backOffPolicy::setInitialInterval);
201201
map.from(properties::getMultiplier).to(backOffPolicy::setMultiplier);
202-
map.from(properties::getMaxInterval).to(backOffPolicy::setMaxInterval);
202+
map.from(properties::getMaxInterval).whenNonNull().as(Duration::toMillis)
203+
.to(backOffPolicy::setMaxInterval);
203204
template.setBackOffPolicy(backOffPolicy);
204205
return template;
205206
}

spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/amqp/RabbitProperties.java

Lines changed: 22 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -438,10 +438,10 @@ public static class Channel {
438438
private Integer size;
439439

440440
/**
441-
* Number of milliseconds to wait to obtain a channel if the cache size has
442-
* been reached. If 0, always create a new channel.
441+
* Duration to wait to obtain a channel if the cache size has been reached. If
442+
* 0, always create a new channel.
443443
*/
444-
private Long checkoutTimeout;
444+
private Duration checkoutTimeout;
445445

446446
public Integer getSize() {
447447
return this.size;
@@ -451,14 +451,13 @@ public void setSize(Integer size) {
451451
this.size = size;
452452
}
453453

454-
public Long getCheckoutTimeout() {
454+
public Duration getCheckoutTimeout() {
455455
return this.checkoutTimeout;
456456
}
457457

458-
public void setCheckoutTimeout(Long checkoutTimeout) {
458+
public void setCheckoutTimeout(Duration checkoutTimeout) {
459459
this.checkoutTimeout = checkoutTimeout;
460460
}
461-
462461
}
463462

464463
public static class Connection {
@@ -696,12 +695,12 @@ public static class Template {
696695
/**
697696
* Timeout for `receive()` operations.
698697
*/
699-
private Long receiveTimeout;
698+
private Duration receiveTimeout;
700699

701700
/**
702701
* Timeout for `sendAndReceive()` operations.
703702
*/
704-
private Long replyTimeout;
703+
private Duration replyTimeout;
705704

706705
/**
707706
* Name of the default exchange to use for send operations.
@@ -725,19 +724,19 @@ public void setMandatory(Boolean mandatory) {
725724
this.mandatory = mandatory;
726725
}
727726

728-
public Long getReceiveTimeout() {
727+
public Duration getReceiveTimeout() {
729728
return this.receiveTimeout;
730729
}
731730

732-
public void setReceiveTimeout(Long receiveTimeout) {
731+
public void setReceiveTimeout(Duration receiveTimeout) {
733732
this.receiveTimeout = receiveTimeout;
734733
}
735734

736-
public Long getReplyTimeout() {
735+
public Duration getReplyTimeout() {
737736
return this.replyTimeout;
738737
}
739738

740-
public void setReplyTimeout(Long replyTimeout) {
739+
public void setReplyTimeout(Duration replyTimeout) {
741740
this.replyTimeout = replyTimeout;
742741
}
743742

@@ -772,19 +771,19 @@ public static class Retry {
772771
private int maxAttempts = 3;
773772

774773
/**
775-
* Interval, in milliseconds, between the first and second attempt to deliver a message.
774+
* Duration between the first and second attempt to deliver a message.
776775
*/
777-
private long initialInterval = 1000L;
776+
private Duration initialInterval = Duration.ofMillis(1000);
778777

779778
/**
780779
* Multiplier to apply to the previous retry interval.
781780
*/
782781
private double multiplier = 1.0;
783782

784783
/**
785-
* Maximum interval, in milliseconds, between attempts.
784+
* Maximum duration between attempts.
786785
*/
787-
private long maxInterval = 10000L;
786+
private Duration maxInterval = Duration.ofMillis(10000);
788787

789788
public boolean isEnabled() {
790789
return this.enabled;
@@ -802,14 +801,18 @@ public void setMaxAttempts(int maxAttempts) {
802801
this.maxAttempts = maxAttempts;
803802
}
804803

805-
public long getInitialInterval() {
804+
public Duration getInitialInterval() {
806805
return this.initialInterval;
807806
}
808807

809-
public void setInitialInterval(long initialInterval) {
808+
public void setInitialInterval(Duration initialInterval) {
810809
this.initialInterval = initialInterval;
811810
}
812811

812+
public void setMaxInterval(Duration maxInterval) {
813+
this.maxInterval = maxInterval;
814+
}
815+
813816
public double getMultiplier() {
814817
return this.multiplier;
815818
}
@@ -818,14 +821,10 @@ public void setMultiplier(double multiplier) {
818821
this.multiplier = multiplier;
819822
}
820823

821-
public long getMaxInterval() {
824+
public Duration getMaxInterval() {
822825
return this.maxInterval;
823826
}
824827

825-
public void setMaxInterval(long maxInterval) {
826-
this.maxInterval = maxInterval;
827-
}
828-
829828
}
830829

831830
public static class ListenerRetry extends Retry {

spring-boot-project/spring-boot-docs/src/main/asciidoc/appendix-application-properties.adoc

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1071,9 +1071,9 @@ content into your application. Rather, pick only the properties that you need.
10711071
spring.rabbitmq.listener.direct.idle-event-interval= # How often idle container events should be published.
10721072
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).
10731073
spring.rabbitmq.listener.direct.retry.enabled=false # Whether publishing retries are enabled.
1074-
spring.rabbitmq.listener.direct.retry.initial-interval=1000ms # Interval, in milliseconds, between the first and second attempt to deliver a message.
1074+
spring.rabbitmq.listener.direct.retry.initial-interval=1000ms # Duration between the first and second attempt to deliver a message.
10751075
spring.rabbitmq.listener.direct.retry.max-attempts=3 # Maximum number of attempts to deliver a message.
1076-
spring.rabbitmq.listener.direct.retry.max-interval=10000ms # Maximum interval, in milliseconds, between attempts.
1076+
spring.rabbitmq.listener.direct.retry.max-interval=10000ms # Maximum duration between attempts.
10771077
spring.rabbitmq.listener.direct.retry.multiplier=1 # Multiplier to apply to the previous retry interval.
10781078
spring.rabbitmq.listener.direct.retry.stateless=true # Whether retries are stateless or stateful.
10791079
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.
10841084
spring.rabbitmq.listener.simple.max-concurrency= # Maximum number of listener invoker threads.
10851085
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).
10861086
spring.rabbitmq.listener.simple.retry.enabled=false # Whether publishing retries are enabled.
1087-
spring.rabbitmq.listener.simple.retry.initial-interval=1000 # Interval, in milliseconds, between the first and second attempt to deliver a message.
1087+
spring.rabbitmq.listener.simple.retry.initial-interval=1000ms # Duration between the first and second attempt to deliver a message.
10881088
spring.rabbitmq.listener.simple.retry.max-attempts=3 # Maximum number of attempts to deliver a message.
1089-
spring.rabbitmq.listener.simple.retry.max-interval=10000 # Maximum interval, in milliseconds, between attempts.
1089+
spring.rabbitmq.listener.simple.retry.max-interval=10000ms # Maximum duration between attempts.
10901090
spring.rabbitmq.listener.simple.retry.multiplier=1 # Multiplier to apply to the previous retry interval.
10911091
spring.rabbitmq.listener.simple.retry.stateless=true # Whether retries are stateless or stateful.
10921092
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.
11091109
spring.rabbitmq.template.receive-timeout= # Timeout for `receive()` operations.
11101110
spring.rabbitmq.template.reply-timeout= # Timeout for `sendAndReceive()` operations.
11111111
spring.rabbitmq.template.retry.enabled=false # Whether publishing retries are enabled.
1112-
spring.rabbitmq.template.retry.initial-interval=1000 # Interval, in milliseconds, between the first and second attempt to deliver a message.
1112+
spring.rabbitmq.template.retry.initial-interval=1000ms # Duration between the first and second attempt to deliver a message.
11131113
spring.rabbitmq.template.retry.max-attempts=3 # Maximum number of attempts to deliver a message.
1114-
spring.rabbitmq.template.retry.max-interval=10000 # Maximum interval, in milliseconds, between attempts.
1114+
spring.rabbitmq.template.retry.max-interval=10000ms # Maximum duration between attempts.
11151115
spring.rabbitmq.template.retry.multiplier=1 # Multiplier to apply to the previous retry interval.
11161116
spring.rabbitmq.template.routing-key= # Value of a default routing key to use for send operations.
11171117
spring.rabbitmq.username=guest # Login user to authenticate to the broker.

0 commit comments

Comments
 (0)