我有一组骆驼路线的弹簧启动应用程序。我正在寻找一种在一个 JVM 出现故障时在骆驼路由中实现故障转移的选项。我的目标是让我的应用程序在一个 JVM 中运行,当该应用程序出现故障时,另一个 JVM 的路由应该处理我的消息。
当我尝试添加集群时,我收到一个错误(原因:java.lang.IllegalStateException: CamelCluster service not found),甚至我不确定我尝试我的代码的方式是否正确。
public class RouteCmdLineRunner implements CommandLineRunner {
@Autowired
private Configuration configuration;
@Autowired
private CamelContext camelContext;
@Override
public void run(String... args) {
CamelClusterService atomixClusterService = new AtomixClusterService();
atomixClusterService.setId("camel-node-1");
camelContext.addService(atomixClusterService);
if (configuration != null && configuration.getRoutes() != null) {
configuration.getRoutes().forEach(route -> {
try {
camelContext.addRoutePolicyFactory(ClusteredRoutePolicyFactory.forNamespace("my-ns"));
camelContext.addRoutes(new MyRouteBuilder(route, configuration));
} catch (Exception e) {
throw new RuntimeException(e);
}
});
}
}
}
应用程序.yml
camel:
component:
atomix:
cluster:
service:
id: testid-1
enabled: true
order: 1
mode: node
address: localhost:8081
master:
service: AtomixClusterService
camel.clustered.controller.namespace: my-ns
camel.clustered.controller.enabled: true
camel.component.master.service: true
pom.xml
<dependency>
<groupId>org.apache.camel.springboot</groupId>
<artifactId>camel-master-starter</artifactId>
</dependency>
<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-atomix-starter</artifactId>
<version>3.0.0-RC3</version>
</dependency>
<dependency>
<groupId>io.atomix</groupId>
<artifactId>atomix-all</artifactId>
<version>1.0.8</version>
</dependency>
- Camel中的聚类是否处于实验阶段?https://camel.apache.org/manual/latest/clustering.html
- Camel 文档说它有一个主组件来进行故障转移。(https://camel.apache.org/components/latest/master-component.html)但我没有看到集群的完整示例。
- 骆驼集群控制器有什么用?
尽管有骆驼文档,但它仍然不完整且令人困惑。
- 骆驼版:3.1.0
- 春季启动:2.2.5.RELEASE
任何指针都有助于实现 Camel 聚类。我在概念上遗漏了什么吗?
对于这个故障转移,我没有安装任何新服务器的选项,比如 ZooKeeper/Consul 服务器。