Skip to content

Commit 7d58393

Browse files
committed
Auto-configure stream template and env irrespective of listener type
Closes spring-projectsgh-32477
1 parent 9d30de9 commit 7d58393

File tree

2 files changed

+14
-14
lines changed

2 files changed

+14
-14
lines changed

spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/amqp/RabbitStreamConfiguration.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,11 +47,11 @@
4747
*/
4848
@Configuration(proxyBeanMethods = false)
4949
@ConditionalOnClass(StreamRabbitListenerContainerFactory.class)
50-
@ConditionalOnProperty(prefix = "spring.rabbitmq.listener", name = "type", havingValue = "stream")
5150
class RabbitStreamConfiguration {
5251

5352
@Bean(name = "rabbitListenerContainerFactory")
5453
@ConditionalOnMissingBean(name = "rabbitListenerContainerFactory")
54+
@ConditionalOnProperty(prefix = "spring.rabbitmq.listener", name = "type", havingValue = "stream")
5555
StreamRabbitListenerContainerFactory streamRabbitListenerContainerFactory(Environment rabbitStreamEnvironment,
5656
RabbitProperties properties, ObjectProvider<ConsumerCustomizer> consumerCustomizer,
5757
ObjectProvider<ContainerCustomizer<StreamListenerContainer>> containerCustomizer) {

spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/amqp/RabbitStreamConfigurationTests.java

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,11 @@ void whenNativeListenerIsEnabledThenContainerFactoryIsConfiguredToUseNativeListe
8080
.extracting("nativeListener", InstanceOfAssertFactories.BOOLEAN).isTrue());
8181
}
8282

83+
@Test
84+
void environmentIsAutoConfiguredByDefault() {
85+
this.contextRunner.run((context) -> assertThat(context).hasSingleBean(Environment.class));
86+
}
87+
8388
@Test
8489
void whenCustomEnvironmentIsDefinedThenAutoConfiguredEnvironmentBacksOff() {
8590
this.contextRunner.withUserConfiguration(CustomEnvironmentConfiguration.class).run((context) -> {
@@ -156,13 +161,11 @@ void whenStreamCredentialsAreSetThenEnvironmentUsesStreamCredentials() {
156161

157162
@Test
158163
void testDefaultRabbitStreamTemplateConfiguration() {
159-
this.contextRunner
160-
.withPropertyValues("spring.rabbitmq.listener.type:stream", "spring.rabbitmq.stream.name:stream-test")
161-
.run((context) -> {
162-
assertThat(context).hasSingleBean(RabbitStreamTemplate.class);
163-
assertThat(context.getBean(RabbitStreamTemplate.class)).hasFieldOrPropertyWithValue("streamName",
164-
"stream-test");
165-
});
164+
this.contextRunner.withPropertyValues("spring.rabbitmq.stream.name:stream-test").run((context) -> {
165+
assertThat(context).hasSingleBean(RabbitStreamTemplate.class);
166+
assertThat(context.getBean(RabbitStreamTemplate.class)).hasFieldOrPropertyWithValue("streamName",
167+
"stream-test");
168+
});
166169
}
167170

168171
@Test
@@ -174,8 +177,7 @@ void testDefaultRabbitStreamTemplateConfigurationWithoutStreamName() {
174177
@Test
175178
void testRabbitStreamTemplateConfigurationWithCustomMessageConverter() {
176179
this.contextRunner.withUserConfiguration(MessageConvertersConfiguration.class)
177-
.withPropertyValues("spring.rabbitmq.listener.type:stream", "spring.rabbitmq.stream.name:stream-test")
178-
.run((context) -> {
180+
.withPropertyValues("spring.rabbitmq.stream.name:stream-test").run((context) -> {
179181
assertThat(context).hasSingleBean(RabbitStreamTemplate.class);
180182
RabbitStreamTemplate streamTemplate = context.getBean(RabbitStreamTemplate.class);
181183
assertThat(streamTemplate).hasFieldOrPropertyWithValue("streamName", "stream-test");
@@ -189,8 +191,7 @@ void testRabbitStreamTemplateConfigurationWithCustomStreamMessageConverter() {
189191
this.contextRunner
190192
.withBean("myStreamMessageConverter", StreamMessageConverter.class,
191193
() -> mock(StreamMessageConverter.class))
192-
.withPropertyValues("spring.rabbitmq.listener.type:stream", "spring.rabbitmq.stream.name:stream-test")
193-
.run((context) -> {
194+
.withPropertyValues("spring.rabbitmq.stream.name:stream-test").run((context) -> {
194195
assertThat(context).hasSingleBean(RabbitStreamTemplate.class);
195196
assertThat(context.getBean(RabbitStreamTemplate.class)).extracting("messageConverter")
196197
.isSameAs(context.getBean("myStreamMessageConverter"));
@@ -201,8 +202,7 @@ void testRabbitStreamTemplateConfigurationWithCustomStreamMessageConverter() {
201202
void testRabbitStreamTemplateConfigurationWithCustomProducerCustomizer() {
202203
this.contextRunner
203204
.withBean("myProducerCustomizer", ProducerCustomizer.class, () -> mock(ProducerCustomizer.class))
204-
.withPropertyValues("spring.rabbitmq.listener.type:stream", "spring.rabbitmq.stream.name:stream-test")
205-
.run((context) -> {
205+
.withPropertyValues("spring.rabbitmq.stream.name:stream-test").run((context) -> {
206206
assertThat(context).hasSingleBean(RabbitStreamTemplate.class);
207207
assertThat(context.getBean(RabbitStreamTemplate.class)).extracting("producerCustomizer")
208208
.isSameAs(context.getBean("myProducerCustomizer"));

0 commit comments

Comments
 (0)