-
Notifications
You must be signed in to change notification settings - Fork 80
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
AMQP - Support multiple instances of RabbitTemplate #67
Comments
I thought about it a bit, and it seems this can be fixed by simply injecting a list of templates in the SpringwolfAmqpProducer and just using the first one. Does this make sense? |
Thanks for the detailed issue! We can definitely use the bindings and operation bindings to route the message correctly.
To move this forward, I think we should need to clearly define:
Once we these, we can design a solution. |
Just so we're on the same page, RabbitMQ (which is AMQP 0-9-1) publishes a message to specific exchange with some routing key. That message is routed to a queue based on that information. I think these are the main things user should be able to do (probably also in the order of importance):
As far as the new interface/API changes, would be nice to have annotations like AmqpProducer/AmqpConsumer to put on the methods for example and be able to add channelName, exchangeName, routingKey, description, payloadType there. ** at the moment publishing a message via UI to a queue works, because Rabbit's queues are automatically binded to the default exchange with their name as a routing key. So even if a queue 'book-added' is binded to an exchange 'books' with a routing key 'added', when you publish a message with RabbitTemplate.send('book-added', message) it's routed to the queue anyway. Which makes it seem as the message is sent directly to the queue, but it's not the case, as the message are published to an exchange only. |
Thanks for the explanation, I think I understand it better now,
@RabbitListener(bindings = {
@QueueBinding(
exchange = @Exchange(name = "name", type = ExchangeTypes.TOPIC),
value = @Queue(name = "example-bindings-queue"),
key = "routing-key"
)
})
public void bindingsExample(AnotherPayloadDto payload) {
logger.info("Received new message in example-bindings-queue: {}", payload.toString());
} The For the producers, we can for the moment ask the user to manually build the bindings object, or provide methods to construct it more conveniently.
The bindings data will be displayed in the binding tab as json. I didn't have plans to make it prettier, but I'm always open to ideas.
That's the trickier part. If I understand correctly, we would need to be able to use the binding information to route the message to the correct template, which also needs to find its way to the controller somehow. I will try and figure it out when I have some spare time, but again, ideas are welcome. Anyway, we can start with (1) and move forward step by step. Would you like to work on it? |
I think I'll have some time over the weekend, so I'd be happy to work on the first point. |
Let me know if you need anything when working on this. |
There's a handful of problems with supporting a case when there are multiple RabbitTemplate's.
Here's a use case, instead of using one rabbit template with a default exchange, and specifying a concrete exchange and routing key when sending messages, there could be multiple rabbit template with set exchanges, so that when sending a message you specify only the routing key.
The issues:
I think it needs to use a List of RabbitTemplate's in the SpringwolfAmqpProducer bean, and choose an appropriate one to send the message.
In order to send the message correctly, can the channel binding and operation binding info be used? https://github.com/asyncapi/bindings/tree/master/amqp#channel-binding-object (Specifically exchange.name/queue.name from channel binding and cc from operation binding)
Here's a starter demo if you want to test it out: https://github.com/DmitriButorchin/amqp-demo/tree/multiple-rabbit-templates
The text was updated successfully, but these errors were encountered: