GH-1517: Docs and Polishing for Composite Cust.
This commit is contained in:
@@ -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<C>} providing the configuration of multiple customizers at the same time.
|
||||
* Implementation of {@link ContainerCustomizer<C>} providing the configuration of
|
||||
* multiple customizers at the same time.
|
||||
*
|
||||
* @param <C> the container type.
|
||||
*
|
||||
* @author Rene Felgentraeger
|
||||
* @author Gary Russell
|
||||
*/
|
||||
public class CompositeContainerCustomizer<C extends MessageListenerContainer> implements ContainerCustomizer<C> {
|
||||
|
||||
private final List<ContainerCustomizer<C>> customizers;
|
||||
private final List<ContainerCustomizer<C>> customizers = new ArrayList<>();
|
||||
|
||||
/**
|
||||
* Create an instance with the provided delegate customizers.
|
||||
* @param customizers the customizers.
|
||||
*/
|
||||
public CompositeContainerCustomizer(List<ContainerCustomizer<C>> 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));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -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<MessageListenerContainer> mock1 = mock(ContainerCustomizer.class);
|
||||
ContainerCustomizer<MessageListenerContainer> mock2 = mock(ContainerCustomizer.class);
|
||||
CompositeContainerCustomizer<MessageListenerContainer> cust = new CompositeContainerCustomizer<>(
|
||||
List.of(mock1, mock2));
|
||||
MessageListenerContainer mlc = mock(MessageListenerContainer.class);
|
||||
cust.configure(mlc);
|
||||
verify(mock1).configure(mlc);
|
||||
verify(mock2).configure(mlc);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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.
|
||||
|
||||
|
||||
Reference in New Issue
Block a user