Uploaded image for project: 'Spring AMQP'
  1. Spring AMQP
  2. AMQP-754

Expose AbstractRabbitListenerContainerFactory's adviceChain using a getter


    • Type: Improvement
    • Status: Closed
    • Priority: Minor
    • Resolution: Complete
    • Affects Version/s: 1.7.3
    • Fix Version/s: 1.7.4, 2.0 RC1
    • Component/s: RabbitMQ
    • Labels:


      I'm writing a Spring Boot application using Spring-AMQP. For my use case I want to establish a Spring Security SecurityContext before my annotation-based listeners are invoked based on some message headers. This is fairly easy to achieve by writing a custom org.aopalliance.aop.Advice which I then wire into my SimpleRabbitListenerContainerFactory through its setAdviceChain method.
      However, the canonical way of configuring such a container factory in a Spring Boot app is like this:

      SimpleRabbitListenerContainerFactory containerFactory(ConnectionFactory rabbitConnectionFactory, SimpleRabbitListenerContainerFactoryConfigurer configurer) {
          SimpleRabbitListenerContainerFactory listenerContainerFactory = new SimpleRabbitListenerContainerFactory();
          // apply default Boot configuration:
          configurer.configure(listenerContainerFactory, rabbitConnectionFactory);
          // note that if you'd configure a retry strategy through Boot, (re)setting the advice chain here will undo that...
          listenerContainerFactory.setAdviceChain(new SecurityContextPopulatingListenerAdvice());
          return listenerContainerFactory;

      So we're passing the factory to Boot's SimpleRabbitListenerContainerFactoryConfigurer to have Boot config applied before continuing with our custom configuration.
      As the comment in that code states, this is problematic if you configure a retry through Spring Boot and then also want to register a custom advice: the Boot configurer will set an advice chain containing the retry advice, but there's no way to detect and preserve that in our own factory bean when adding our own custom advice, as the advice chain only has a setter.

      I don't think adding a custom advice to a listener container is common enough to require something fancy, but providing application developers with a way to merge the advice(s) configured from the Boot configurer with custom advice themselves would be nice and simply adding a getter to the container factory would suffice for that.




            • Assignee:
              abilan Artem Bilan
              jkuipers Joris Kuipers
            • Votes:
              0 Vote for this issue
              2 Start watching this issue


              • Created: