camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From lburgazz...@apache.org
Subject [4/6] camel git commit: CAMEL-10320: Initial version of Camel Master component for clustered services
Date Wed, 27 Sep 2017 14:18:15 GMT
CAMEL-10320: Initial version of Camel Master component for clustered services

CAMEL-10320: Provide a LeaderPolicy to ease the implementation of master/slave route/context


Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/14f23913
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/14f23913
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/14f23913

Branch: refs/heads/master
Commit: 14f23913a1a42cbd3751e68e711a15f6921c8c2b
Parents: ab42e16
Author: Dhiraj Bokde <dhirajsb@yahoo.com>
Authored: Wed Jun 7 01:37:40 2017 -0700
Committer: lburgazzoli <lburgazzoli@gmail.com>
Committed: Wed Sep 27 16:17:01 2017 +0200

----------------------------------------------------------------------
 apache-camel/pom.xml                            |   9 +
 .../src/main/descriptors/common-bin.xml         |   2 +
 components/camel-master/pom.xml                 | 101 +++++++++
 .../src/main/docs/master-component.adoc         | 135 ++++++++++++
 .../camel/component/master/MasterComponent.java |  60 ++++++
 .../camel/component/master/MasterConsumer.java  | 169 +++++++++++++++
 .../camel/component/master/MasterEndpoint.java  |  84 ++++++++
 .../src/main/resources/META-INF/LICENSE.txt     | 203 +++++++++++++++++++
 .../src/main/resources/META-INF/NOTICE.txt      |  11 +
 .../services/org/apache/camel/component/master  |  17 ++
 .../component/master/MasterComponentTest.java   | 106 ++++++++++
 .../master/util/InMemoryClusterMember.java      |  49 +++++
 .../master/util/InMemoryClusterService.java     |  47 +++++
 .../master/util/InMemoryClusterView.java        | 159 +++++++++++++++
 .../src/test/resources/jgroups-tcp.xml          |  53 +++++
 .../src/test/resources/log4j2.properties        |  40 ++++
 components/camel-zookeeper/pom.xml              |   5 +
 .../zookeeper/ha/ZooKeeperMasterMain.java       |  63 ++++++
 .../zookeeper/ha/ZooKeeperMasterTest.java       | 120 +++++++++++
 .../src/test/resources/log4j2.properties        |   1 -
 components/pom.xml                              |   1 +
 parent/pom.xml                                  |  10 +
 .../camel-master-starter/pom.xml                |  53 +++++
 .../MasterComponentAutoConfiguration.java       | 128 ++++++++++++
 .../MasterComponentConfiguration.java           |  50 +++++
 .../src/main/resources/META-INF/LICENSE.txt     | 203 +++++++++++++++++++
 .../src/main/resources/META-INF/NOTICE.txt      |  11 +
 .../main/resources/META-INF/spring.factories    |  19 ++
 .../src/main/resources/META-INF/spring.provides |  17 ++
 .../spring-boot/components-starter/pom.xml      |   1 +
 30 files changed, 1926 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/14f23913/apache-camel/pom.xml
----------------------------------------------------------------------
diff --git a/apache-camel/pom.xml b/apache-camel/pom.xml
index d8f671d..dd15392 100644
--- a/apache-camel/pom.xml
+++ b/apache-camel/pom.xml
@@ -663,6 +663,10 @@
     </dependency>
     <dependency>
       <groupId>org.apache.camel</groupId>
+      <artifactId>camel-master</artifactId>
+    </dependency>
+    <dependency>
+      <groupId>org.apache.camel</groupId>
       <artifactId>camel-metrics</artifactId>
     </dependency>
     <dependency>
@@ -1841,6 +1845,11 @@
     </dependency>
     <dependency>
       <groupId>org.apache.camel</groupId>
+      <artifactId>camel-master</artifactId>
+      <version>${project.version}</version>
+    </dependency>
+    <dependency>
+      <groupId>org.apache.camel</groupId>
       <artifactId>camel-mail-starter</artifactId>
       <version>${project.version}</version>
     </dependency>

http://git-wip-us.apache.org/repos/asf/camel/blob/14f23913/apache-camel/src/main/descriptors/common-bin.xml
----------------------------------------------------------------------
diff --git a/apache-camel/src/main/descriptors/common-bin.xml b/apache-camel/src/main/descriptors/common-bin.xml
index 646adcc..59d5c5e 100644
--- a/apache-camel/src/main/descriptors/common-bin.xml
+++ b/apache-camel/src/main/descriptors/common-bin.xml
@@ -176,6 +176,7 @@
         <include>org.apache.camel:camel-metrics</include>
         <include>org.apache.camel:camel-milo</include>
         <include>org.apache.camel:camel-mail</include>
+        <include>org.apache.camel:camel-master</include>
         <include>org.apache.camel:camel-mina</include>
         <include>org.apache.camel:camel-mina2</include>
         <include>org.apache.camel:camel-mllp</include>
@@ -466,6 +467,7 @@
         <include>org.apache.camel:camel-lumberjack-starter</include>
         <include>org.apache.camel:camel-lzf-starter</include>
         <include>org.apache.camel:camel-mail-starter</include>
+        <include>org.apache.camel:camel-master-starter</include>
         <include>org.apache.camel:camel-metrics-starter</include>
         <include>org.apache.camel:camel-milo-starter</include>
         <include>org.apache.camel:camel-mina2-starter</include>

http://git-wip-us.apache.org/repos/asf/camel/blob/14f23913/components/camel-master/pom.xml
----------------------------------------------------------------------
diff --git a/components/camel-master/pom.xml b/components/camel-master/pom.xml
new file mode 100644
index 0000000..58390b4
--- /dev/null
+++ b/components/camel-master/pom.xml
@@ -0,0 +1,101 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+
+    Licensed to the Apache Software Foundation (ASF) under one or more
+    contributor license agreements.  See the NOTICE file distributed with
+    this work for additional information regarding copyright ownership.
+    The ASF licenses this file to You under the Apache License, Version 2.0
+    (the "License"); you may not use this file except in compliance with
+    the License.  You may obtain a copy of the License at
+
+         http://www.apache.org/licenses/LICENSE-2.0
+
+    Unless required by applicable law or agreed to in writing, software
+    distributed under the License is distributed on an "AS IS" BASIS,
+    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+    See the License for the specific language governing permissions and
+    limitations under the License.
+
+-->
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+
+  <modelVersion>4.0.0</modelVersion>
+
+  <parent>
+    <groupId>org.apache.camel</groupId>
+    <artifactId>components</artifactId>
+    <version>2.20.0-SNAPSHOT</version>
+  </parent>
+
+  <artifactId>camel-master</artifactId>
+  <packaging>jar</packaging>
+  <name>Camel :: Master</name>
+  <description>Camel Master Support</description>
+
+  <properties>
+    <camel.osgi.import>
+      !com.google.common.base;,
+      !org.apache.camel.component.master.group,
+      *
+    </camel.osgi.import>
+    <camel.osgi.export.pkg>
+      org.apache.camel.component.master
+    </camel.osgi.export.pkg>
+    <camel.osgi.export.service>org.apache.camel.spi.ComponentResolver;component=master</camel.osgi.export.service>
+  </properties>
+
+  <dependencies>
+
+    <dependency>
+      <groupId>org.apache.camel</groupId>
+      <artifactId>camel-core</artifactId>
+    </dependency>
+
+    <!-- test dependencies -->
+    <dependency>
+      <groupId>org.apache.camel</groupId>
+      <artifactId>camel-test</artifactId>
+      <scope>test</scope>
+    </dependency>
+    <dependency>
+      <groupId>org.jgroups</groupId>
+      <artifactId>jgroups</artifactId>
+      <version>${jgroups-version}</version>
+      <scope>test</scope>
+    </dependency>
+
+    <dependency>
+      <groupId>org.apache.logging.log4j</groupId>
+      <artifactId>log4j-api</artifactId>
+      <scope>test</scope>
+    </dependency>
+    <dependency>
+      <groupId>org.apache.logging.log4j</groupId>
+      <artifactId>log4j-core</artifactId>
+      <scope>test</scope>
+    </dependency>
+    <dependency>
+      <groupId>org.apache.logging.log4j</groupId>
+      <artifactId>log4j-slf4j-impl</artifactId>
+      <scope>test</scope>
+    </dependency>
+
+  </dependencies>
+
+  <build>
+    <plugins>
+      <plugin>
+        <artifactId>maven-surefire-plugin</artifactId>
+        <configuration>
+          <childDelegation>false</childDelegation>
+          <useFile>true</useFile>
+          <forkCount>1</forkCount>
+          <reuseForks>true</reuseForks>
+          <forkedProcessTimeoutInSeconds>600</forkedProcessTimeoutInSeconds>
+        </configuration>
+      </plugin>
+    </plugins>
+  </build>
+
+
+</project>

http://git-wip-us.apache.org/repos/asf/camel/blob/14f23913/components/camel-master/src/main/docs/master-component.adoc
----------------------------------------------------------------------
diff --git a/components/camel-master/src/main/docs/master-component.adoc b/components/camel-master/src/main/docs/master-component.adoc
new file mode 100644
index 0000000..bce8b37
--- /dev/null
+++ b/components/camel-master/src/main/docs/master-component.adoc
@@ -0,0 +1,135 @@
+== Master Component
+
+*Available as of Camel version 2.20*
+
+The **zookeeper-master:** endpoint provides a way to ensure only a single consumer in a cluster consumes from a given endpoint;
+with automatic failover if that JVM dies.
+
+This can be very useful if you need to consume from some legacy back end which either doesn't support concurrent
+consumption or due to commercial or stability reasons you can only have a single connection at any point in time.
+
+### Using the master endpoint
+
+Just prefix any camel endpoint with **zookeeper-master:someName:** where _someName_ is a logical name and is
+used to acquire the master lock. e.g.
+
+```
+from("zookeeper-master:cheese:jms:foo").to("activemq:wine");
+```
+The above simulates the [Exclusive Consumers](http://activemq.apache.org/exclusive-consumer.html) type feature in
+ActiveMQ; but on any third party JMS provider which maybe doesn't support exclusive consumers.
+
+
+### URI format
+
+[source]
+----
+zookeeper-master:name:endpoint[?options]
+----
+
+Where endpoint is any Camel endpoint you want to run in master/slave mode.
+
+
+### Options
+
+// component options: START
+The Master component has no options.
+// component options: END
+
+// endpoint options: START
+The Master endpoint is configured using URI syntax:
+
+----
+master:namespace:delegateUri
+----
+
+with the following path and query parameters:
+
+==== Path Parameters (2 parameters):
+
+[width="100%",cols="2,5,^1,2",options="header"]
+|===
+| Name | Description | Default | Type
+| *namespace* | *Required* The name of the cluster namespace to use |  | String
+| *delegateUri* | *Required* The endpoint uri to use in master/slave mode |  | String
+|===
+
+==== Query Parameters (4 parameters):
+
+[width="100%",cols="2,5,^1,2",options="header"]
+|===
+| Name | Description | Default | Type
+| *bridgeErrorHandler* (consumer) | Allows for bridging the consumer to the Camel routing Error Handler which mean any exceptions occurred while the consumer is trying to pickup incoming messages or the likes will now be processed as a message and handled by the routing Error Handler. By default the consumer will use the org.apache.camel.spi.ExceptionHandler to deal with exceptions that will be logged at WARN or ERROR level and ignored. | false | boolean
+| *exceptionHandler* (consumer) | To let the consumer use a custom ExceptionHandler. Notice if the option bridgeErrorHandler is enabled then this options is not in use. By default the consumer will deal with exceptions that will be logged at WARN or ERROR level and ignored. |  | ExceptionHandler
+| *exchangePattern* (consumer) | Sets the exchange pattern when the consumer creates an exchange. |  | ExchangePattern
+| *synchronous* (advanced) | Sets whether synchronous processing should be strictly used or Camel is allowed to use asynchronous processing (if supported). | false | boolean
+|===
+// endpoint options: END
+
+### Example
+
+You can protect a clustered Camel application to only consume files from one active node.
+
+
+[source,java]
+----
+    // the file endpoint we want to consume from
+    String url = "file:target/inbox?delete=true";
+
+    // use the zookeeper master component in the clustered group named myGroup
+    // to run a master/slave mode in the following Camel url
+    from("zookeeper-master:myGroup:" + url)
+        .log(name + " - Received file: ${file:name}")
+        .delay(delay)
+        .log(name + " - Done file:     ${file:name}")
+        .to("file:target/outbox");
+----
+
+ZooKeeper will by default connect to `localhost:2181`, but you can configure this on the component level.
+
+[source,java]
+----
+    MasterComponent master = new MasterComponent();
+    master.setZooKeeperUrl("myzookeeper:2181");
+----
+
+However you can also configure the url of the ZooKeeper ensemble using environment variables.
+
+    export ZOOKEEPER_URL = "myzookeeper:2181"
+
+## Master RoutePolicy
+
+You can also use a `RoutePolicy` to control routes in master/slave mode.
+
+When doing so you must configure the route policy with
+
+- url to zookeeper ensemble
+- name of cluster group
+- *important* and set the route to not auto startup
+
+A little example
+
+[source,java]
+----
+    MasterRoutePolicy master = new MasterRoutePolicy();
+    master.setZooKeeperUrl("localhost:2181");
+    master.setGroupName("myGroup");
+
+    // its import to set the route to not auto startup
+    // as we let the route policy start/stop the routes when it becomes a master/slave etc
+    from("file:target/inbox?delete=true").noAutoStartup()
+        // use the zookeeper master route policy in the clustered group
+        // to run this route in master/slave mode
+        .routePolicy(master)
+        .log(name + " - Received file: ${file:name}")
+        .delay(delay)
+        .log(name + " - Done file:     ${file:name}")
+        .to("file:target/outbox");
+----
+
+### See Also
+
+* link:configuring-camel.html[Configuring Camel]
+* link:component.html[Component]
+* link:endpoint.html[Endpoint]
+* link:getting-started.html[Getting Started]

http://git-wip-us.apache.org/repos/asf/camel/blob/14f23913/components/camel-master/src/main/java/org/apache/camel/component/master/MasterComponent.java
----------------------------------------------------------------------
diff --git a/components/camel-master/src/main/java/org/apache/camel/component/master/MasterComponent.java b/components/camel-master/src/main/java/org/apache/camel/component/master/MasterComponent.java
new file mode 100644
index 0000000..3c10d9d
--- /dev/null
+++ b/components/camel-master/src/main/java/org/apache/camel/component/master/MasterComponent.java
@@ -0,0 +1,60 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.component.master;
+
+import java.util.Map;
+
+import org.apache.camel.CamelContext;
+import org.apache.camel.Endpoint;
+import org.apache.camel.impl.DefaultComponent;
+import org.apache.camel.util.ObjectHelper;
+import org.apache.camel.util.StringHelper;
+
+/**
+ * The master camel component ensures that only a single endpoint in a cluster is
+ * active at any point in time with all other JVMs being hot standbys which wait
+ * until the master JVM dies before taking over to provide high availability of
+ * a single consumer.
+ */
+public class MasterComponent extends DefaultComponent {
+
+    public MasterComponent() {
+        this(null);
+    }
+
+    public MasterComponent(CamelContext context) {
+        super(context);
+    }
+
+    @Override
+    protected Endpoint createEndpoint(String uri, String remaining, Map<String, Object> params) throws Exception {
+        // we are registering a regular endpoint
+        String namespace = StringHelper.before(remaining, ":");
+        String delegateUri = StringHelper.after(remaining, ":");
+
+        if (ObjectHelper.isEmpty(namespace) || ObjectHelper.isEmpty(delegateUri)) {
+            throw new IllegalArgumentException("Wrong uri syntax : master:namespace:uri, got " + remaining);
+        }
+
+        // we need to apply the params here
+        if (params != null && params.size() > 0) {
+            delegateUri = delegateUri + "?" + uri.substring(uri.indexOf('?') + 1);
+        }
+
+        return new MasterEndpoint(uri, this, namespace, delegateUri);
+    }
+}

http://git-wip-us.apache.org/repos/asf/camel/blob/14f23913/components/camel-master/src/main/java/org/apache/camel/component/master/MasterConsumer.java
----------------------------------------------------------------------
diff --git a/components/camel-master/src/main/java/org/apache/camel/component/master/MasterConsumer.java b/components/camel-master/src/main/java/org/apache/camel/component/master/MasterConsumer.java
new file mode 100644
index 0000000..b693464
--- /dev/null
+++ b/components/camel-master/src/main/java/org/apache/camel/component/master/MasterConsumer.java
@@ -0,0 +1,169 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.component.master;
+
+import org.apache.camel.CamelContext;
+import org.apache.camel.Consumer;
+import org.apache.camel.Endpoint;
+import org.apache.camel.Processor;
+import org.apache.camel.StartupListener;
+import org.apache.camel.SuspendableService;
+import org.apache.camel.api.management.ManagedAttribute;
+import org.apache.camel.api.management.ManagedResource;
+import org.apache.camel.ha.CamelClusterEventListener;
+import org.apache.camel.ha.CamelClusterMember;
+import org.apache.camel.ha.CamelClusterService;
+import org.apache.camel.ha.CamelClusterView;
+import org.apache.camel.impl.DefaultConsumer;
+import org.apache.camel.util.ObjectHelper;
+import org.apache.camel.util.ServiceHelper;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+@ManagedResource(description = "Managed Master Consumer")
+public class MasterConsumer extends DefaultConsumer {
+    private static final transient Logger LOGER = LoggerFactory.getLogger(MasterConsumer.class);
+
+    private final MasterEndpoint masterEndpoint;
+    private final Endpoint delegatedEndpoint;
+    private final Processor processor;
+    private final CamelClusterEventListener.Leadership leadershipListener;
+    private Consumer delegatedConsumer;
+    private CamelClusterService service;
+    private CamelClusterView view;
+
+    public MasterConsumer(MasterEndpoint masterEndpoint, Processor processor) {
+        super(masterEndpoint, processor);
+
+        this.masterEndpoint = masterEndpoint;
+        this.delegatedEndpoint = masterEndpoint.getEndpoint();
+        this.processor = processor;
+        this.leadershipListener = new LeadershipListener();
+    }
+
+    @Override
+    protected void doStart() throws Exception {
+        super.doStart();
+
+        CamelContext context = super.getEndpoint().getCamelContext();
+        service = context.hasService(CamelClusterService.class);
+
+        if (service == null) {
+            throw new IllegalStateException("No cluster service found");
+        }
+
+        view = service.getView(masterEndpoint.getNamespace());
+        view.addEventListener(leadershipListener);
+
+        if (isMaster()) {
+            onLeadershipTaken();
+        }
+    }
+
+    @Override
+    protected void doStop() throws Exception {
+        super.doStop();
+
+        if (view != null) {
+            view.removeEventListener(leadershipListener);
+        }
+
+        ServiceHelper.stopAndShutdownServices(delegatedConsumer);
+        ServiceHelper.stopAndShutdownServices(delegatedEndpoint);
+
+        delegatedConsumer = null;
+    }
+
+    @Override
+    protected void doResume() throws Exception {
+        if (delegatedConsumer != null && delegatedConsumer instanceof SuspendableService) {
+            ((SuspendableService)delegatedConsumer).resume();
+        }
+        super.doResume();
+    }
+
+    @Override
+    protected void doSuspend() throws Exception {
+        if (delegatedConsumer != null && delegatedConsumer instanceof SuspendableService) {
+            ((SuspendableService)delegatedConsumer).suspend();
+        }
+        super.doSuspend();
+    }
+
+    @ManagedAttribute(description = "Are we the master")
+    public boolean isMaster() {
+        return view != null
+            ? view.getLocalMember().isMaster()
+            : false;
+    }
+
+    // **************************************
+    // Helpers
+    // **************************************
+
+    private synchronized void onLeadershipTaken() throws Exception {
+        if (!isRunAllowed()) {
+            return;
+        }
+
+        if (delegatedConsumer != null) {
+            return;
+        }
+
+        delegatedConsumer = delegatedEndpoint.createConsumer(processor);
+        if (delegatedConsumer instanceof StartupListener) {
+            getEndpoint().getCamelContext().addStartupListener((StartupListener) delegatedConsumer);
+        }
+
+        ServiceHelper.startService(delegatedEndpoint);
+        ServiceHelper.startService(delegatedConsumer);
+
+        LOGER.info("Leadership taken: consumer started: {}", delegatedEndpoint);
+    }
+
+    private synchronized void onLeadershipLost() throws Exception {
+        ServiceHelper.stopAndShutdownServices(delegatedConsumer);
+        ServiceHelper.stopAndShutdownServices(delegatedEndpoint);
+
+        delegatedConsumer = null;
+
+        LOGER.info("Leadership lost: consumer stopped: {}", delegatedEndpoint);
+    }
+
+    // **************************************
+    // Listener
+    // **************************************
+
+    private final class LeadershipListener implements CamelClusterEventListener.Leadership {
+        @Override
+        public void leadershipChanged(CamelClusterView view, CamelClusterMember leader) {
+            if (!isRunAllowed()) {
+                return;
+            }
+
+            try {
+                if (view.getLocalMember().isMaster()) {
+                    onLeadershipTaken();
+                } else if (delegatedConsumer != null) {
+                    onLeadershipLost();
+                }
+            } catch (Exception e) {
+                throw ObjectHelper.wrapRuntimeCamelException(e);
+            }
+        }
+    }
+}

http://git-wip-us.apache.org/repos/asf/camel/blob/14f23913/components/camel-master/src/main/java/org/apache/camel/component/master/MasterEndpoint.java
----------------------------------------------------------------------
diff --git a/components/camel-master/src/main/java/org/apache/camel/component/master/MasterEndpoint.java b/components/camel-master/src/main/java/org/apache/camel/component/master/MasterEndpoint.java
new file mode 100644
index 0000000..2b63597
--- /dev/null
+++ b/components/camel-master/src/main/java/org/apache/camel/component/master/MasterEndpoint.java
@@ -0,0 +1,84 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.component.master;
+
+import org.apache.camel.Consumer;
+import org.apache.camel.DelegateEndpoint;
+import org.apache.camel.Endpoint;
+import org.apache.camel.Processor;
+import org.apache.camel.Producer;
+import org.apache.camel.api.management.ManagedAttribute;
+import org.apache.camel.api.management.ManagedResource;
+import org.apache.camel.impl.DefaultEndpoint;
+import org.apache.camel.spi.Metadata;
+import org.apache.camel.spi.UriEndpoint;
+import org.apache.camel.spi.UriPath;
+
+@ManagedResource(description = "Managed Master Endpoint")
+@UriEndpoint(firstVersion = "2.20.0", scheme = "master", syntax = "master:namespace:delegateUri", consumerClass = MasterConsumer.class, consumerOnly = true,
+    title = "Master", lenientProperties = true, label = "clustering")
+public class MasterEndpoint extends DefaultEndpoint implements DelegateEndpoint {
+
+    private final Endpoint delegateEndpoint;
+
+    @UriPath(description = "The name of the cluster namespace to use")
+    @Metadata(required = "true")
+    private final String namespace;
+
+    @UriPath(description = "The endpoint uri to use in master/slave mode")
+    @Metadata(required = "true")
+    private final String delegateUri;
+
+    public MasterEndpoint(String uri, MasterComponent component, String namespace, String delegateUri) {
+        super(uri, component);
+        this.namespace = namespace;
+        this.delegateUri = delegateUri;
+        this.delegateEndpoint = getCamelContext().getEndpoint(delegateUri);
+    }
+
+    @Override
+    public Producer createProducer() throws Exception {
+        throw new UnsupportedOperationException("Cannot produce from this endpoint");
+    }
+
+    @Override
+    public Consumer createConsumer(Processor processor) throws Exception {
+        return new MasterConsumer(this, processor);
+    }
+
+    @Override
+    public boolean isSingleton() {
+        return true;
+    }
+
+    @Override
+    public boolean isLenientProperties() {
+        // to allow properties to be propagated to the child endpoint
+        return true;
+    }
+
+    @ManagedAttribute(description = "The consumer endpoint url to use in master/slave mode", mask = true)
+    @Override
+    public Endpoint getEndpoint() {
+        return delegateEndpoint;
+    }
+
+    @ManagedAttribute(description = "The name of the cluster namespace/group to use")
+    public String getNamespace() {
+        return namespace;
+    }
+}

http://git-wip-us.apache.org/repos/asf/camel/blob/14f23913/components/camel-master/src/main/resources/META-INF/LICENSE.txt
----------------------------------------------------------------------
diff --git a/components/camel-master/src/main/resources/META-INF/LICENSE.txt b/components/camel-master/src/main/resources/META-INF/LICENSE.txt
new file mode 100644
index 0000000..6b0b127
--- /dev/null
+++ b/components/camel-master/src/main/resources/META-INF/LICENSE.txt
@@ -0,0 +1,203 @@
+
+                                 Apache License
+                           Version 2.0, January 2004
+                        http://www.apache.org/licenses/
+
+   TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
+
+   1. Definitions.
+
+      "License" shall mean the terms and conditions for use, reproduction,
+      and distribution as defined by Sections 1 through 9 of this document.
+
+      "Licensor" shall mean the copyright owner or entity authorized by
+      the copyright owner that is granting the License.
+
+      "Legal Entity" shall mean the union of the acting entity and all
+      other entities that control, are controlled by, or are under common
+      control with that entity. For the purposes of this definition,
+      "control" means (i) the power, direct or indirect, to cause the
+      direction or management of such entity, whether by contract or
+      otherwise, or (ii) ownership of fifty percent (50%) or more of the
+      outstanding shares, or (iii) beneficial ownership of such entity.
+
+      "You" (or "Your") shall mean an individual or Legal Entity
+      exercising permissions granted by this License.
+
+      "Source" form shall mean the preferred form for making modifications,
+      including but not limited to software source code, documentation
+      source, and configuration files.
+
+      "Object" form shall mean any form resulting from mechanical
+      transformation or translation of a Source form, including but
+      not limited to compiled object code, generated documentation,
+      and conversions to other media types.
+
+      "Work" shall mean the work of authorship, whether in Source or
+      Object form, made available under the License, as indicated by a
+      copyright notice that is included in or attached to the work
+      (an example is provided in the Appendix below).
+
+      "Derivative Works" shall mean any work, whether in Source or Object
+      form, that is based on (or derived from) the Work and for which the
+      editorial revisions, annotations, elaborations, or other modifications
+      represent, as a whole, an original work of authorship. For the purposes
+      of this License, Derivative Works shall not include works that remain
+      separable from, or merely link (or bind by name) to the interfaces of,
+      the Work and Derivative Works thereof.
+
+      "Contribution" shall mean any work of authorship, including
+      the original version of the Work and any modifications or additions
+      to that Work or Derivative Works thereof, that is intentionally
+      submitted to Licensor for inclusion in the Work by the copyright owner
+      or by an individual or Legal Entity authorized to submit on behalf of
+      the copyright owner. For the purposes of this definition, "submitted"
+      means any form of electronic, verbal, or written communication sent
+      to the Licensor or its representatives, including but not limited to
+      communication on electronic mailing lists, source code control systems,
+      and issue tracking systems that are managed by, or on behalf of, the
+      Licensor for the purpose of discussing and improving the Work, but
+      excluding communication that is conspicuously marked or otherwise
+      designated in writing by the copyright owner as "Not a Contribution."
+
+      "Contributor" shall mean Licensor and any individual or Legal Entity
+      on behalf of whom a Contribution has been received by Licensor and
+      subsequently incorporated within the Work.
+
+   2. Grant of Copyright License. Subject to the terms and conditions of
+      this License, each Contributor hereby grants to You a perpetual,
+      worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+      copyright license to reproduce, prepare Derivative Works of,
+      publicly display, publicly perform, sublicense, and distribute the
+      Work and such Derivative Works in Source or Object form.
+
+   3. Grant of Patent License. Subject to the terms and conditions of
+      this License, each Contributor hereby grants to You a perpetual,
+      worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+      (except as stated in this section) patent license to make, have made,
+      use, offer to sell, sell, import, and otherwise transfer the Work,
+      where such license applies only to those patent claims licensable
+      by such Contributor that are necessarily infringed by their
+      Contribution(s) alone or by combination of their Contribution(s)
+      with the Work to which such Contribution(s) was submitted. If You
+      institute patent litigation against any entity (including a
+      cross-claim or counterclaim in a lawsuit) alleging that the Work
+      or a Contribution incorporated within the Work constitutes direct
+      or contributory patent infringement, then any patent licenses
+      granted to You under this License for that Work shall terminate
+      as of the date such litigation is filed.
+
+   4. Redistribution. You may reproduce and distribute copies of the
+      Work or Derivative Works thereof in any medium, with or without
+      modifications, and in Source or Object form, provided that You
+      meet the following conditions:
+
+      (a) You must give any other recipients of the Work or
+          Derivative Works a copy of this License; and
+
+      (b) You must cause any modified files to carry prominent notices
+          stating that You changed the files; and
+
+      (c) You must retain, in the Source form of any Derivative Works
+          that You distribute, all copyright, patent, trademark, and
+          attribution notices from the Source form of the Work,
+          excluding those notices that do not pertain to any part of
+          the Derivative Works; and
+
+      (d) If the Work includes a "NOTICE" text file as part of its
+          distribution, then any Derivative Works that You distribute must
+          include a readable copy of the attribution notices contained
+          within such NOTICE file, excluding those notices that do not
+          pertain to any part of the Derivative Works, in at least one
+          of the following places: within a NOTICE text file distributed
+          as part of the Derivative Works; within the Source form or
+          documentation, if provided along with the Derivative Works; or,
+          within a display generated by the Derivative Works, if and
+          wherever such third-party notices normally appear. The contents
+          of the NOTICE file are for informational purposes only and
+          do not modify the License. You may add Your own attribution
+          notices within Derivative Works that You distribute, alongside
+          or as an addendum to the NOTICE text from the Work, provided
+          that such additional attribution notices cannot be construed
+          as modifying the License.
+
+      You may add Your own copyright statement to Your modifications and
+      may provide additional or different license terms and conditions
+      for use, reproduction, or distribution of Your modifications, or
+      for any such Derivative Works as a whole, provided Your use,
+      reproduction, and distribution of the Work otherwise complies with
+      the conditions stated in this License.
+
+   5. Submission of Contributions. Unless You explicitly state otherwise,
+      any Contribution intentionally submitted for inclusion in the Work
+      by You to the Licensor shall be under the terms and conditions of
+      this License, without any additional terms or conditions.
+      Notwithstanding the above, nothing herein shall supersede or modify
+      the terms of any separate license agreement you may have executed
+      with Licensor regarding such Contributions.
+
+   6. Trademarks. This License does not grant permission to use the trade
+      names, trademarks, service marks, or product names of the Licensor,
+      except as required for reasonable and customary use in describing the
+      origin of the Work and reproducing the content of the NOTICE file.
+
+   7. Disclaimer of Warranty. Unless required by applicable law or
+      agreed to in writing, Licensor provides the Work (and each
+      Contributor provides its Contributions) on an "AS IS" BASIS,
+      WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+      implied, including, without limitation, any warranties or conditions
+      of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
+      PARTICULAR PURPOSE. You are solely responsible for determining the
+      appropriateness of using or redistributing the Work and assume any
+      risks associated with Your exercise of permissions under this License.
+
+   8. Limitation of Liability. In no event and under no legal theory,
+      whether in tort (including negligence), contract, or otherwise,
+      unless required by applicable law (such as deliberate and grossly
+      negligent acts) or agreed to in writing, shall any Contributor be
+      liable to You for damages, including any direct, indirect, special,
+      incidental, or consequential damages of any character arising as a
+      result of this License or out of the use or inability to use the
+      Work (including but not limited to damages for loss of goodwill,
+      work stoppage, computer failure or malfunction, or any and all
+      other commercial damages or losses), even if such Contributor
+      has been advised of the possibility of such damages.
+
+   9. Accepting Warranty or Additional Liability. While redistributing
+      the Work or Derivative Works thereof, You may choose to offer,
+      and charge a fee for, acceptance of support, warranty, indemnity,
+      or other liability obligations and/or rights consistent with this
+      License. However, in accepting such obligations, You may act only
+      on Your own behalf and on Your sole responsibility, not on behalf
+      of any other Contributor, and only if You agree to indemnify,
+      defend, and hold each Contributor harmless for any liability
+      incurred by, or claims asserted against, such Contributor by reason
+      of your accepting any such warranty or additional liability.
+
+   END OF TERMS AND CONDITIONS
+
+   APPENDIX: How to apply the Apache License to your work.
+
+      To apply the Apache License to your work, attach the following
+      boilerplate notice, with the fields enclosed by brackets "[]"
+      replaced with your own identifying information. (Don't include
+      the brackets!)  The text should be enclosed in the appropriate
+      comment syntax for the file format. We also recommend that a
+      file or class name and description of purpose be included on the
+      same "printed page" as the copyright notice for easier
+      identification within third-party archives.
+
+   Copyright [yyyy] [name of copyright owner]
+
+   Licensed under the Apache License, Version 2.0 (the "License");
+   you may not use this file except in compliance with the License.
+   You may obtain a copy of the License at
+
+       http://www.apache.org/licenses/LICENSE-2.0
+
+   Unless required by applicable law or agreed to in writing, software
+   distributed under the License is distributed on an "AS IS" BASIS,
+   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+   See the License for the specific language governing permissions and
+   limitations under the License.
+

http://git-wip-us.apache.org/repos/asf/camel/blob/14f23913/components/camel-master/src/main/resources/META-INF/NOTICE.txt
----------------------------------------------------------------------
diff --git a/components/camel-master/src/main/resources/META-INF/NOTICE.txt b/components/camel-master/src/main/resources/META-INF/NOTICE.txt
new file mode 100644
index 0000000..2e215bf
--- /dev/null
+++ b/components/camel-master/src/main/resources/META-INF/NOTICE.txt
@@ -0,0 +1,11 @@
+   =========================================================================
+   ==  NOTICE file corresponding to the section 4 d of                    ==
+   ==  the Apache License, Version 2.0,                                   ==
+   ==  in this case for the Apache Camel distribution.                    ==
+   =========================================================================
+
+   This product includes software developed by
+   The Apache Software Foundation (http://www.apache.org/).
+
+   Please read the different LICENSE files present in the licenses directory of
+   this distribution.

http://git-wip-us.apache.org/repos/asf/camel/blob/14f23913/components/camel-master/src/main/resources/META-INF/services/org/apache/camel/component/master
----------------------------------------------------------------------
diff --git a/components/camel-master/src/main/resources/META-INF/services/org/apache/camel/component/master b/components/camel-master/src/main/resources/META-INF/services/org/apache/camel/component/master
new file mode 100644
index 0000000..af75625
--- /dev/null
+++ b/components/camel-master/src/main/resources/META-INF/services/org/apache/camel/component/master
@@ -0,0 +1,17 @@
+#
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements.  See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# The ASF licenses this file to You under the Apache License, Version 2.0
+# (the "License"); you may not use this file except in compliance with
+# the License.  You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+class=org.apache.camel.component.master.MasterComponent

http://git-wip-us.apache.org/repos/asf/camel/blob/14f23913/components/camel-master/src/test/java/org/apache/camel/component/master/MasterComponentTest.java
----------------------------------------------------------------------
diff --git a/components/camel-master/src/test/java/org/apache/camel/component/master/MasterComponentTest.java b/components/camel-master/src/test/java/org/apache/camel/component/master/MasterComponentTest.java
new file mode 100644
index 0000000..bbd8ce3
--- /dev/null
+++ b/components/camel-master/src/test/java/org/apache/camel/component/master/MasterComponentTest.java
@@ -0,0 +1,106 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.component.master;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.concurrent.CountDownLatch;
+import java.util.concurrent.Executors;
+import java.util.concurrent.ScheduledExecutorService;
+import java.util.concurrent.ThreadLocalRandom;
+import java.util.concurrent.TimeUnit;
+import java.util.stream.Collectors;
+import java.util.stream.IntStream;
+
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.master.util.InMemoryClusterService;
+import org.apache.camel.impl.DefaultCamelContext;
+import org.apache.camel.test.AvailablePortFinder;
+import org.junit.Assert;
+import org.junit.Test;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+
+public class MasterComponentTest {
+    private static final Logger LOGGER = LoggerFactory.getLogger(MasterComponentTest.class);
+    private static final List<String> INSTANCES = IntStream.range(0, 3).mapToObj(Integer::toString).collect(Collectors.toList());
+    private static final List<Integer> PORTS = INSTANCES.stream().map(i -> AvailablePortFinder.getNextAvailable()).collect(Collectors.toList());
+    private static final List<String> RESULTS = new ArrayList<>();
+    private static final ScheduledExecutorService SCHEDULER = Executors.newScheduledThreadPool(INSTANCES.size() * 2);
+    private static final CountDownLatch LATCH = new CountDownLatch(INSTANCES.size());
+
+    @Test
+    public void test()  throws Exception {
+        for (int i = 0; i < INSTANCES.size(); i++) {
+            int index = i;
+            SCHEDULER.submit(() -> run(INSTANCES.get(index), index, PORTS));
+            Thread.sleep(1000);
+        }
+
+        LATCH.await(1, TimeUnit.MINUTES);
+        SCHEDULER.shutdownNow();
+
+        Assert.assertEquals(INSTANCES.size(), RESULTS.size());
+        Assert.assertTrue(RESULTS.containsAll(INSTANCES));
+    }
+
+    // ************************************
+    // Run a Camel node
+    // ************************************
+
+    private static void run(String id, int index, List<Integer> ports) {
+        try {
+            CountDownLatch contextLatch = new CountDownLatch(1);
+
+            InMemoryClusterService service = new InMemoryClusterService();
+            service.setIndex(index);
+            service.setPorts(ports);
+
+            DefaultCamelContext context = new DefaultCamelContext();
+            context.disableJMX();
+            context.setName("context-" + id);
+            context.addService(service);
+            context.addRoutes(new RouteBuilder() {
+                @Override
+                public void configure() throws Exception {
+                    from("master:ns:timer:test?delay=1s&period=1s&repeatCount=1")
+                        .routeId("route-" + id)
+                        .process(e -> {
+                            LOGGER.info("Node {} done", id);
+                            RESULTS.add(id);
+                            // Shutdown the context later on to give a chance to
+                            // other members to catch-up
+                            SCHEDULER.schedule(contextLatch::countDown, 2 + ThreadLocalRandom.current().nextInt(3), TimeUnit.SECONDS);
+                        });
+                }
+            });
+
+            // Start the context after some random time so the startup order
+            // changes for each test.
+            Thread.sleep(ThreadLocalRandom.current().nextInt(500));
+            context.start();
+
+            contextLatch.await();
+            context.stop();
+
+            LATCH.countDown();
+        } catch (Exception e) {
+            LOGGER.warn("", e);
+        }
+    }
+}

http://git-wip-us.apache.org/repos/asf/camel/blob/14f23913/components/camel-master/src/test/java/org/apache/camel/component/master/util/InMemoryClusterMember.java
----------------------------------------------------------------------
diff --git a/components/camel-master/src/test/java/org/apache/camel/component/master/util/InMemoryClusterMember.java b/components/camel-master/src/test/java/org/apache/camel/component/master/util/InMemoryClusterMember.java
new file mode 100644
index 0000000..cfe3fcc
--- /dev/null
+++ b/components/camel-master/src/test/java/org/apache/camel/component/master/util/InMemoryClusterMember.java
@@ -0,0 +1,49 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.component.master.util;
+
+import java.util.List;
+
+import org.apache.camel.ha.CamelClusterMember;
+import org.apache.camel.util.ObjectHelper;
+import org.jgroups.Address;
+import org.jgroups.JChannel;
+import org.jgroups.View;
+
+public class InMemoryClusterMember implements CamelClusterMember {
+    private final JChannel channel;
+    private final View view;
+
+    public InMemoryClusterMember(JChannel channel) {
+        this.channel = channel;
+        this.view = channel.getView();
+    }
+
+    @Override
+    public boolean isMaster() {
+        final List<Address> members = view.getMembers();
+
+        return ObjectHelper.isNotEmpty(members)
+            ? members.get(0).equals(channel.getAddress())
+            : false;
+    }
+
+    @Override
+    public String getId() {
+        return channel.name();
+    }
+}

http://git-wip-us.apache.org/repos/asf/camel/blob/14f23913/components/camel-master/src/test/java/org/apache/camel/component/master/util/InMemoryClusterService.java
----------------------------------------------------------------------
diff --git a/components/camel-master/src/test/java/org/apache/camel/component/master/util/InMemoryClusterService.java b/components/camel-master/src/test/java/org/apache/camel/component/master/util/InMemoryClusterService.java
new file mode 100644
index 0000000..7b40a72
--- /dev/null
+++ b/components/camel-master/src/test/java/org/apache/camel/component/master/util/InMemoryClusterService.java
@@ -0,0 +1,47 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.component.master.util;
+
+import java.util.List;
+
+import org.apache.camel.impl.ha.AbstractCamelClusterService;
+
+public class InMemoryClusterService extends AbstractCamelClusterService<InMemoryClusterView> {
+    private int index;
+    private List<Integer> ports;
+
+    @Override
+    protected InMemoryClusterView createView(String namespace) throws Exception {
+        return new InMemoryClusterView(this, namespace);
+    }
+
+    public int getIndex() {
+        return index;
+    }
+
+    public void setIndex(int index) {
+        this.index = index;
+    }
+
+    public List<Integer> getPorts() {
+        return ports;
+    }
+
+    public void setPorts(List<Integer> ports) {
+        this.ports = ports;
+    }
+}

http://git-wip-us.apache.org/repos/asf/camel/blob/14f23913/components/camel-master/src/test/java/org/apache/camel/component/master/util/InMemoryClusterView.java
----------------------------------------------------------------------
diff --git a/components/camel-master/src/test/java/org/apache/camel/component/master/util/InMemoryClusterView.java b/components/camel-master/src/test/java/org/apache/camel/component/master/util/InMemoryClusterView.java
new file mode 100644
index 0000000..41728e1
--- /dev/null
+++ b/components/camel-master/src/test/java/org/apache/camel/component/master/util/InMemoryClusterView.java
@@ -0,0 +1,159 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.component.master.util;
+
+import java.net.InetAddress;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+import java.util.Optional;
+
+import static java.util.stream.Collectors.toList;
+
+import org.apache.camel.ha.CamelClusterMember;
+import org.apache.camel.ha.CamelClusterService;
+import org.apache.camel.impl.ha.AbstractCamelClusterView;
+import org.apache.camel.util.ObjectHelper;
+import org.jgroups.Address;
+import org.jgroups.JChannel;
+import org.jgroups.PhysicalAddress;
+import org.jgroups.ReceiverAdapter;
+import org.jgroups.View;
+import org.jgroups.protocols.TCP;
+import org.jgroups.protocols.TCPPING;
+import org.jgroups.stack.IpAddress;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class InMemoryClusterView extends AbstractCamelClusterView {
+    private static final Logger LOGGER = LoggerFactory.getLogger(InMemoryClusterView.class);
+
+    private JChannel channel;
+
+    protected InMemoryClusterView(CamelClusterService cluster, String namespace) {
+        super(cluster, namespace);
+    }
+
+    @Override
+    public Optional<CamelClusterMember> getMaster() {
+        return channel != null
+            ? Optional.of(new InMemoryClusterMember(channel))
+            : Optional.empty();
+    }
+
+    @Override
+    public CamelClusterMember getLocalMember() {
+        return new LocalClusterMember();
+    }
+
+    @Override
+    public List<CamelClusterMember> getMembers() {
+        if (channel != null) {
+            channel.getView().getMembers().stream()
+                .map(ClusterMember::new)
+                .collect(toList());
+        }
+
+        return Collections.emptyList();
+    }
+
+    @Override
+    protected void doStart() throws Exception {
+        final int index = getClusterService().unwrap(InMemoryClusterService.class).getIndex();
+        final List<Integer> ports = getClusterService().unwrap(InMemoryClusterService.class).getPorts();
+        final List<PhysicalAddress> addresses = new ArrayList<>();
+
+        for (Integer port: ports) {
+            addresses.add(new IpAddress("127.0.0.1", port));
+        }
+
+        this.channel = new JChannel(getClass().getResourceAsStream("/jgroups-tcp.xml"));
+
+        TCP tcp = this.channel.getProtocolStack().findProtocol(TCP.class);
+        tcp.setBindAddress(InetAddress.getByName("127.0.0.1"));
+        tcp.setBindPort(ports.get(index));
+
+        TCPPING tcpping  = this.channel.getProtocolStack().findProtocol(TCPPING.class);
+        tcpping.setInitialHosts(addresses);
+
+        this.channel.setReceiver(new ReceiverAdapter() {
+            @Override
+            public void viewAccepted(View view) {
+                fireLeadershipChangedEvent(new ClusterMember(view.getMembers().get(0)));
+            }
+        });
+
+        this.channel.connect(getNamespace());
+    }
+
+    @Override
+    protected void doStop() throws Exception {
+        if (channel != null) {
+            channel.close();
+        }
+    }
+
+    // ***********************************
+    //
+    // ***********************************
+
+    private class LocalClusterMember implements CamelClusterMember {
+        @Override
+        public boolean isMaster() {
+            if (channel == null) {
+                return false;
+            }
+
+            List<Address> members = channel.view().getMembers();
+
+            if (ObjectHelper.isNotEmpty(members)) {
+                LOGGER.info("master={}, channel={}, members={}", members.get(0), channel.getAddress(), members);
+                return members.get(0).equals(channel.getAddress());
+            }
+
+            return false;
+        }
+
+        @Override
+        public String getId() {
+            return channel != null ? channel.getAddressAsString() : "local";
+        }
+    }
+
+    private class ClusterMember implements CamelClusterMember {
+        private final Address address;
+
+        public ClusterMember(Address address) {
+            this.address = address;
+        }
+
+        @Override
+        public boolean isMaster() {
+            final List<Address> members = channel.view().getMembers();
+
+            return ObjectHelper.isNotEmpty(members)
+                ? members.get(0).equals(address)
+                : false;
+        }
+
+        @Override
+        public String getId() {
+            return channel.getAddressAsString();
+        }
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/camel/blob/14f23913/components/camel-master/src/test/resources/jgroups-tcp.xml
----------------------------------------------------------------------
diff --git a/components/camel-master/src/test/resources/jgroups-tcp.xml b/components/camel-master/src/test/resources/jgroups-tcp.xml
new file mode 100644
index 0000000..3e6d58d
--- /dev/null
+++ b/components/camel-master/src/test/resources/jgroups-tcp.xml
@@ -0,0 +1,53 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+
+    Licensed to the Apache Software Foundation (ASF) under one or more
+    contributor license agreements.  See the NOTICE file distributed with
+    this work for additional information regarding copyright ownership.
+    The ASF licenses this file to You under the Apache License, Version 2.0
+    (the "License"); you may not use this file except in compliance with
+    the License.  You may obtain a copy of the License at
+
+         http://www.apache.org/licenses/LICENSE-2.0
+
+    Unless required by applicable law or agreed to in writing, software
+    distributed under the License is distributed on an "AS IS" BASIS,
+    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+    See the License for the specific language governing permissions and
+    limitations under the License.
+
+-->
+<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+        xmlns="urn:org:jgroups"
+        xsi:schemaLocation="urn:org:jgroups http://www.jgroups.org/schema/jgroups.xsd">
+  <TCP bind_port="7800"
+       recv_buf_size="${tcp.recv_buf_size:130k}"
+       send_buf_size="${tcp.send_buf_size:130k}"
+       max_bundle_size="64K"
+       sock_conn_timeout="300"
+
+       thread_pool.min_threads="0"
+       thread_pool.max_threads="20"
+       thread_pool.keep_alive_time="30000"/>
+
+  <TCPPING async_discovery="true"
+           initial_hosts="${jgroups.tcpping.initial_hosts:localhost[7800],localhost[7801]}"
+           port_range="2"/>
+  <MERGE3  min_interval="10000"
+           max_interval="30000"/>
+  <FD_SOCK/>
+  <FD timeout="3000" max_tries="3" />
+  <VERIFY_SUSPECT timeout="1500"  />
+  <BARRIER />
+  <pbcast.NAKACK2 use_mcast_xmit="false"
+                  discard_delivered_msgs="true"/>
+  <UNICAST3 />
+  <pbcast.STABLE desired_avg_gossip="50000"
+                 max_bytes="4M"/>
+  <pbcast.GMS print_local_addr="true" join_timeout="2000"/>
+  <MFC max_credits="2M"
+       min_threshold="0.4"/>
+  <FRAG2 frag_size="60K"  />
+  <!--RSVP resend_interval="2000" timeout="10000"/-->
+  <pbcast.STATE_TRANSFER/>
+</config>
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/camel/blob/14f23913/components/camel-master/src/test/resources/log4j2.properties
----------------------------------------------------------------------
diff --git a/components/camel-master/src/test/resources/log4j2.properties b/components/camel-master/src/test/resources/log4j2.properties
new file mode 100644
index 0000000..e5a24c1f
--- /dev/null
+++ b/components/camel-master/src/test/resources/log4j2.properties
@@ -0,0 +1,40 @@
+## ---------------------------------------------------------------------------
+## Licensed to the Apache Software Foundation (ASF) under one or more
+## contributor license agreements.  See the NOTICE file distributed with
+## this work for additional information regarding copyright ownership.
+## The ASF licenses this file to You under the Apache License, Version 2.0
+## (the "License"); you may not use this file except in compliance with
+## the License.  You may obtain a copy of the License at
+##
+##      http://www.apache.org/licenses/LICENSE-2.0
+##
+## Unless required by applicable law or agreed to in writing, software
+## distributed under the License is distributed on an "AS IS" BASIS,
+## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+## See the License for the specific language governing permissions and
+## limitations under the License.
+## ---------------------------------------------------------------------------
+
+appender.file.type = File
+appender.file.name = file
+appender.file.fileName = target/camel-master-test.log
+appender.file.layout.type = PatternLayout
+appender.file.layout.pattern = %d [%-15.15t] %-5p %-30.30c{1} - %m%n
+appender.out.type = Console
+appender.out.name = out
+appender.out.layout.type = PatternLayout
+appender.out.layout.pattern = [%t] %c{1} %-5p %m%n
+
+logger.camel-master.name = org.apache.camel.component.master
+logger.camel-master.level = DEBUG
+logger.camel.name = org.apache.camel
+logger.camel.level = INFO
+
+logger.springframework.name = org.springframework
+logger.springframework.level = WARN
+
+rootLogger.level = INFO
+rootLogger.appenderRef.stdout.ref = out
+rootLogger.appenderRef.file.ref = file
+
+

http://git-wip-us.apache.org/repos/asf/camel/blob/14f23913/components/camel-zookeeper/pom.xml
----------------------------------------------------------------------
diff --git a/components/camel-zookeeper/pom.xml b/components/camel-zookeeper/pom.xml
index afb1b16..0ce41bf 100644
--- a/components/camel-zookeeper/pom.xml
+++ b/components/camel-zookeeper/pom.xml
@@ -95,6 +95,11 @@
     </dependency>
     <dependency>
       <groupId>org.apache.camel</groupId>
+      <artifactId>camel-master</artifactId>
+      <scope>test</scope>
+    </dependency>
+    <dependency>
+      <groupId>org.apache.camel</groupId>
       <artifactId>camel-test-spring</artifactId>
       <scope>test</scope>
     </dependency>  

http://git-wip-us.apache.org/repos/asf/camel/blob/14f23913/components/camel-zookeeper/src/test/java/org/apache/camel/component/zookeeper/ha/ZooKeeperMasterMain.java
----------------------------------------------------------------------
diff --git a/components/camel-zookeeper/src/test/java/org/apache/camel/component/zookeeper/ha/ZooKeeperMasterMain.java b/components/camel-zookeeper/src/test/java/org/apache/camel/component/zookeeper/ha/ZooKeeperMasterMain.java
new file mode 100644
index 0000000..148a5dd
--- /dev/null
+++ b/components/camel-zookeeper/src/test/java/org/apache/camel/component/zookeeper/ha/ZooKeeperMasterMain.java
@@ -0,0 +1,63 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.component.zookeeper.ha;
+
+import java.util.UUID;
+import java.util.concurrent.ThreadLocalRandom;
+
+import org.apache.camel.CamelContext;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.main.Main;
+import org.apache.camel.main.MainListenerSupport;
+
+public final class ZooKeeperMasterMain {
+    public static void main(String[] args) throws Exception {
+        final String nodeId = UUID.randomUUID().toString();
+        final String address = args[0];
+
+        ZooKeeperClusterService service = new ZooKeeperClusterService();
+        service.setId("node-" + nodeId);
+        service.setNodes(address);
+        service.setBasePath("/camel/master");
+
+        Main main = new Main();
+        main.addMainListener(new MainListenerSupport() {
+            @Override
+            public void configure(CamelContext context) {
+                try {
+                    context.addService(service);
+                } catch (Exception e) {
+                    throw new RuntimeException(e);
+                }
+            }
+        });
+
+        main.addRouteBuilder(new RouteBuilder() {
+            @Override
+            public void configure() throws Exception {
+                final int delay = 1 + ThreadLocalRandom.current().nextInt(10);
+                final int period = 1 + ThreadLocalRandom.current().nextInt(5);
+
+                fromF("master:zk:timer:master?delay=%ds&period=%ds", delay, period)
+                    .routeId("route-" + nodeId)
+                    .log("Node " + nodeId + " timer");
+            }
+        });
+
+        main.run();
+    }
+}

http://git-wip-us.apache.org/repos/asf/camel/blob/14f23913/components/camel-zookeeper/src/test/java/org/apache/camel/component/zookeeper/ha/ZooKeeperMasterTest.java
----------------------------------------------------------------------
diff --git a/components/camel-zookeeper/src/test/java/org/apache/camel/component/zookeeper/ha/ZooKeeperMasterTest.java b/components/camel-zookeeper/src/test/java/org/apache/camel/component/zookeeper/ha/ZooKeeperMasterTest.java
new file mode 100644
index 0000000..948834a
--- /dev/null
+++ b/components/camel-zookeeper/src/test/java/org/apache/camel/component/zookeeper/ha/ZooKeeperMasterTest.java
@@ -0,0 +1,120 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.component.zookeeper.ha;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.concurrent.CountDownLatch;
+import java.util.concurrent.Executors;
+import java.util.concurrent.ScheduledExecutorService;
+import java.util.concurrent.ThreadLocalRandom;
+import java.util.concurrent.TimeUnit;
+import java.util.stream.Collectors;
+import java.util.stream.IntStream;
+
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.zookeeper.ZooKeeperTestSupport;
+import org.apache.camel.component.zookeeper.ZooKeeperTestSupport.TestZookeeperServer;
+import org.apache.camel.impl.DefaultCamelContext;
+import org.apache.camel.test.AvailablePortFinder;
+import org.junit.Assert;
+import org.junit.Test;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public final class ZooKeeperMasterTest {
+    private static final int PORT = AvailablePortFinder.getNextAvailable();
+    private static final Logger LOGGER = LoggerFactory.getLogger(ZooKeeperMasterTest.class);
+    private static final List<String> CLIENTS = IntStream.range(0, 3).mapToObj(Integer::toString).collect(Collectors.toList());
+    private static final List<String> RESULTS = new ArrayList<>();
+    private static final ScheduledExecutorService SCHEDULER = Executors.newScheduledThreadPool(CLIENTS.size() * 2);
+    private static final CountDownLatch LATCH = new CountDownLatch(CLIENTS.size());
+
+    // ************************************
+    // Test
+    // ************************************
+
+    @Test
+    public void test() throws Exception {
+        TestZookeeperServer server = null;
+
+        try {
+            server = new TestZookeeperServer(PORT, true);
+            ZooKeeperTestSupport.waitForServerUp("localhost:" + PORT, 1000);
+
+            for (String id : CLIENTS) {
+                SCHEDULER.submit(() -> run(id));
+            }
+
+            LATCH.await(1, TimeUnit.MINUTES);
+            SCHEDULER.shutdownNow();
+
+            Assert.assertEquals(CLIENTS.size(), RESULTS.size());
+            Assert.assertTrue(RESULTS.containsAll(CLIENTS));
+        } finally {
+            if (server != null) {
+                server.shutdown();
+            }
+        }
+    }
+
+    // ************************************
+    // Run a Camel node
+    // ************************************
+
+    private static void run(String id) {
+        try {
+            CountDownLatch contextLatch = new CountDownLatch(1);
+
+            ZooKeeperClusterService service = new ZooKeeperClusterService();
+            service.setId("node-" + id);
+            service.setNodes("localhost:" + PORT);
+            service.setBasePath("/camel/master");
+
+            DefaultCamelContext context = new DefaultCamelContext();
+            context.disableJMX();
+            context.setName("context-" + id);
+            context.addService(service);
+            context.addRoutes(new RouteBuilder() {
+                @Override
+                public void configure() throws Exception {
+                    from("master:zk:timer:master?delay=1s&period=1s&repeatCount=1")
+                        .routeId("route-" + id)
+                        .process(e -> {
+                            LOGGER.debug("Node {} done", id);
+                            RESULTS.add(id);
+                            // Shutdown the context later on to give a chance to
+                            // other members to catch-up
+                            SCHEDULER.schedule(contextLatch::countDown, 2 + ThreadLocalRandom.current().nextInt(3), TimeUnit.SECONDS);
+                        });
+                }
+            });
+
+            // Start the context after some random time so the startup order
+            // changes for each test.
+            Thread.sleep(ThreadLocalRandom.current().nextInt(500));
+            context.start();
+
+            contextLatch.await();
+            context.stop();
+
+            LATCH.countDown();
+        } catch (Exception e) {
+            LOGGER.warn("", e);
+        }
+    }
+}

http://git-wip-us.apache.org/repos/asf/camel/blob/14f23913/components/camel-zookeeper/src/test/resources/log4j2.properties
----------------------------------------------------------------------
diff --git a/components/camel-zookeeper/src/test/resources/log4j2.properties b/components/camel-zookeeper/src/test/resources/log4j2.properties
index 52dfed8..1dda6f0 100644
--- a/components/camel-zookeeper/src/test/resources/log4j2.properties
+++ b/components/camel-zookeeper/src/test/resources/log4j2.properties
@@ -48,4 +48,3 @@ logger.springframework.level = WARN
 rootLogger.level = INFO
 #rootLogger.appenderRef.stdout.ref = out
 rootLogger.appenderRef.file.ref = file
-

http://git-wip-us.apache.org/repos/asf/camel/blob/14f23913/components/pom.xml
----------------------------------------------------------------------
diff --git a/components/pom.xml b/components/pom.xml
index 78570ef..83d4b52 100644
--- a/components/pom.xml
+++ b/components/pom.xml
@@ -59,6 +59,7 @@
     <module>camel-cxf</module>
     <module>camel-cxf-transport</module>
     <module>camel-jms</module>
+    <module>camel-master</module>
 
     <!-- build it first so it can be used by other component to test i.e. ServiceCall EIP -->
     <module>camel-ribbon</module>

http://git-wip-us.apache.org/repos/asf/camel/blob/14f23913/parent/pom.xml
----------------------------------------------------------------------
diff --git a/parent/pom.xml b/parent/pom.xml
index d471b57..a68ee43 100644
--- a/parent/pom.xml
+++ b/parent/pom.xml
@@ -1582,6 +1582,11 @@
       </dependency>
       <dependency>
         <groupId>org.apache.camel</groupId>
+        <artifactId>camel-master</artifactId>
+        <version>${project.version}</version>
+      </dependency>
+      <dependency>
+        <groupId>org.apache.camel</groupId>
         <artifactId>camel-metrics</artifactId>
         <version>${project.version}</version>
       </dependency>
@@ -2996,6 +3001,11 @@
       </dependency>
       <dependency>
         <groupId>org.apache.camel</groupId>
+        <artifactId>camel-master-starter</artifactId>
+        <version>${project.version}</version>
+      </dependency>
+      <dependency>
+        <groupId>org.apache.camel</groupId>
         <artifactId>camel-metrics-starter</artifactId>
         <version>${project.version}</version>
       </dependency>

http://git-wip-us.apache.org/repos/asf/camel/blob/14f23913/platforms/spring-boot/components-starter/camel-master-starter/pom.xml
----------------------------------------------------------------------
diff --git a/platforms/spring-boot/components-starter/camel-master-starter/pom.xml b/platforms/spring-boot/components-starter/camel-master-starter/pom.xml
new file mode 100644
index 0000000..bd8b9d7
--- /dev/null
+++ b/platforms/spring-boot/components-starter/camel-master-starter/pom.xml
@@ -0,0 +1,53 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+
+    Licensed to the Apache Software Foundation (ASF) under one or more
+    contributor license agreements.  See the NOTICE file distributed with
+    this work for additional information regarding copyright ownership.
+    The ASF licenses this file to You under the Apache License, Version 2.0
+    (the "License"); you may not use this file except in compliance with
+    the License.  You may obtain a copy of the License at
+
+         http://www.apache.org/licenses/LICENSE-2.0
+
+    Unless required by applicable law or agreed to in writing, software
+    distributed under the License is distributed on an "AS IS" BASIS,
+    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+    See the License for the specific language governing permissions and
+    limitations under the License.
+
+-->
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+  <modelVersion>4.0.0</modelVersion>
+  <parent>
+    <groupId>org.apache.camel</groupId>
+    <artifactId>components-starter</artifactId>
+    <version>2.20.0-SNAPSHOT</version>
+  </parent>
+  <artifactId>camel-master-starter</artifactId>
+  <packaging>jar</packaging>
+  <name>Spring-Boot Starter :: Camel :: Master</name>
+  <description>Spring-Boot Starter for Camel Master Support</description>
+  <dependencies>
+    <dependency>
+      <groupId>org.springframework.boot</groupId>
+      <artifactId>spring-boot-starter</artifactId>
+      <version>${spring-boot-version}</version>
+    </dependency>
+    <dependency>
+      <groupId>org.apache.camel</groupId>
+      <artifactId>camel-master</artifactId>
+      <version>${project.version}</version>
+    </dependency>
+    <!--START OF GENERATED CODE-->
+    <dependency>
+      <groupId>org.apache.camel</groupId>
+      <artifactId>camel-core-starter</artifactId>
+    </dependency>
+    <dependency>
+      <groupId>org.apache.camel</groupId>
+      <artifactId>camel-spring-boot-starter</artifactId>
+    </dependency>
+    <!--END OF GENERATED CODE-->
+  </dependencies>
+</project>

http://git-wip-us.apache.org/repos/asf/camel/blob/14f23913/platforms/spring-boot/components-starter/camel-master-starter/src/main/java/org/apache/camel/component/master/springboot/MasterComponentAutoConfiguration.java
----------------------------------------------------------------------
diff --git a/platforms/spring-boot/components-starter/camel-master-starter/src/main/java/org/apache/camel/component/master/springboot/MasterComponentAutoConfiguration.java b/platforms/spring-boot/components-starter/camel-master-starter/src/main/java/org/apache/camel/component/master/springboot/MasterComponentAutoConfiguration.java
new file mode 100644
index 0000000..562413a
--- /dev/null
+++ b/platforms/spring-boot/components-starter/camel-master-starter/src/main/java/org/apache/camel/component/master/springboot/MasterComponentAutoConfiguration.java
@@ -0,0 +1,128 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.component.master.springboot;
+
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import javax.annotation.Generated;
+import org.apache.camel.CamelContext;
+import org.apache.camel.component.master.MasterComponent;
+import org.apache.camel.spi.ComponentCustomizer;
+import org.apache.camel.spi.HasId;
+import org.apache.camel.spring.boot.CamelAutoConfiguration;
+import org.apache.camel.spring.boot.ComponentConfigurationProperties;
+import org.apache.camel.spring.boot.util.CamelPropertiesHelper;
+import org.apache.camel.spring.boot.util.ConditionalOnCamelContextAndAutoConfigurationBeans;
+import org.apache.camel.spring.boot.util.GroupCondition;
+import org.apache.camel.spring.boot.util.HierarchicalPropertiesEvaluator;
+import org.apache.camel.util.IntrospectionSupport;
+import org.apache.camel.util.ObjectHelper;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.boot.autoconfigure.AutoConfigureAfter;
+import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
+import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
+import org.springframework.boot.context.properties.EnableConfigurationProperties;
+import org.springframework.context.ApplicationContext;
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Conditional;
+import org.springframework.context.annotation.Configuration;
+import org.springframework.context.annotation.Lazy;
+
+/**
+ * Generated by camel-package-maven-plugin - do not edit this file!
+ */
+@Generated("org.apache.camel.maven.packaging.SpringBootAutoConfigurationMojo")
+@Configuration
+@Conditional({ConditionalOnCamelContextAndAutoConfigurationBeans.class,
+        MasterComponentAutoConfiguration.GroupConditions.class})
+@AutoConfigureAfter(CamelAutoConfiguration.class)
+@EnableConfigurationProperties({ComponentConfigurationProperties.class,
+        MasterComponentConfiguration.class})
+public class MasterComponentAutoConfiguration {
+
+    private static final Logger LOGGER = LoggerFactory
+            .getLogger(MasterComponentAutoConfiguration.class);
+    @Autowired
+    private ApplicationContext applicationContext;
+    @Autowired
+    private CamelContext camelContext;
+    @Autowired
+    private MasterComponentConfiguration configuration;
+    @Autowired(required = false)
+    private List<ComponentCustomizer<MasterComponent>> customizers;
+
+    static class GroupConditions extends GroupCondition {
+        public GroupConditions() {
+            super("camel.component", "camel.component.master");
+        }
+    }
+
+    @Lazy
+    @Bean(name = "master-component")
+    @ConditionalOnMissingBean(MasterComponent.class)
+    public MasterComponent configureMasterComponent() throws Exception {
+        MasterComponent component = new MasterComponent();
+        component.setCamelContext(camelContext);
+        Map<String, Object> parameters = new HashMap<>();
+        IntrospectionSupport.getProperties(configuration, parameters, null,
+                false);
+        for (Map.Entry<String, Object> entry : parameters.entrySet()) {
+            Object value = entry.getValue();
+            Class<?> paramClass = value.getClass();
+            if (paramClass.getName().endsWith("NestedConfiguration")) {
+                Class nestedClass = null;
+                try {
+                    nestedClass = (Class) paramClass.getDeclaredField(
+                            "CAMEL_NESTED_CLASS").get(null);
+                    HashMap<String, Object> nestedParameters = new HashMap<>();
+                    IntrospectionSupport.getProperties(value, nestedParameters,
+                            null, false);
+                    Object nestedProperty = nestedClass.newInstance();
+                    CamelPropertiesHelper.setCamelProperties(camelContext,
+                            nestedProperty, nestedParameters, false);
+                    entry.setValue(nestedProperty);
+                } catch (NoSuchFieldException e) {
+                }
+            }
+        }
+        CamelPropertiesHelper.setCamelProperties(camelContext, component,
+                parameters, false);
+        if (ObjectHelper.isNotEmpty(customizers)) {
+            for (ComponentCustomizer<MasterComponent> customizer : customizers) {
+                boolean useCustomizer = (customizer instanceof HasId)
+                        ? HierarchicalPropertiesEvaluator.evaluate(
+                                applicationContext.getEnvironment(),
+                                "camel.component.customizer",
+                                "camel.component.master.customizer",
+                                ((HasId) customizer).getId())
+                        : HierarchicalPropertiesEvaluator.evaluate(
+                                applicationContext.getEnvironment(),
+                                "camel.component.customizer",
+                                "camel.component.master.customizer");
+                if (useCustomizer) {
+                    LOGGER.debug("Configure component {}, with customizer {}",
+                            component, customizer);
+                    customizer.customize(component);
+                }
+            }
+        }
+        return component;
+    }
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/camel/blob/14f23913/platforms/spring-boot/components-starter/camel-master-starter/src/main/java/org/apache/camel/component/master/springboot/MasterComponentConfiguration.java
----------------------------------------------------------------------
diff --git a/platforms/spring-boot/components-starter/camel-master-starter/src/main/java/org/apache/camel/component/master/springboot/MasterComponentConfiguration.java b/platforms/spring-boot/components-starter/camel-master-starter/src/main/java/org/apache/camel/component/master/springboot/MasterComponentConfiguration.java
new file mode 100644
index 0000000..9c104c1
--- /dev/null
+++ b/platforms/spring-boot/components-starter/camel-master-starter/src/main/java/org/apache/camel/component/master/springboot/MasterComponentConfiguration.java
@@ -0,0 +1,50 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.component.master.springboot;
+
+import javax.annotation.Generated;
+import org.apache.camel.spring.boot.ComponentConfigurationPropertiesCommon;
+import org.springframework.boot.context.properties.ConfigurationProperties;
+
+/**
+ * Represents an endpoint which only becomes active when it obtains the master
+ * lock
+ * 
+ * Generated by camel-package-maven-plugin - do not edit this file!
+ */
+@Generated("org.apache.camel.maven.packaging.SpringBootAutoConfigurationMojo")
+@ConfigurationProperties(prefix = "camel.component.master")
+public class MasterComponentConfiguration
+        extends
+            ComponentConfigurationPropertiesCommon {
+
+    /**
+     * Whether the component should resolve property placeholders on itself when
+     * starting. Only properties which are of String type can use property
+     * placeholders.
+     */
+    private Boolean resolvePropertyPlaceholders = true;
+
+    public Boolean getResolvePropertyPlaceholders() {
+        return resolvePropertyPlaceholders;
+    }
+
+    public void setResolvePropertyPlaceholders(
+            Boolean resolvePropertyPlaceholders) {
+        this.resolvePropertyPlaceholders = resolvePropertyPlaceholders;
+    }
+}
\ No newline at end of file


Mime
View raw message