Skip to content

Commit afe3ab7

Browse files
committed
Merge pull request #17587 from dreis2211
* pr/17587: Polish "Adjust to changes in Spring AMQP 2.2 snapshots" Adjust to changes in Spring AMQP 2.2 snapshots Closes gh-17587
2 parents e5ca9df + 3dd5426 commit afe3ab7

File tree

3 files changed

+50
-12
lines changed

3 files changed

+50
-12
lines changed

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

Lines changed: 28 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
import org.springframework.amqp.core.AcknowledgeMode;
2525
import org.springframework.amqp.rabbit.connection.CachingConnectionFactory.CacheMode;
2626
import org.springframework.boot.context.properties.ConfigurationProperties;
27+
import org.springframework.boot.context.properties.DeprecatedConfigurationProperty;
2728
import org.springframework.boot.convert.DurationUnit;
2829
import org.springframework.util.CollectionUtils;
2930
import org.springframework.util.StringUtils;
@@ -662,10 +663,10 @@ public static class SimpleContainer extends AmqpContainer {
662663
private Integer maxConcurrency;
663664

664665
/**
665-
* Number of messages to be processed between acks when the acknowledge mode is
666-
* AUTO. If larger than prefetch, prefetch will be increased to this value.
666+
* Batch size, expressed as the number of physical messages, to be used by the
667+
* container.
667668
*/
668-
private Integer transactionSize;
669+
private Integer batchSize;
669670

670671
/**
671672
* Whether to fail if the queues declared by the container are not available on
@@ -690,12 +691,34 @@ public void setMaxConcurrency(Integer maxConcurrency) {
690691
this.maxConcurrency = maxConcurrency;
691692
}
692693

694+
/**
695+
* Return the number of messages processed in one transaction.
696+
* @return the number of messages
697+
* @deprecated since 2.2.0 in favor of {@link SimpleContainer#getBatchSize()}
698+
*/
699+
@DeprecatedConfigurationProperty(replacement = "spring.rabbitmq.listener.simple.batch-size")
700+
@Deprecated
693701
public Integer getTransactionSize() {
694-
return this.transactionSize;
702+
return getBatchSize();
695703
}
696704

705+
/**
706+
* Set the number of messages processed in one transaction.
707+
* @param transactionSize the number of messages
708+
* @deprecated since 2.2.0 in favor of
709+
* {@link SimpleContainer#setBatchSize(Integer)}
710+
*/
711+
@Deprecated
697712
public void setTransactionSize(Integer transactionSize) {
698-
this.transactionSize = transactionSize;
713+
setBatchSize(transactionSize);
714+
}
715+
716+
public Integer getBatchSize() {
717+
return this.batchSize;
718+
}
719+
720+
public void setBatchSize(Integer batchSize) {
721+
this.batchSize = batchSize;
699722
}
700723

701724
@Override

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ public void configure(SimpleRabbitListenerContainerFactory factory, ConnectionFa
3838
configure(factory, connectionFactory, config);
3939
map.from(config::getConcurrency).whenNonNull().to(factory::setConcurrentConsumers);
4040
map.from(config::getMaxConcurrency).whenNonNull().to(factory::setMaxConcurrentConsumers);
41-
map.from(config::getTransactionSize).whenNonNull().to(factory::setTxSize);
41+
map.from(config::getBatchSize).whenNonNull().to(factory::setBatchSize);
4242
}
4343

4444
}

spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/amqp/RabbitAutoConfigurationTests.java

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
package org.springframework.boot.autoconfigure.amqp;
1818

1919
import java.security.NoSuchAlgorithmException;
20+
import java.util.List;
2021
import java.util.concurrent.atomic.AtomicInteger;
2122

2223
import javax.net.ssl.SSLContext;
@@ -125,6 +126,7 @@ void testDefaultConnectionFactoryConfiguration() {
125126
}
126127

127128
@Test
129+
@SuppressWarnings("unchecked")
128130
void testConnectionFactoryWithOverrides() {
129131
this.contextRunner.withUserConfiguration(TestConfiguration.class)
130132
.withPropertyValues("spring.rabbitmq.host:remote-server", "spring.rabbitmq.port:9000",
@@ -137,15 +139,16 @@ void testConnectionFactoryWithOverrides() {
137139
assertThat(connectionFactory.getVirtualHost()).isEqualTo("/vhost");
138140
com.rabbitmq.client.ConnectionFactory rcf = connectionFactory.getRabbitConnectionFactory();
139141
assertThat(rcf.getConnectionTimeout()).isEqualTo(123);
140-
assertThat((Address[]) ReflectionTestUtils.getField(connectionFactory, "addresses")).hasSize(1);
142+
assertThat((List<Address>) ReflectionTestUtils.getField(connectionFactory, "addresses")).hasSize(1);
141143
});
142144
}
143145

144146
@Test
147+
@SuppressWarnings("unchecked")
145148
void testConnectionFactoryWithCustomConnectionNameStrategy() {
146149
this.contextRunner.withUserConfiguration(ConnectionNameStrategyConfiguration.class).run((context) -> {
147150
CachingConnectionFactory connectionFactory = context.getBean(CachingConnectionFactory.class);
148-
Address[] addresses = (Address[]) ReflectionTestUtils.getField(connectionFactory, "addresses");
151+
List<Address> addresses = (List<Address>) ReflectionTestUtils.getField(connectionFactory, "addresses");
149152
assertThat(addresses).hasSize(1);
150153
com.rabbitmq.client.ConnectionFactory rcf = mock(com.rabbitmq.client.ConnectionFactory.class);
151154
given(rcf.newConnection(isNull(), eq(addresses), anyString())).willReturn(mock(Connection.class));
@@ -363,8 +366,8 @@ void testRabbitListenerContainerFactoryBackOff() {
363366
this.contextRunner.withUserConfiguration(TestConfiguration5.class).run((context) -> {
364367
SimpleRabbitListenerContainerFactory rabbitListenerContainerFactory = context
365368
.getBean("rabbitListenerContainerFactory", SimpleRabbitListenerContainerFactory.class);
366-
rabbitListenerContainerFactory.setTxSize(10);
367-
verify(rabbitListenerContainerFactory).setTxSize(10);
369+
rabbitListenerContainerFactory.setBatchSize(10);
370+
verify(rabbitListenerContainerFactory).setBatchSize(10);
368371
assertThat(rabbitListenerContainerFactory.getAdviceChain()).isNull();
369372
});
370373
}
@@ -385,20 +388,32 @@ void testSimpleRabbitListenerContainerFactoryWithCustomSettings() {
385388
"spring.rabbitmq.listener.simple.prefetch:40",
386389
"spring.rabbitmq.listener.simple.defaultRequeueRejected:false",
387390
"spring.rabbitmq.listener.simple.idleEventInterval:5",
388-
"spring.rabbitmq.listener.simple.transactionSize:20",
391+
"spring.rabbitmq.listener.simple.batchSize:20",
389392
"spring.rabbitmq.listener.simple.missingQueuesFatal:false")
390393
.run((context) -> {
391394
SimpleRabbitListenerContainerFactory rabbitListenerContainerFactory = context
392395
.getBean("rabbitListenerContainerFactory", SimpleRabbitListenerContainerFactory.class);
393396
assertThat(rabbitListenerContainerFactory).hasFieldOrPropertyWithValue("concurrentConsumers", 5);
394397
assertThat(rabbitListenerContainerFactory).hasFieldOrPropertyWithValue("maxConcurrentConsumers",
395398
10);
396-
assertThat(rabbitListenerContainerFactory).hasFieldOrPropertyWithValue("txSize", 20);
399+
assertThat(rabbitListenerContainerFactory).hasFieldOrPropertyWithValue("batchSize", 20);
397400
assertThat(rabbitListenerContainerFactory).hasFieldOrPropertyWithValue("missingQueuesFatal", false);
398401
checkCommonProps(context, rabbitListenerContainerFactory);
399402
});
400403
}
401404

405+
@Test
406+
@Deprecated
407+
void testRabbitListenerContainerFactoryWithDeprecatedTransactionSizeStillWorks() {
408+
this.contextRunner
409+
.withUserConfiguration(MessageConvertersConfiguration.class, MessageRecoverersConfiguration.class)
410+
.withPropertyValues("spring.rabbitmq.listener.simple.transactionSize:20").run((context) -> {
411+
SimpleRabbitListenerContainerFactory rabbitListenerContainerFactory = context
412+
.getBean("rabbitListenerContainerFactory", SimpleRabbitListenerContainerFactory.class);
413+
assertThat(rabbitListenerContainerFactory).hasFieldOrPropertyWithValue("batchSize", 20);
414+
});
415+
}
416+
402417
@Test
403418
void testDirectRabbitListenerContainerFactoryWithCustomSettings() {
404419
this.contextRunner

0 commit comments

Comments
 (0)