gpt4 book ai didi

java - 我可以创建 Spring RabbitListener 别名吗?

转载 作者:太空宇宙 更新时间:2023-11-04 11:02:38 24 4
gpt4 key购买 nike

我有 @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 模块的别名支持。有什么方法可以注册我的别名吗?

最佳答案

我刚刚意识到我犯了一个愚蠢的错误,没有正确创建别名。它应该看起来像这样:

@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 "";
}

关于java - 我可以创建 Spring RabbitListener 别名吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46725264/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com