Skip to content

Commit

Permalink
GH-1517: Docs and Polishing for Composite Cust.
Browse files Browse the repository at this point in the history
  • Loading branch information
garyrussell committed Oct 18, 2022
1 parent aa86a02 commit b9b83f9
Show file tree
Hide file tree
Showing 3 changed files with 82 additions and 3 deletions.
@@ -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);
}

}
2 changes: 2 additions & 0 deletions src/reference/asciidoc/amqp.adoc
Expand Up @@ -2598,6 +2598,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.

Expand Down

0 comments on commit b9b83f9

Please sign in to comment.