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>
- Is Clustering in Camel in the experimental stage? https://camel.apache.org/manual/latest/clustering.html
- 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.
- 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.
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:
One of the two is probably the the reason you are hitting IllegalStateException.
About your questions: