How can I route messages from a single RabbitMQ queue to separate methods?

Viewed 36

I've got a Spring Boot application. I've been designing microservices and these microservices communicate with each other via RabbitMQ. There is a channel service for directing my messages to related microservices. You can see the picture below.

My channel and microservices picture

Channel is directing messages to microservice 1, but microservice 1 should get my message to a specific method, for example, getById() method or createAThing() method.

How can I route my message to the related listener method?

Here is my code that consumes queue:

@RabbitListener(queues = "my-single-queue")
public void createObjectByMessage(Message message) {
    // Create object with message
}

@RabbitListener(queues = "my-single-queue")
public void getByIdByMessage(Message message) {
    // Get object with message ID
}

Or, how can I consume the message from the same queue but using a different routing key? I have no config class. I'm using @RabbitListener annotation.

0 Answers
Related