Skip to content

add support for multiple ContainerCustomizer (spring-amqp) #32617

Closed as not planned
@rfelgent

Description

@rfelgent

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    for: external-projectFor an external project and not something we can fixstatus: declinedA suggestion or change that we don't feel we should currently apply

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions