Skip to content

MultiRabbit containerFactory SpEL Resolution Bug #2809

Closed
@BenEfrati

Description

@BenEfrati

In what version(s) of Spring AMQP are you seeing this issue?

3.1.6

Describe the bug

The resolveMultiRabbitAdminName method in MultiRabbitListenerAnnotationBeanPostProcessor does not properly resolve SpEL expressions for the containerFactory attribute of @RabbitListener annotations. According to the JavaDoc, the containerFactory attribute should support SpEL expressions, but the current implementation does not resolve these expressions, potentially leading to incorrect admin name resolution.

Additional context
JavaDoc for containerFactory() method in RabbitListener:

 * The bean name of the
 * {@link org.springframework.amqp.rabbit.listener.RabbitListenerContainerFactory} to
 * use to create the message listener container responsible to serve this endpoint.
 * <p>
 * If not specified, the default container factory is used, if any. If a SpEL
 * expression is provided ({@code #{...}}), the expression can either evaluate to a
 * container factory instance or a bean name.
 * @return the
 * {@link org.springframework.amqp.rabbit.listener.RabbitListenerContainerFactory}
 * bean name.
 */
String containerFactory() default "";

* expression is provided ({@code #{...}}), the expression can either evaluate to a

To Reproduce

  1. Define a @RabbitListener annotation with a SpEL expression for the containerFactory attribute.
  2. Observe that the resolveMultiRabbitAdminName method does not resolve the SpEL expression.

Expected behavior

The method should resolve SpEL expressions for both admin and containerFactory attributes. A proposed fix would be:

protected String resolveMultiRabbitAdminName(RabbitListener rabbitListener) {
    String admin = super.resolveExpressionAsString(rabbitListener.admin(), "admin");
    if (!StringUtils.hasText(admin) && StringUtils.hasText(rabbitListener.containerFactory())) {
        String containerFactory = super.resolveExpressionAsString(rabbitListener.containerFactory(), "containerFactory");
        admin = containerFactory + RabbitListenerConfigUtils.MULTI_RABBIT_ADMIN_SUFFIX;
    }
    if (!StringUtils.hasText(admin)) {
        admin = RabbitListenerConfigUtils.RABBIT_ADMIN_BEAN_NAME;
    }
    return admin;
}

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions