Skip to content

Commit b63cd5b

Browse files
committed
GH-1517: Docs and Polishing for Composite Cust.
1 parent b3bab6b commit b63cd5b

File tree

3 files changed

+82
-3
lines changed

3 files changed

+82
-3
lines changed
Lines changed: 32 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,52 @@
1+
/*
2+
* Copyright 2022 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
117
package org.springframework.amqp.rabbit.config;
218

19+
import java.util.ArrayList;
320
import java.util.List;
21+
422
import org.springframework.amqp.rabbit.listener.MessageListenerContainer;
523
import org.springframework.util.Assert;
624

725
/**
8-
* Implementation of {@link ContainerCustomizer<C>} providing the configuration of multiple customizers at the same time.
26+
* Implementation of {@link ContainerCustomizer<C>} providing the configuration of
27+
* multiple customizers at the same time.
28+
*
29+
* @param <C> the container type.
30+
*
31+
* @author Rene Felgentraeger
32+
* @author Gary Russell
933
*/
1034
public class CompositeContainerCustomizer<C extends MessageListenerContainer> implements ContainerCustomizer<C> {
1135

12-
private final List<ContainerCustomizer<C>> customizers;
36+
private final List<ContainerCustomizer<C>> customizers = new ArrayList<>();
1337

38+
/**
39+
* Create an instance with the provided delegate customizers.
40+
* @param customizers the customizers.
41+
*/
1442
public CompositeContainerCustomizer(List<ContainerCustomizer<C>> customizers) {
1543
Assert.notNull(customizers, "At least one customizer must be present");
16-
this.customizers = customizers;
44+
this.customizers.addAll(customizers);
1745
}
1846

1947
@Override
2048
public void configure(C container) {
2149
customizers.forEach(c -> c.configure(container));
2250
}
51+
2352
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
/*
2+
* Copyright 2022 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package org.springframework.amqp.rabbit.config;
18+
19+
import static org.mockito.Mockito.mock;
20+
import static org.mockito.Mockito.verify;
21+
22+
import java.util.List;
23+
24+
import org.junit.jupiter.api.Test;
25+
26+
import org.springframework.amqp.rabbit.listener.MessageListenerContainer;
27+
28+
/**
29+
* @author Gary Russell
30+
* @since 2.4.8
31+
*
32+
*/
33+
public class CompositeContainerCustomizerTests {
34+
35+
@SuppressWarnings("unchecked")
36+
@Test
37+
void allCalled() {
38+
ContainerCustomizer<MessageListenerContainer> mock1 = mock(ContainerCustomizer.class);
39+
ContainerCustomizer<MessageListenerContainer> mock2 = mock(ContainerCustomizer.class);
40+
CompositeContainerCustomizer<MessageListenerContainer> cust = new CompositeContainerCustomizer<>(
41+
List.of(mock1, mock2));
42+
MessageListenerContainer mlc = mock(MessageListenerContainer.class);
43+
cust.configure(mlc);
44+
verify(mock1).configure(mlc);
45+
verify(mock2).configure(mlc);
46+
}
47+
48+
}

src/reference/asciidoc/amqp.adoc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2597,6 +2597,8 @@ NOTE: For information to help you choose between `SimpleRabbitListenerContainerF
25972597
Starting wih version 2.2.2, you can provide a `ContainerCustomizer` implementation (as shown above).
25982598
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.
25992599

2600+
Version 2.4.8 provides the `CompositeContainerCustomizer` for situations where you wish to apply multiple customizers.
2601+
26002602
By default, the infrastructure looks for a bean named `rabbitListenerContainerFactory` as the source for the factory to use to create message listener containers.
26012603
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.
26022604

0 commit comments

Comments
 (0)