0

我有一组骆驼路线的弹簧启动应用程序。我正在寻找一种在一个 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>
  1. Camel中的聚类是否处于实验阶段?https://camel.apache.org/manual/latest/clustering.html
  2. Camel 文档说它有一个主组件来进行故障转移。(https://camel.apache.org/components/latest/master-component.html)但我没有看到集群的完整示例。
  3. 骆驼集群控制器有什么用?

尽管有骆驼文档,但它仍然不完整且令人困惑。

  • 骆驼版:3.1.0
  • 春季启动:2.2.5.RELEASE

任何指针都有助于实现 Camel 聚类。我在概念上遗漏了什么吗?

对于这个故障转移,我没有安装任何新服务器的选项,比如 ZooKeeper/Consul 服务器。

4

1 回答 1

1

camel-spring-boot 示例 repo 上有一个示例:https ://github.com/apache/camel-spring-boot/tree/master/examples/camel-example-spring-boot-clustered-route-controller

查看您的代码,我发现了许多问题:

  • 您确实在 run 方法中以编程方式配置集群服务以及使用 spring boot 属性
  • 主组件的配置将 AtomixClusterService 设置为要使用的服务,但看起来您没有这样命名的 bean

两者之一可能是您遇到 IllegalStateException 的原因。

关于您的问题:

  1. 是的,它仍然是实验性的
  2. 集群文档末尾有一个示例(肯定没有完成)
  3. 集群控制器负责在领导权被采取/失去时自动启动/停止路由,而无需您添加任何路由策略或配置主组件。
于 2020-03-20T14:20:55.463 回答