Polish "Add configuration options for RabbitMQ's batch listener config"

See gh-23766
This commit is contained in:
Stephane Nicoll 2020-10-21 08:49:34 +02:00
parent 3aa247f1ca
commit 17e12ea025
2 changed files with 29 additions and 13 deletions

View File

@ -663,7 +663,8 @@ public class RabbitProperties {
private Duration idleEventInterval;
/**
* Whether to present batched messages (created by a BatchingRabbitTemplate) as discrete messages.
* Whether the container should present batched messages as discrete messages or
* call the listener with the batch.
*/
private boolean deBatchingEnabled = true;
@ -715,7 +716,7 @@ public class RabbitProperties {
public abstract boolean isMissingQueuesFatal();
public boolean isDeBatchingEnabled() {
return deBatchingEnabled;
return this.deBatchingEnabled;
}
public void setDeBatchingEnabled(boolean deBatchingEnabled) {
@ -757,9 +758,10 @@ public class RabbitProperties {
private boolean missingQueuesFatal = true;
/**
* When true, the container will create a batch of messages based on the 'receiveTimeout' and 'batchSize'.
* Coerces 'deBatchingEnabled' to true to include the contents of a producer created batch in the batch as
* discrete records.
* Whether the container creates a batch of messages based on the
* 'receive-timeout' and 'batch-size'. Coerces 'de-batching-enabled' to true to
* include the contents of a producer created batch in the batch as discrete
* records.
*/
private boolean consumerBatchEnabled;
@ -797,7 +799,7 @@ public class RabbitProperties {
}
public boolean isConsumerBatchEnabled() {
return consumerBatchEnabled;
return this.consumerBatchEnabled;
}
public void setConsumerBatchEnabled(boolean consumerBatchEnabled) {

View File

@ -33,8 +33,9 @@ import com.rabbitmq.client.impl.CredentialsRefreshService;
import com.rabbitmq.client.impl.DefaultCredentialsProvider;
import org.aopalliance.aop.Advice;
import org.junit.jupiter.api.Test;
import org.mockito.InOrder;
import org.mockito.Mockito;
import org.springframework.amqp.core.AcknowledgeMode;
import org.springframework.amqp.core.AmqpAdmin;
import org.springframework.amqp.core.Message;
@ -76,7 +77,8 @@ import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.ArgumentMatchers.isNull;
import static org.mockito.BDDMockito.given;
import static org.mockito.Mockito.*;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;
/**
* Tests for {@link RabbitAutoConfiguration}.
@ -538,7 +540,22 @@ class RabbitAutoConfigurationTests {
.withPropertyValues("spring.rabbitmq.listener.type:direct",
"spring.rabbitmq.listener.simple.concurrency:5",
"spring.rabbitmq.listener.simple.maxConcurrency:10",
"spring.rabbitmq.listener.simple.prefetch:40",
"spring.rabbitmq.listener.simple.prefetch:40")
.run((context) -> {
SimpleRabbitListenerContainerFactoryConfigurer configurer = context
.getBean(SimpleRabbitListenerContainerFactoryConfigurer.class);
SimpleRabbitListenerContainerFactory factory = mock(SimpleRabbitListenerContainerFactory.class);
configurer.configure(factory, mock(ConnectionFactory.class));
verify(factory).setConcurrentConsumers(5);
verify(factory).setMaxConcurrentConsumers(10);
verify(factory).setPrefetchCount(40);
});
}
@Test
void testSimpleRabbitListenerContainerFactoryConfigurerEnableDeBatchingWithConsumerBatchEnabled() {
this.contextRunner.withUserConfiguration(TestConfiguration.class)
.withPropertyValues("spring.rabbitmq.listener.type:direct",
"spring.rabbitmq.listener.simple.consumer-batch-enabled:true",
"spring.rabbitmq.listener.simple.de-batching-enabled:false")
.run((context) -> {
@ -546,10 +563,7 @@ class RabbitAutoConfigurationTests {
.getBean(SimpleRabbitListenerContainerFactoryConfigurer.class);
SimpleRabbitListenerContainerFactory factory = mock(SimpleRabbitListenerContainerFactory.class);
configurer.configure(factory, mock(ConnectionFactory.class));
InOrder inOrder = inOrder(factory);
verify(factory).setConcurrentConsumers(5);
verify(factory).setMaxConcurrentConsumers(10);
verify(factory).setPrefetchCount(40);
InOrder inOrder = Mockito.inOrder(factory);
verify(factory).setConsumerBatchEnabled(true);
inOrder.verify(factory).setDeBatchingEnabled(false);
inOrder.verify(factory).setDeBatchingEnabled(true);