2017-10-13 144 views
1

我有@RabbitListener(id="example", queues={"a", "b"})偵聽器,我複製粘貼在我的代碼中的多個位置通過不同的模塊。我想創造一個別名,如:我可以創建Spring RabbitListener別名嗎?

@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

我剛剛意識到我犯了一個愚蠢的錯誤,沒有正確創建別名。它應該看起來像這樣:

@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 ""; 
} 
相關問題