Spring boot Apache Camel主/从

Spring boot Apache Camel主/从,spring-boot,apache-camel,spring-camel,atomix,Spring Boot,Apache Camel,Spring Camel,Atomix,我有一个SpringBoot应用程序,它有一组驼峰路径。我正在寻找一种在一个JVM宕机时实现驼峰路由故障切换的方法。我的目标是让我的应用程序在一个JVM中运行,当该应用程序停止运行时,另一个JVM的路由应该能够处理我的消息 当我尝试添加集群时,我得到了一个错误(由:java.lang.IllegalStateException:CamelCluster service not found引起),甚至我也不确定我尝试代码的方式是否正确 public class RouteCmdLineRunner

我有一个SpringBoot应用程序,它有一组驼峰路径。我正在寻找一种在一个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);
            }
        });
    }
  }
}
application.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>

org.apache.camel.springboot

  • Camel文档说它有一个主组件来执行故障切换。()但是我没有看到集群的完整示例
  • 驼峰群集控制器的用途是什么 尽管有驼峰文档,但它仍然不完整,而且非常混乱

    • 骆驼版本:3.1.0
    • 弹簧防尘套:2.2.5.1释放
    任何指针都有助于实现Camel集群。我在概念上遗漏了什么吗


    对于此故障切换,我没有安装任何新服务器(如ZooKeeper/Consor服务器)的选项。

    camel-spring引导示例repo上有一个示例:

    查看您的代码,我发现了一些问题:

    • 您可以在run方法中以编程方式配置集群服务,也可以使用spring引导属性
    • 主组件的配置将AtomixClusterService设置为要使用的服务,但看起来您没有bean 如此命名
    这两种情况中的一种可能是您遇到非法状态异常的原因

    关于你的问题:

  • 是的,它仍然是实验性的
  • 集群文档末尾有一个示例(该文档最终未完成)
  • 集群控制器负责在领导地位被自动占据/丧失时启动/停止路由,而无需您添加任何路由策略或配置主组件

  • 你能添加一个完整的示例吗?添加了示例片段。