我试图理解这段代码,这是rabbitmq配置。
@Configuration
public class RabbitMqConfig {
public static final String EXCHANGE = "com.mldn.fish.exchange";
public static final String ROUTINGKEY = "com.mldn.fish.routingkey";
public static final String QUEUE_NAME = "com.mldn.fish.queue";
@Bean
public DirectExchange getDirectExchange() {
return new DirectExchange(RabbitMqConfig.EXCHANGE);
}
@Bean
public Queue getQueue() {
return new Queue(RabbitMqConfig.QUEUE_NAME);
}
@Bean
public Binding bindingExchangeQueue(DirectExchange exchange, Queue queue) {
return BindingBuilder.bind(queue).to(exchange).with(RabbitMqConfig.ROUTINGKEY);
}
}
在这里,“bindingExchangeQueue”方法的参数是什么意思?
应该是的-
@Bean
public Binding bindingExchangeQueue(DirectExchange getDirectExchange, Queue getQueue) {
return BindingBuilder.bind(getQueue).to(getDirectExchange).with(RabbitMqConfig.ROUTINGKEY);
}
基本上,我想知道这些参数包含什么,以及名称是否与配置为@beans的方法名匹配。有人能解释一下吗?
我还发现了一个配置了多个队列的示例。
请在下面找到-
@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");
}
在这里,bean bindingExchangeFoo的队列参数名为queueFoo,它与@bean queueFoo匹配。否则,由于现在有两个队列,它如何知道仅基于返回类型绑定哪个队列?