【发布时间】:2018-04-18 11:15:21
【问题描述】:
我需要实现从两台服务器的队列中监听。队列名称相同。第一台服务器是主服务器,第二台服务器是备份服务器。 当主服务器关闭时,应继续使用备用服务器队列。
我的班级:
@RabbitListener(queues = "to_client")
public class ClientRabbitService {
现在我使用 RoutingConnectionFactory:
@Bean
@Primary
public ConnectionFactory routingConnectionFactory() {
SimpleRoutingConnectionFactory rcf = new SimpleRoutingConnectionFactory();
Map<Object, ConnectionFactory> map = new HashMap<>();
map.put("[to_kernel]", mainConnectionFactory());
map.put("[to_kernel_reserve]", reserveConnectionFactory());
map.put("[to_client]", mainConnectionFactory());
rcf.setTargetConnectionFactories(map);
return rcf;
}
[to_kernel] 和 [to_kernel_reserve] - 仅用于发送消息的队列,[to_client] - 接收它们。
有什么想法吗?
【问题讨论】:
标签: java spring spring-boot rabbitmq