Apache Camel-Master/Slave

1.2k Views Asked by At

I've spring boot application which has a set of camel routes. I'm looking for an option to achieve failover in camel routes when one JVM goes down. My goal is to have my app running in one JVM and when that application goes down, another JVM's route should get process my messages.

When I try to add the Clustering, I'm getting an error (Caused by: java.lang.IllegalStateException: CamelCluster service not found) and even I'm not sure whether the way I'm trying my code is correct.

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>
  1. Is Clustering in Camel in the experimental stage? https://camel.apache.org/manual/latest/clustering.html
  2. Camel documentation says it has a master component which does the failover. (https://camel.apache.org/components/latest/master-component.html) but I don't see the complete example for Clustering.
  3. What is the use of a camel clustered controller?

Although there is camel documentation still it is not complete and confusing a lot.

  • Camel Version: 3.1.0
  • Spring-boot: 2.2.5.RELEASE

Any pointers would be helpful in achieving Camel clustering. Am I missing anything conceptually?.

For this failover, I don't have the option to install any new server like ZooKeeper/Consul servers.

1

There are 1 best solutions below

0
Luca Burgazzoli On

There is an example on the camel-spring-boot example repo: https://github.com/apache/camel-spring-boot/tree/master/examples/camel-example-spring-boot-clustered-route-controller

Looking at your code I see a number of issues:

  • you do configure a cluster service programmatically in your run method as well as using spring boot properties
  • the configuration of master component set AtomixClusterService as service to use but it does not look like you have a bean so named

One of the two is probably the the reason you are hitting IllegalStateException.

About your questions:

  1. Yes it is still experimental
  2. There is an example at the end of the clustering doc (which is definitively not completed)
  3. the clustered controller is in charge to start/stop routes when the leadership is taken/lost automatically without having you to add any route policy or configuring master component.