Single Queue, multiple @RabbitListener but different services

后端 未结 1 1858
挽巷
挽巷 2021-01-19 08:43

Is it possible to have a single @RabbitListener, e.g:

@RabbitListener(queues = STORAGE_REQUEST_QUEUE_NAME)
public FindApplicationByIdResponse findApplication         


        
相关标签:
1条回答
  • 2021-01-19 08:48

    That doesn't work with @RabbitListener on the method level, but it is possible on the class level with the @RabbitHandler on methods:

    @RabbitListener(queues = STORAGE_REQUEST_QUEUE_NAME)
    public class MultiListenerBean {
    
        @RabbitHandler
        public String bar(Bar bar) {
            ...
        }
    
        @RabbitHandler
        public String baz(Baz baz) {
            ...
        }
    
        @RabbitHandler
        public String qux(@Header("amqp_receivedRoutingKey") String rk, @Payload Qux qux) {
            ...
        }
    
    }
    

    https://docs.spring.io/spring-amqp/reference/html/#annotation-method-selection

    0 讨论(0)
提交回复
热议问题