Reputation: 53
I have a project with "n" number of microservices module that uses RabbitMQ. Currently, each microservices have their own implementation of RabbitMQ consumer and producer. But I want to abstract and isolate this interaction with RabbitMQ to a common method in an external library so my project is not tightly coupled with RabbitMQ broker - I would want to change it to an ActiveMQ, etc., in the future with relative ease.
The Producer abstraction seems straight forward but how do I achieve Consumer abstraction? I want to be able to call the consumer method with the queue name as an argument from outside/external method and it should return me the message that it received from the given queue name. I have looked into using SpringAmqp @RabbitListener annotation or RabbitTemplate with Message Listener configured, but it looks like I need to first configure the queue name statically. I also tried Java client Channel basicConsume but I could not figure a way out to extract/send the message to an external method using basicConsume.
Any help with a sample example would be greatly appreciated.
Upvotes: 0
Views: 1152
Reputation: 174634
Consider using Spring Integration instead of using Spring AMQP directly.
That way, you can easily swap out the inbound/outbound channel adapters with different technologies because the adapters there use a common (spring-messaging) Message<?>
abstraction.
but it looks like I need to first configure the queue name statically.
That is not true; the queue name(s) can be populated via properties and/or SpEL expressions.
Upvotes: 1