Reputation: 309
I have the following question about rabbitmq consumer:
Message Model 1:
String name; //apple //audi
String type; //fruit //car
Message Model 2:
String name; //apple //audi
String type; //fruit //car
+
correlation_id: e.g a mapping id used in business logic: 1234567
(the only difference between them is the correlation id which is a metadata)
When I publish a message I use the following routing key: com.my.routingKey. (for both Data Model 1 and Data Model 2)
When I consume the messages I use 2 different queues:
Using the above approach all messages would be handled in both queue1 and queue2. Some messages would be ignored in queue1 (those specific to queue2) and vice versa.
Is there any way to handle these kinds of messages only in one queue? Not sure if it is a good approach to differentiate these messages using the correlation id. e.g in consumer: if correlation id exists then do logic specific to data model 2 else do logic specific to data model 1
Upvotes: 0
Views: 1657
Reputation: 121177
The messages in the AMPQ protocol are placed into an exchange from the producer. The exchange makes a decision to which bound queue to place this or that message. Therefore your logic about two queues is correct, only the problem to really figure out a proper routing logic.
Please, consider to investigate different exchange types to determine which one is the best of your logic based on that metadata:
https://www.rabbitmq.com/tutorials/amqp-concepts.html
Upvotes: 1