Reputation: 117
I am trying to understand RabbitMQ with spring boot and java based configurations. I came across a code in github, where 2 queues are being configured. Please look at the code snippet below:
@Bean
Queue queueFoo() {
return new Queue("queue.foo", false);
}
@Bean
Queue queueBar() {
return new Queue("queue.bar", false);
}
@Bean
TopicExchange exchange() {
return new TopicExchange("exchange");
}
@Bean
Binding bindingExchangeFoo(Queue queueFoo, TopicExchange exchange) {
return BindingBuilder.bind(queueFoo).to(exchange).with("queue.foo");
}
@Bean
Binding bindingExchangeBar(Queue queueBar, TopicExchange exchange) {
return BindingBuilder.bind(queueBar).to(exchange).with("queue.bar");
}
There are 2 Queue Bean definitions.- queueFoo and queueBar. Is the binding configuration correct?? In the line-
Binding bindingExchangeFoo(Queue queueFoo, TopicExchange exchange) {
So does it the name of argument - queueFoo have to be matched with the bean name of Queue?? Can anyone please clear my doubt?
Upvotes: 0
Views: 1962
Reputation: 1475
The argument name should be the same with the method name(for method name would be used as the bean name defaultlly) so that spring can autowire the dependecies. If this way does not work, you can try like this:
@Bean
Binding bindingExchangeFoo() {
return BindingBuilder.bind(queueFoo()).to(exchange()).with("queue.foo");
}
@Bean
Binding bindingExchangeBar() {
return BindingBuilder.bind(queueBar()).to(exchange()).with("queue.bar");
}
Upvotes: 1