From 127e5b4648c992f753d9221ac688b1fd68197895 Mon Sep 17 00:00:00 2001 From: Gary Russell Date: Fri, 7 Feb 2020 10:57:28 -0500 Subject: [PATCH] Add isConsumerBatchEnabled() to listener container In preparation for https://github.com/spring-projects/spring-integration/issues/3172 Allow the inbound endpoint to detect if its listener container is configured to return batches. --- .../rabbit/listener/MessageListenerContainer.java | 12 +++++++++++- .../listener/SimpleMessageListenerContainer.java | 7 ++++++- ...essageListenerContainerRetryIntegrationTests.java | 3 ++- 3 files changed, 19 insertions(+), 3 deletions(-) diff --git a/spring-rabbit/src/main/java/org/springframework/amqp/rabbit/listener/MessageListenerContainer.java b/spring-rabbit/src/main/java/org/springframework/amqp/rabbit/listener/MessageListenerContainer.java index ed9620a457..e4d8edac69 100644 --- a/spring-rabbit/src/main/java/org/springframework/amqp/rabbit/listener/MessageListenerContainer.java +++ b/spring-rabbit/src/main/java/org/springframework/amqp/rabbit/listener/MessageListenerContainer.java @@ -1,5 +1,5 @@ /* - * Copyright 2014-2019 the original author or authors. + * Copyright 2014-2020 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -47,4 +47,14 @@ default void lazyLoad() { // no-op } + /** + * Return true if this container is capable of (and configured to) create batches + * of consumed messages. + * @return true if enabled. + * @since 2.2.4 + */ + default boolean isConsumerBatchEnabled() { + return false; + } + } diff --git a/spring-rabbit/src/main/java/org/springframework/amqp/rabbit/listener/SimpleMessageListenerContainer.java b/spring-rabbit/src/main/java/org/springframework/amqp/rabbit/listener/SimpleMessageListenerContainer.java index b01ae8a83b..cec60c212d 100644 --- a/spring-rabbit/src/main/java/org/springframework/amqp/rabbit/listener/SimpleMessageListenerContainer.java +++ b/spring-rabbit/src/main/java/org/springframework/amqp/rabbit/listener/SimpleMessageListenerContainer.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2019 the original author or authors. + * Copyright 2002-2020 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -378,6 +378,11 @@ public void setConsumerBatchEnabled(boolean consumerBatchEnabled) { this.consumerBatchEnabled = consumerBatchEnabled; } + @Override + public boolean isConsumerBatchEnabled() { + return this.consumerBatchEnabled; + } + /** * {@inheritDoc} *

diff --git a/spring-rabbit/src/test/java/org/springframework/amqp/rabbit/listener/MessageListenerContainerRetryIntegrationTests.java b/spring-rabbit/src/test/java/org/springframework/amqp/rabbit/listener/MessageListenerContainerRetryIntegrationTests.java index b96b3a1e1b..97bcd4ff34 100644 --- a/spring-rabbit/src/test/java/org/springframework/amqp/rabbit/listener/MessageListenerContainerRetryIntegrationTests.java +++ b/spring-rabbit/src/test/java/org/springframework/amqp/rabbit/listener/MessageListenerContainerRetryIntegrationTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2019 the original author or authors. + * Copyright 2002-2020 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -112,6 +112,7 @@ private void doTestRetryWithBatchListener(boolean stateful) throws Exception { }); container.setAcknowledgeMode(AcknowledgeMode.AUTO); container.setConsumerBatchEnabled(true); + assertThat(container.isConsumerBatchEnabled()).isTrue(); container.setBatchSize(2); final CountDownLatch latch = new CountDownLatch(1);