|
37 | 37 | import org.springframework.amqp.core.AmqpAdmin; |
38 | 38 | import org.springframework.amqp.core.Message; |
39 | 39 | import org.springframework.amqp.rabbit.annotation.EnableRabbit; |
| 40 | +import org.springframework.amqp.rabbit.annotation.RabbitListener; |
40 | 41 | import org.springframework.amqp.rabbit.config.AbstractRabbitListenerContainerFactory; |
| 42 | +import org.springframework.amqp.rabbit.config.ContainerCustomizer; |
41 | 43 | import org.springframework.amqp.rabbit.config.DirectRabbitListenerContainerFactory; |
42 | 44 | import org.springframework.amqp.rabbit.config.RabbitListenerConfigUtils; |
43 | 45 | import org.springframework.amqp.rabbit.config.SimpleRabbitListenerContainerFactory; |
|
49 | 51 | import org.springframework.amqp.rabbit.core.RabbitAdmin; |
50 | 52 | import org.springframework.amqp.rabbit.core.RabbitMessagingTemplate; |
51 | 53 | import org.springframework.amqp.rabbit.core.RabbitTemplate; |
| 54 | +import org.springframework.amqp.rabbit.listener.DirectMessageListenerContainer; |
52 | 55 | import org.springframework.amqp.rabbit.listener.RabbitListenerContainerFactory; |
| 56 | +import org.springframework.amqp.rabbit.listener.SimpleMessageListenerContainer; |
53 | 57 | import org.springframework.amqp.rabbit.retry.MessageRecoverer; |
54 | 58 | import org.springframework.amqp.support.converter.MessageConverter; |
55 | 59 | import org.springframework.beans.factory.NoSuchBeanDefinitionException; |
|
60 | 64 | import org.springframework.boot.test.system.OutputCaptureExtension; |
61 | 65 | import org.springframework.context.annotation.Bean; |
62 | 66 | import org.springframework.context.annotation.Configuration; |
| 67 | +import org.springframework.context.annotation.Import; |
63 | 68 | import org.springframework.context.annotation.Primary; |
64 | 69 | import org.springframework.core.Ordered; |
65 | 70 | import org.springframework.core.annotation.Order; |
|
74 | 79 |
|
75 | 80 | import static org.assertj.core.api.Assertions.assertThat; |
76 | 81 | import static org.assertj.core.api.Assertions.assertThatExceptionOfType; |
| 82 | +import static org.mockito.ArgumentMatchers.any; |
77 | 83 | import static org.mockito.ArgumentMatchers.anyString; |
78 | 84 | import static org.mockito.ArgumentMatchers.eq; |
79 | 85 | import static org.mockito.ArgumentMatchers.isNull; |
@@ -849,6 +855,23 @@ void whenMultipleConnectionFactoryCustomizersAreDefinedThenTheyAreCalledInOrder( |
849 | 855 | }); |
850 | 856 | } |
851 | 857 |
|
| 858 | + @Test |
| 859 | + @SuppressWarnings("unchecked") |
| 860 | + void whenASimpleContainerCustomizerIsDefinedThenItIsCalledToConfigureTheContainer() { |
| 861 | + this.contextRunner.withUserConfiguration(SimpleContainerCustomizerConfiguration.class) |
| 862 | + .run((context) -> verify(context.getBean(ContainerCustomizer.class)) |
| 863 | + .configure(any(SimpleMessageListenerContainer.class))); |
| 864 | + } |
| 865 | + |
| 866 | + @Test |
| 867 | + @SuppressWarnings("unchecked") |
| 868 | + void whenADirectContainerCustomizerIsDefinedThenItIsCalledToConfigureTheContainer() { |
| 869 | + this.contextRunner.withUserConfiguration(DirectContainerCustomizerConfiguration.class) |
| 870 | + .withPropertyValues("spring.rabbitmq.listener.type:direct") |
| 871 | + .run((context) -> verify(context.getBean(ContainerCustomizer.class)) |
| 872 | + .configure(any(DirectMessageListenerContainer.class))); |
| 873 | + } |
| 874 | + |
852 | 875 | private com.rabbitmq.client.ConnectionFactory getTargetConnectionFactory(AssertableApplicationContext context) { |
853 | 876 | CachingConnectionFactory connectionFactory = context.getBean(CachingConnectionFactory.class); |
854 | 877 | return connectionFactory.getRabbitConnectionFactory(); |
@@ -1113,4 +1136,36 @@ ConnectionFactoryCustomizer firstCustomizer() { |
1113 | 1136 |
|
1114 | 1137 | } |
1115 | 1138 |
|
| 1139 | + @Import(TestListener.class) |
| 1140 | + @Configuration(proxyBeanMethods = false) |
| 1141 | + static class SimpleContainerCustomizerConfiguration { |
| 1142 | + |
| 1143 | + @Bean |
| 1144 | + @SuppressWarnings("unchecked") |
| 1145 | + ContainerCustomizer<SimpleMessageListenerContainer> customizer() { |
| 1146 | + return mock(ContainerCustomizer.class); |
| 1147 | + } |
| 1148 | + |
| 1149 | + } |
| 1150 | + |
| 1151 | + @Import(TestListener.class) |
| 1152 | + @Configuration(proxyBeanMethods = false) |
| 1153 | + static class DirectContainerCustomizerConfiguration { |
| 1154 | + |
| 1155 | + @Bean |
| 1156 | + @SuppressWarnings("unchecked") |
| 1157 | + ContainerCustomizer<DirectMessageListenerContainer> customizer() { |
| 1158 | + return mock(ContainerCustomizer.class); |
| 1159 | + } |
| 1160 | + |
| 1161 | + } |
| 1162 | + |
| 1163 | + static class TestListener { |
| 1164 | + |
| 1165 | + @RabbitListener(queues = "test", autoStartup = "false") |
| 1166 | + void listen(String in) { |
| 1167 | + } |
| 1168 | + |
| 1169 | + } |
| 1170 | + |
1116 | 1171 | } |
0 commit comments