简体   繁体   中英

Subscribe specific message in RMQ message queue

I have a RM queue test-queue . In there I need to handle 3 separate messages ( message-1, message-2, message-3 ) for 3 separate processes in 3 separate services.

I use @RabbitListener like below to access the message

@RabbitListener(queues = "test-queue")
        public void getMessage1(Message message) {
     System.out.println(message);
    }

but I need to access specific message ex: message-1 only in this function.

Any heads up?

That's wrong design for AMQP protocol. You need to think about 3 different queues for those messages and correct bindings for them from a single exchange with the proper routing. Then you can easy have 3 consumers from those queues.

My point is that queue entity is a consumer responsibility. The producer just dump a message into an exchange. So, you just dictate from your consumer application how you'd like to get produced messages.

Out of subject you can investigate a Spring Integration router pattern implementation if you really can't change your RabbitMQ structure: https://docs.spring.io/spring-integration/docs/current/reference/html/message-routing.html#messaging-routing-chapter

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM