Closed as not planned
Description
Hello community,
I have a feature request.
Background: I have splitted up my ContainerCustomizer
logic into multiple parts in order to increase focus (one takes care of timeouts, another one takes care of consumer concurency and so on).
Currently, SpringBoots auto-configuration for ContainerCustomizer
allows only one instance at a time.
@Bean(name = "rabbitListenerContainerFactory")
@ConditionalOnMissingBean(name = "rabbitListenerContainerFactory")
@ConditionalOnProperty(prefix = "spring.rabbitmq.listener", name = "type", havingValue = "simple",
matchIfMissing = true)
SimpleRabbitListenerContainerFactory simpleRabbitListenerContainerFactory(
SimpleRabbitListenerContainerFactoryConfigurer configurer, ConnectionFactory connectionFactory,
ObjectProvider<ContainerCustomizer<SimpleMessageListenerContainer>> simpleContainerCustomizer) {
SimpleRabbitListenerContainerFactory factory = new SimpleRabbitListenerContainerFactory();
configurer.configure(factory, connectionFactory);
simpleContainerCustomizer.ifUnique(factory::setContainerCustomizer); // here is the "problem"
return factory;
}
My currenct work around is to provide one ContainerCustomizier
as an adapter which delegates the work to each ContainerCustomizier
, like this:
...
// SpringBoot defaults
// simpleContainerCustomizer.ifUnique(factory::setContainerCustomizer);
List<ContainerCustomizer<SimpleMessageListenerContainer>> containerCustomizers = simpleContainerCustomizer.orderedStream().collect(Collectors.toList());
if (!containerCustomizers.isEmpty()) {
factory.setContainerCustomizer(container -> containerCustomizers.forEach(customizer -> customizer.configure(container))); // here comes the wrapper/delegate logic
}
I know that I could encapsulate all me customization into one ContainerCustomizer
but,
- I would like to keep things simple/small and consistent by splitting along its purpose/usage (catchword: seperation of concerns)
- there are other customizers in SpringBoot auto-configure which do allow multiple implementations at the same time, e.g.
WebClientCustomizer
Please let me know if my feature request to add logic that can handle multiple ContainerCustomizer` is feasable/useful.
If so, I could provide a pull request.