Question

I would like to know what is the best approach to control routes remotely. I have already taking a look to Apache Zookeeper and its integration with Camel but I am not sure if what I want can be done with it.

My scenario is the following: I have two exact same routes running in two different Java Apps. I want both of the routes running but just one of them consuming. However, I want to be able to decide which route should be consuming. I am not sure if that's possible with the ZookeeperRoutePolicy. If it is, how can I achieve this? If not, creating my own route policy would be the way to go?

Thanks!

Was it helpful?

Solution

Suppose any one of the apps can consume. Then the apps will try to create an ephemeral znode, say "/consumerstarted" and will start consuming if creation succeeded. Whichever app creates the ephemeral node first, that will be the consumer. The other app will get "Zookeeper node already exist" kind of exception and will decide not to consume. Now from both the apps you should set a watch on the Znode and the watch listener will be fired when the node gets deleted (may be because of the owner app explicitly deleting the ephemeral node or the owner app shutdown, or owner app losing connection to Zookeeper). Then the apps should again try to become consumer by creating the ephemeral "/consumerstarted" Znode.

Another approach may be: All the apps registers their own ephemeral Znodes under some "folder" say "/allapps". The name of the Znodes may be some unique Id. Eg., /allapps/uuid1, /allapps/uuid2 etc. All the apps should put watches on their corresponding Znode for data changes. Whenever the data is set to something like "start consuming", the corresponding app should start consuming. You may set data from another program or Zookeeper CLI.

BTW, https://github.com/sgroschupf/zkclient is a very good Zookeeper client library.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top