Polish "Add RabbitTemplateCustomizer"
See gh-34050
This commit is contained in:
@@ -155,10 +155,10 @@ public class RabbitAutoConfiguration {
|
||||
@ConditionalOnSingleCandidate(ConnectionFactory.class)
|
||||
@ConditionalOnMissingBean(RabbitOperations.class)
|
||||
public RabbitTemplate rabbitTemplate(RabbitTemplateConfigurer configurer, ConnectionFactory connectionFactory,
|
||||
ObjectProvider<RabbitTemplateCustomizer> rabbitTemplateCustomizers) {
|
||||
ObjectProvider<RabbitTemplateCustomizer> customizers) {
|
||||
RabbitTemplate template = new RabbitTemplate();
|
||||
configurer.configure(template, connectionFactory);
|
||||
rabbitTemplateCustomizers.orderedStream().forEach((customizer) -> customizer.customize(template));
|
||||
customizers.orderedStream().forEach((customizer) -> customizer.customize(template));
|
||||
return template;
|
||||
}
|
||||
|
||||
|
||||
@@ -22,13 +22,13 @@ import org.springframework.amqp.rabbit.core.RabbitTemplate;
|
||||
* Callback interface that can be used to customize a {@link RabbitTemplate}.
|
||||
*
|
||||
* @author dang zhicairang
|
||||
* @since 2.3.0
|
||||
* @since 3.1.0
|
||||
*/
|
||||
@FunctionalInterface
|
||||
public interface RabbitTemplateCustomizer {
|
||||
|
||||
/**
|
||||
* Customize the {@link RabbitTemplate}.
|
||||
* Callback to customize a {@link RabbitTemplate} instance.
|
||||
* @param rabbitTemplate the rabbitTemplate to customize
|
||||
*/
|
||||
void customize(RabbitTemplate rabbitTemplate);
|
||||
|
||||
@@ -388,17 +388,17 @@ class RabbitAutoConfigurationTests {
|
||||
@Test
|
||||
void whenMultipleRabbitTemplateCustomizersAreDefinedThenTheyAreCalledInOrder() {
|
||||
this.contextRunner.withUserConfiguration(MultipleRabbitTemplateCustomizersConfiguration.class)
|
||||
.run((context) -> {
|
||||
RabbitTemplateCustomizer firstCustomizer = context.getBean("firstCustomizer",
|
||||
RabbitTemplateCustomizer.class);
|
||||
RabbitTemplateCustomizer secondCustomizer = context.getBean("secondCustomizer",
|
||||
RabbitTemplateCustomizer.class);
|
||||
InOrder inOrder = inOrder(firstCustomizer, secondCustomizer);
|
||||
RabbitTemplate template = context.getBean(RabbitTemplate.class);
|
||||
then(firstCustomizer).should(inOrder).customize(template);
|
||||
then(secondCustomizer).should(inOrder).customize(template);
|
||||
inOrder.verifyNoMoreInteractions();
|
||||
});
|
||||
.run((context) -> {
|
||||
RabbitTemplateCustomizer firstCustomizer = context.getBean("firstCustomizer",
|
||||
RabbitTemplateCustomizer.class);
|
||||
RabbitTemplateCustomizer secondCustomizer = context.getBean("secondCustomizer",
|
||||
RabbitTemplateCustomizer.class);
|
||||
InOrder inOrder = inOrder(firstCustomizer, secondCustomizer);
|
||||
RabbitTemplate template = context.getBean(RabbitTemplate.class);
|
||||
then(firstCustomizer).should(inOrder).customize(template);
|
||||
then(secondCustomizer).should(inOrder).customize(template);
|
||||
inOrder.verifyNoMoreInteractions();
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -41,6 +41,8 @@ To configure lower-level details of the RabbitMQ `ConnectionFactory` that is use
|
||||
|
||||
If a `ConnectionNameStrategy` bean exists in the context, it will be automatically used to name connections created by the auto-configured `CachingConnectionFactory`.
|
||||
|
||||
To make an application-wide, additive customization to the `RabbitTemplate`, use a `RabbitTemplateCustomizer` bean.
|
||||
|
||||
TIP: See https://spring.io/blog/2010/06/14/understanding-amqp-the-protocol-used-by-rabbitmq/[Understanding AMQP, the protocol used by RabbitMQ] for more details.
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user