我有@RabbitListener(id="example", queues={"a", "b"})
监听器,我在不同模块的代码中复制粘贴在多个位置。我想创建一个别名,例如:
@Target({ ElementType.TYPE, ElementType.METHOD, ElementType.ANNOTATION_TYPE })
@Retention(RetentionPolicy.RUNTIME)
@MessageMapping
@Documented
public @interface MyRabbitListener {
@AliasFor(annotation = RabbitListener.class)
String id() default "example";
@AliasFor(annotation = RabbitListener.class)
String containerFactory() default "";
@AliasFor(annotation = RabbitListener.class)
String[] queues() default {"a", "b"};
@AliasFor(annotation = RabbitListener.class)
boolean exclusive() default false;
@AliasFor(annotation = RabbitListener.class)
String priority() default "";
@AliasFor(annotation = RabbitListener.class)
String admin() default "";
@AliasFor(annotation = RabbitListener.class)
QueueBinding[] bindings() default {};
@AliasFor(annotation = RabbitListener.class)
String group() default "";
}
然后我只是在我的方法上使用@MyRabbitListener
,但它不起作用,因为我认为还没有spring-amqp
模块的别名支持。有什么方法可以注册我的别名吗?
答案 0 :(得分:0)
我刚刚意识到我犯了一个愚蠢的错误并没有正确创建别名。它应该是这样的:
@Target({ ElementType.TYPE, ElementType.METHOD, ElementType.ANNOTATION_TYPE })
@Retention(RetentionPolicy.RUNTIME)
@MessageMapping
@Documented
@RabbitListener(id = "example", queues = {"a", "b"})
public @interface MyRabbitListener {
@AliasFor(annotation = RabbitListener.class)
String containerFactory() default "";
@AliasFor(annotation = RabbitListener.class)
boolean exclusive() default false;
@AliasFor(annotation = RabbitListener.class)
String priority() default "";
@AliasFor(annotation = RabbitListener.class)
String admin() default "";
@AliasFor(annotation = RabbitListener.class)
QueueBinding[] bindings() default {};
@AliasFor(annotation = RabbitListener.class)
String group() default "";
}