diff --git a/spring-rabbit/src/main/java/org/springframework/amqp/rabbit/config/CompositeContainerCustomizer.java b/spring-rabbit/src/main/java/org/springframework/amqp/rabbit/config/CompositeContainerCustomizer.java index 57e762e7..31c77171 100644 --- a/spring-rabbit/src/main/java/org/springframework/amqp/rabbit/config/CompositeContainerCustomizer.java +++ b/spring-rabbit/src/main/java/org/springframework/amqp/rabbit/config/CompositeContainerCustomizer.java @@ -1,23 +1,52 @@ +/* + * Copyright 2022 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. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + package org.springframework.amqp.rabbit.config; +import java.util.ArrayList; import java.util.List; + import org.springframework.amqp.rabbit.listener.MessageListenerContainer; import org.springframework.util.Assert; /** - * Implementation of {@link ContainerCustomizer} providing the configuration of multiple customizers at the same time. + * Implementation of {@link ContainerCustomizer} providing the configuration of + * multiple customizers at the same time. + * + * @param the container type. + * + * @author Rene Felgentraeger + * @author Gary Russell */ public class CompositeContainerCustomizer implements ContainerCustomizer { - private final List> customizers; + private final List> customizers = new ArrayList<>(); + /** + * Create an instance with the provided delegate customizers. + * @param customizers the customizers. + */ public CompositeContainerCustomizer(List> customizers) { Assert.notNull(customizers, "At least one customizer must be present"); - this.customizers = customizers; + this.customizers.addAll(customizers); } @Override public void configure(C container) { customizers.forEach(c -> c.configure(container)); } + } diff --git a/spring-rabbit/src/test/java/org/springframework/amqp/rabbit/config/CompositeContainerCustomizerTests.java b/spring-rabbit/src/test/java/org/springframework/amqp/rabbit/config/CompositeContainerCustomizerTests.java new file mode 100644 index 00000000..3162721c --- /dev/null +++ b/spring-rabbit/src/test/java/org/springframework/amqp/rabbit/config/CompositeContainerCustomizerTests.java @@ -0,0 +1,48 @@ +/* + * Copyright 2022 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. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.amqp.rabbit.config; + +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.verify; + +import java.util.List; + +import org.junit.jupiter.api.Test; + +import org.springframework.amqp.rabbit.listener.MessageListenerContainer; + +/** + * @author Gary Russell + * @since 2.4.8 + * + */ +public class CompositeContainerCustomizerTests { + + @SuppressWarnings("unchecked") + @Test + void allCalled() { + ContainerCustomizer mock1 = mock(ContainerCustomizer.class); + ContainerCustomizer mock2 = mock(ContainerCustomizer.class); + CompositeContainerCustomizer cust = new CompositeContainerCustomizer<>( + List.of(mock1, mock2)); + MessageListenerContainer mlc = mock(MessageListenerContainer.class); + cust.configure(mlc); + verify(mock1).configure(mlc); + verify(mock2).configure(mlc); + } + +} diff --git a/src/reference/asciidoc/amqp.adoc b/src/reference/asciidoc/amqp.adoc index 1dbe3d33..15da14df 100644 --- a/src/reference/asciidoc/amqp.adoc +++ b/src/reference/asciidoc/amqp.adoc @@ -2597,6 +2597,8 @@ NOTE: For information to help you choose between `SimpleRabbitListenerContainerF Starting wih version 2.2.2, you can provide a `ContainerCustomizer` implementation (as shown above). This can be used to further configure the container after it has been created and configured; you can use this, for example, to set properties that are not exposed by the container factory. +Version 2.4.8 provides the `CompositeContainerCustomizer` for situations where you wish to apply multiple customizers. + By default, the infrastructure looks for a bean named `rabbitListenerContainerFactory` as the source for the factory to use to create message listener containers. In this case, and ignoring the RabbitMQ infrastructure setup, the `processOrder` method can be invoked with a core poll size of three threads and a maximum pool size of ten threads.