使用 spring 集成和 zookeeper,可以实现一个领导者来执行诸如轮询之类的活动。
但是,我们如何将领导者责任分配给集群中的所有节点以进行负载平衡?
给出下面的代码,一旦应用程序启动,我看到同一个节点正在维护领导角色并获取事件。我想将此活动分发到集群中的每个节点以更好地平衡负载。
有什么方法可以安排集群中的每个节点以循环方式获得领导权和撤销?
@Bean
public LeaderInitiatorFactoryBean fooLeaderInitiator(CuratorFramework client) {
new LeaderInitiatorFactoryBean()
.setClient(client)
.setPath("/foofeed")
.setRole("foo");
}
@Bean
@InboundChannelAdapter(channel = "fooIncomingEvents", autoStartup = "false", poller = @Poller(fixedDelay = "5000"))
@Role("foo")
public FooTriggerMessageSource fooInboundChannelAdapter() {
new FooMessageSource("foo")
}