2

Is it possible to have @AliasFor annotation pass the argument to nested annotation? Something like passing value of name() to nested @Queue annotation inside @RabbitListener? I basically wanted to specify multiple queues with same binding parameters to same exchange, and only vary queue name.

enter image description here

1 Answer 1

1

I don't think you can do that for nested annotations. You probably need to think about having a custom @Queue annotation extension and then used it inside your @SomeListener. But the problem is that @Queue annotation cannot be extended. It has that @Target({}), so it is not possible at the moment.

If you really wish to have such a customization, consider to fix Spring AMQP on the matter via @Target(ANNOTATION_TYPE) and add some tests to demonstrate the feature and contribute it back to the framework.

Unfortunately I don't see the other way to support your request, unless you would go the to declare Queue beans and use just their names in that your custom annotation:

@Retention(RUNTIME)
@Target({ ElementType.TYPE, ElementType.METHOD })
@RabbitListener
public @interface MyListener {
    
    @AliasFor(annotation = RabbitListener.class, attribute = "queues")
    String[] queues() default {};
    
}
Sign up to request clarification or add additional context in comments.

3 Comments

One thought I had is we could expose a hook in the bean post processor to allow the user to manipulate the MergedAnnotations before we synthesize the new annotation - e.g. copy the value of a top level attribute into the nested attribute - something like return MergedAnnotations.of(SomeListener.class, updateAttributes(merged.asMap())). I will experiment.
Thanks. Just wanted to see if there is a way to do it that way. I guess I can always just define all the beans separately and wire them...
Prototype here: github.com/garyrussell/spring-amqp/commit/… let me know if providing a hook to allow you to modify the annotation would satisfy your requirements.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.