Skip to content

Commit 9871270

Browse files
committed
Address PR Comments; move unrelated changes to a different PR.
1 parent 88ee436 commit 9871270

File tree

4 files changed

+32
-82
lines changed

4 files changed

+32
-82
lines changed

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

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,10 @@
1919
import java.util.stream.Collectors;
2020

2121
import org.springframework.amqp.rabbit.annotation.EnableRabbit;
22-
import org.springframework.amqp.rabbit.config.ContainerCustomizer;
2322
import org.springframework.amqp.rabbit.config.DirectRabbitListenerContainerFactory;
2423
import org.springframework.amqp.rabbit.config.RabbitListenerConfigUtils;
2524
import org.springframework.amqp.rabbit.config.SimpleRabbitListenerContainerFactory;
2625
import org.springframework.amqp.rabbit.connection.ConnectionFactory;
27-
import org.springframework.amqp.rabbit.listener.DirectMessageListenerContainer;
28-
import org.springframework.amqp.rabbit.listener.SimpleMessageListenerContainer;
2926
import org.springframework.amqp.rabbit.retry.MessageRecoverer;
3027
import org.springframework.amqp.support.converter.MessageConverter;
3128
import org.springframework.beans.factory.ObjectProvider;
@@ -51,23 +48,14 @@ class RabbitAnnotationDrivenConfiguration {
5148

5249
private final ObjectProvider<RabbitRetryTemplateCustomizer> retryTemplateCustomizers;
5350

54-
private final ObjectProvider<ContainerCustomizer<SimpleMessageListenerContainer>> simpleContainerCustomizers;
55-
56-
private final ObjectProvider<ContainerCustomizer<DirectMessageListenerContainer>> directContainerCustomizers;
57-
5851
private final RabbitProperties properties;
5952

6053
RabbitAnnotationDrivenConfiguration(ObjectProvider<MessageConverter> messageConverter,
6154
ObjectProvider<MessageRecoverer> messageRecoverer,
62-
ObjectProvider<RabbitRetryTemplateCustomizer> retryTemplateCustomizers,
63-
ObjectProvider<ContainerCustomizer<SimpleMessageListenerContainer>> simpleContainerCustomizers,
64-
ObjectProvider<ContainerCustomizer<DirectMessageListenerContainer>> directContainerCustomizers,
65-
RabbitProperties properties) {
55+
ObjectProvider<RabbitRetryTemplateCustomizer> retryTemplateCustomizers, RabbitProperties properties) {
6656
this.messageConverter = messageConverter;
6757
this.messageRecoverer = messageRecoverer;
6858
this.retryTemplateCustomizers = retryTemplateCustomizers;
69-
this.simpleContainerCustomizers = simpleContainerCustomizers;
70-
this.directContainerCustomizers = directContainerCustomizers;
7159
this.properties = properties;
7260
}
7361

@@ -91,7 +79,6 @@ SimpleRabbitListenerContainerFactory simpleRabbitListenerContainerFactory(
9179
SimpleRabbitListenerContainerFactoryConfigurer configurer, ConnectionFactory connectionFactory) {
9280
SimpleRabbitListenerContainerFactory factory = new SimpleRabbitListenerContainerFactory();
9381
configurer.configure(factory, connectionFactory);
94-
factory.setContainerCustomizer(this.simpleContainerCustomizers.getIfUnique());
9582
return factory;
9683
}
9784

@@ -114,7 +101,6 @@ DirectRabbitListenerContainerFactory directRabbitListenerContainerFactory(
114101
DirectRabbitListenerContainerFactoryConfigurer configurer, ConnectionFactory connectionFactory) {
115102
DirectRabbitListenerContainerFactory factory = new DirectRabbitListenerContainerFactory();
116103
configurer.configure(factory, connectionFactory);
117-
factory.setContainerCustomizer(this.directContainerCustomizers.getIfUnique());
118104
return factory;
119105
}
120106

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

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -896,6 +896,10 @@ public void setMissingQueuesFatal(boolean missingQueuesFatal) {
896896

897897
public static class StreamContainer extends BaseContainer {
898898

899+
/**
900+
* When true, the container factory will create containers that support listeners
901+
* that consume native stream messages instead of spring-amqp {@code Message}s.
902+
*/
899903
boolean nativeListener;
900904

901905
public boolean isNativeListener() {
@@ -1167,12 +1171,26 @@ private boolean determineSslEnabled(boolean sslEnabled) {
11671171

11681172
public static final class Stream {
11691173

1174+
/**
1175+
* Host of a RabbitMQ instance with the Stream Plugin Enabled
1176+
*/
11701177
private String host = "localhost";
11711178

1179+
/**
1180+
* Stream port of a RabbitMQ instance with the Stream Plugin Enabled
1181+
*/
11721182
private int port = DEFAULT_STREAM_PORT;
11731183

1174-
private String userName;
1184+
/**
1185+
* Login user to authenticate to the broker. If not set
1186+
* {@code spring.rabbitmq.username} will be used.
1187+
*/
1188+
private String username;
11751189

1190+
/**
1191+
* Login password to authenticate to the broker. If not set
1192+
* {@code spring.rabbitmq.password} will be used.
1193+
*/
11761194
private String password;
11771195

11781196
public String getHost() {
@@ -1191,12 +1209,12 @@ public void setPort(int port) {
11911209
this.port = port;
11921210
}
11931211

1194-
public String getUserName() {
1195-
return this.userName;
1212+
public String getUsername() {
1213+
return this.username;
11961214
}
11971215

1198-
public void setUserName(String userName) {
1199-
this.userName = userName;
1216+
public void setUsername(String username) {
1217+
this.username = username;
12001218
}
12011219

12021220
public String getPassword() {

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

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -35,36 +35,31 @@
3535
* Configuration for Spring RabbitMQ Stream Plugin support.
3636
*
3737
* @author Gary Russell
38-
* @since 2.6
3938
*/
4039
@Configuration(proxyBeanMethods = false)
41-
@ConditionalOnClass(EnableRabbit.class)
40+
@ConditionalOnClass(StreamRabbitListenerContainerFactory.class)
4241
@ConditionalOnProperty(prefix = "spring.rabbitmq.listener", name = "type", havingValue = "stream")
43-
public class RabbitStreamConfiguration {
42+
class RabbitStreamConfiguration {
4443

4544
@Bean(name = "rabbitListenerContainerFactory")
4645
@ConditionalOnMissingBean(name = "rabbitListenerContainerFactory")
4746
StreamRabbitListenerContainerFactory streamRabbitListenerContainerFactory(Environment rabbitStreamEnvironment,
48-
RabbitProperties properties, ObjectProvider<ConsumerCustomizer> consumerCustomizers,
49-
ObjectProvider<ContainerCustomizer<StreamListenerContainer>> containerCustomizers) {
47+
RabbitProperties properties, ObjectProvider<ConsumerCustomizer> consumerCustomizer,
48+
ObjectProvider<ContainerCustomizer<StreamListenerContainer>> containerCustomizer) {
5049

5150
StreamRabbitListenerContainerFactory factory = new StreamRabbitListenerContainerFactory(
5251
rabbitStreamEnvironment);
5352
factory.setNativeListener(properties.getListener().getStream().isNativeListener());
54-
if (consumerCustomizers.getIfUnique() != null) {
55-
factory.setConsumerCustomizer(consumerCustomizers.getIfUnique());
56-
}
57-
if (containerCustomizers.getIfUnique() != null) {
58-
factory.setContainerCustomizer(containerCustomizers.getIfUnique());
59-
}
53+
consumerCustomizer.ifUnique(factory::setConsumerCustomizer);
54+
containerCustomizer.ifUnique(factory::setContainerCustomizer);
6055
return factory;
6156
}
6257

6358
@Bean(name = "rabbitStreamEnvironment")
6459
@ConditionalOnMissingBean(name = "rabbitStreamEnvironment")
6560
Environment rabbitStreamEnvironment(RabbitProperties properties) {
6661
RabbitProperties.Stream stream = properties.getStream();
67-
String username = stream.getUserName();
62+
String username = stream.getUsername();
6863
if (username == null) {
6964
username = properties.getUsername();
7065
}

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

Lines changed: 1 addition & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -32,13 +32,12 @@
3232
import org.junit.jupiter.api.Test;
3333
import org.junit.jupiter.api.extension.ExtendWith;
3434
import org.mockito.InOrder;
35+
3536
import org.springframework.amqp.core.AcknowledgeMode;
3637
import org.springframework.amqp.core.AmqpAdmin;
3738
import org.springframework.amqp.core.Message;
3839
import org.springframework.amqp.rabbit.annotation.EnableRabbit;
39-
import org.springframework.amqp.rabbit.annotation.RabbitListener;
4040
import org.springframework.amqp.rabbit.config.AbstractRabbitListenerContainerFactory;
41-
import org.springframework.amqp.rabbit.config.ContainerCustomizer;
4241
import org.springframework.amqp.rabbit.config.DirectRabbitListenerContainerFactory;
4342
import org.springframework.amqp.rabbit.config.RabbitListenerConfigUtils;
4443
import org.springframework.amqp.rabbit.config.SimpleRabbitListenerContainerFactory;
@@ -50,9 +49,7 @@
5049
import org.springframework.amqp.rabbit.core.RabbitAdmin;
5150
import org.springframework.amqp.rabbit.core.RabbitMessagingTemplate;
5251
import org.springframework.amqp.rabbit.core.RabbitTemplate;
53-
import org.springframework.amqp.rabbit.listener.DirectMessageListenerContainer;
5452
import org.springframework.amqp.rabbit.listener.RabbitListenerContainerFactory;
55-
import org.springframework.amqp.rabbit.listener.SimpleMessageListenerContainer;
5653
import org.springframework.amqp.rabbit.retry.MessageRecoverer;
5754
import org.springframework.amqp.support.converter.MessageConverter;
5855
import org.springframework.beans.factory.NoSuchBeanDefinitionException;
@@ -852,20 +849,6 @@ void whenMultipleConnectionFactoryCustomizersAreDefinedThenTheyAreCalledInOrder(
852849
});
853850
}
854851

855-
@Test
856-
void simpleContainerCustomizer() {
857-
this.contextRunner.withUserConfiguration(SimpleContainerCustomizerConfiguration.class).run(
858-
(context) -> assertThat(context.getBean(SimpleContainerCustomizerConfiguration.class).customizerCalled)
859-
.isTrue());
860-
}
861-
862-
@Test
863-
void directContainerCustomizer() {
864-
this.contextRunner.withUserConfiguration(DirectContainerCustomizerConfiguration.class)
865-
.withPropertyValues("spring.rabbitmq.listener.type:direct").run((context) -> assertThat(
866-
context.getBean(DirectContainerCustomizerConfiguration.class).customizerCalled).isTrue());
867-
}
868-
869852
private com.rabbitmq.client.ConnectionFactory getTargetConnectionFactory(AssertableApplicationContext context) {
870853
CachingConnectionFactory connectionFactory = context.getBean(CachingConnectionFactory.class);
871854
return connectionFactory.getRabbitConnectionFactory();
@@ -1130,36 +1113,4 @@ ConnectionFactoryCustomizer firstCustomizer() {
11301113

11311114
}
11321115

1133-
@Configuration(proxyBeanMethods = false)
1134-
static class SimpleContainerCustomizerConfiguration {
1135-
1136-
boolean customizerCalled;
1137-
1138-
@RabbitListener(queues = "test", autoStartup = "false")
1139-
void listen(String in) {
1140-
}
1141-
1142-
@Bean
1143-
ContainerCustomizer<SimpleMessageListenerContainer> customizer() {
1144-
return (container) -> this.customizerCalled = true;
1145-
}
1146-
1147-
}
1148-
1149-
@Configuration(proxyBeanMethods = false)
1150-
static class DirectContainerCustomizerConfiguration {
1151-
1152-
boolean customizerCalled;
1153-
1154-
@RabbitListener(queues = "test", autoStartup = "false")
1155-
void listen(String in) {
1156-
}
1157-
1158-
@Bean
1159-
ContainerCustomizer<DirectMessageListenerContainer> customizer() {
1160-
return (container) -> this.customizerCalled = true;
1161-
}
1162-
1163-
}
1164-
11651116
}

0 commit comments

Comments
 (0)