camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From lburgazz...@apache.org
Subject [1/7] camel git commit: CAMEL-10025: Create a DNS based ServiceCall EIP
Date Tue, 07 Jun 2016 14:32:01 GMT
Repository: camel
Updated Branches:
  refs/heads/master f0b952668 -> 1019bb164


CAMEL-10025: Create a DNS based ServiceCall EIP


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

Branch: refs/heads/master
Commit: 1019bb164f4271ac4b486646da3e70a02ec44006
Parents: bafe28e
Author: lburgazzoli <lburgazzoli@gmail.com>
Authored: Tue Jun 7 11:32:01 2016 +0200
Committer: lburgazzoli <lburgazzoli@gmail.com>
Committed: Tue Jun 7 16:30:43 2016 +0200

----------------------------------------------------------------------
 .../remote/DnsConfigurationDefinition.java      | 82 ++++++++++++++++++++
 .../model/remote/ServiceCallDefinition.java     | 11 +++
 .../org/apache/camel/model/remote/jaxb.index    |  1 +
 .../blueprint/CamelContextFactoryBean.java      |  8 +-
 .../camel/component/dns/DnsConfiguration.java   | 52 +++++++++++++
 .../remote/DnsServiceCallProcessor.java         | 42 ++++++++++
 .../remote/DnsServiceCallProcessorFactory.java  | 68 ++++++++++++++++
 .../processor/remote/DnsServiceCallServer.java  | 37 +++++++++
 .../DnsServiceCallServerListStrategies.java     | 77 ++++++++++++++++++
 .../DnsServiceCallServerListStrategy.java       | 35 +++++++++
 .../remote/DnsServiceLookupFactory.java         | 59 ++++++++++++++
 .../apache/camel/model/ServiceCallDefinition    | 18 +++++
 .../camel/spring/CamelContextFactoryBean.java   |  2 +
 .../spring/handler/CamelNamespaceHandler.java   |  2 +
 14 files changed, 492 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/1019bb16/camel-core/src/main/java/org/apache/camel/model/remote/DnsConfigurationDefinition.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/model/remote/DnsConfigurationDefinition.java
b/camel-core/src/main/java/org/apache/camel/model/remote/DnsConfigurationDefinition.java
new file mode 100644
index 0000000..9af18a3
--- /dev/null
+++ b/camel-core/src/main/java/org/apache/camel/model/remote/DnsConfigurationDefinition.java
@@ -0,0 +1,82 @@
+/**
+ * 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.model.remote;
+
+import javax.xml.bind.annotation.XmlAccessType;
+import javax.xml.bind.annotation.XmlAccessorType;
+import javax.xml.bind.annotation.XmlAttribute;
+import javax.xml.bind.annotation.XmlRootElement;
+
+import org.apache.camel.spi.Metadata;
+
+/**
+ * DNS remote service call configuration
+ */
+@Metadata(label = "eip,routing,remote")
+@XmlRootElement(name = "dnsConfiguration")
+@XmlAccessorType(XmlAccessType.FIELD)
+public class DnsConfigurationDefinition extends ServiceCallConfigurationDefinition {
+
+    @XmlAttribute @Metadata(defaultValue = "_tcp")
+    String proto = "_tcp";
+
+    @XmlAttribute
+    String domain;
+
+    public DnsConfigurationDefinition() {
+    }
+
+    public DnsConfigurationDefinition(ServiceCallDefinition parent) {
+        super(parent);
+    }
+
+    // -------------------------------------------------------------------------
+    // Getter/Setter
+    // -------------------------------------------------------------------------
+
+    public String getProto() {
+        return proto;
+    }
+
+    public void setProto(String proto) {
+        this.proto = proto;
+    }
+
+    public String getDomain() {
+        return domain;
+    }
+
+    public void setDomain(String domain) {
+        this.domain = domain;
+    }
+
+
+    // -------------------------------------------------------------------------
+    // Fluent API
+    // -------------------------------------------------------------------------
+
+    public DnsConfigurationDefinition proto(String proto) {
+        setProto(proto);
+        return this;
+    }
+
+    public DnsConfigurationDefinition domain(String domain) {
+        setDomain(domain);
+        return this;
+    }
+}

http://git-wip-us.apache.org/repos/asf/camel/blob/1019bb16/camel-core/src/main/java/org/apache/camel/model/remote/ServiceCallDefinition.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/model/remote/ServiceCallDefinition.java
b/camel-core/src/main/java/org/apache/camel/model/remote/ServiceCallDefinition.java
index a778b96..131f881 100644
--- a/camel-core/src/main/java/org/apache/camel/model/remote/ServiceCallDefinition.java
+++ b/camel-core/src/main/java/org/apache/camel/model/remote/ServiceCallDefinition.java
@@ -143,6 +143,17 @@ public class ServiceCallDefinition extends NoOutputDefinition<ServiceCallDefinit
         serviceCallConfiguration = new EtcdConfigurationDefinition(this);
         return (EtcdConfigurationDefinition) serviceCallConfiguration;
     }
+
+    /**
+     * Configures the Service Call EIP using Dns
+     * <p/>
+     * Use <tt>end</tt> when configuration is complete, to return back to the
Service Call EIP.
+     */
+    public DnsConfigurationDefinition dnsConfiguration() {
+        serviceCallConfiguration = new DnsConfigurationDefinition(this);
+        return (DnsConfigurationDefinition) serviceCallConfiguration;
+    }
+
     /**
      * Configures the ServiceCall using the given configuration
      */

http://git-wip-us.apache.org/repos/asf/camel/blob/1019bb16/camel-core/src/main/resources/org/apache/camel/model/remote/jaxb.index
----------------------------------------------------------------------
diff --git a/camel-core/src/main/resources/org/apache/camel/model/remote/jaxb.index b/camel-core/src/main/resources/org/apache/camel/model/remote/jaxb.index
index 8100bd3..0b919fe 100644
--- a/camel-core/src/main/resources/org/apache/camel/model/remote/jaxb.index
+++ b/camel-core/src/main/resources/org/apache/camel/model/remote/jaxb.index
@@ -15,6 +15,7 @@
 ## limitations under the License.
 ## ------------------------------------------------------------------------
 ConsulConfigurationDefinition
+DnsConfigurationDefinition
 EtcdConfigurationDefinition
 KubernetesConfigurationDefinition
 RibbonConfigurationDefinition

http://git-wip-us.apache.org/repos/asf/camel/blob/1019bb16/components/camel-blueprint/src/main/java/org/apache/camel/blueprint/CamelContextFactoryBean.java
----------------------------------------------------------------------
diff --git a/components/camel-blueprint/src/main/java/org/apache/camel/blueprint/CamelContextFactoryBean.java
b/components/camel-blueprint/src/main/java/org/apache/camel/blueprint/CamelContextFactoryBean.java
index dda9a98..be8a6af 100644
--- a/components/camel-blueprint/src/main/java/org/apache/camel/blueprint/CamelContextFactoryBean.java
+++ b/components/camel-blueprint/src/main/java/org/apache/camel/blueprint/CamelContextFactoryBean.java
@@ -58,6 +58,9 @@ import org.apache.camel.model.RouteContextRefDefinition;
 import org.apache.camel.model.RouteDefinition;
 import org.apache.camel.model.ThreadPoolProfileDefinition;
 import org.apache.camel.model.dataformat.DataFormatsDefinition;
+import org.apache.camel.model.remote.ConsulConfigurationDefinition;
+import org.apache.camel.model.remote.DnsConfigurationDefinition;
+import org.apache.camel.model.remote.EtcdConfigurationDefinition;
 import org.apache.camel.model.remote.KubernetesConfigurationDefinition;
 import org.apache.camel.model.remote.RibbonConfigurationDefinition;
 import org.apache.camel.model.rest.RestConfigurationDefinition;
@@ -146,8 +149,9 @@ public class CamelContextFactoryBean extends AbstractCamelContextFactoryBean<Blu
         @XmlElement(name = "hystrixConfiguration", type = HystrixConfigurationDefinition.class,
required = false),
         @XmlElement(name = "kubernetesConfiguration", type = KubernetesConfigurationDefinition.class,
required = false),
         @XmlElement(name = "ribbonConfiguration", type = RibbonConfigurationDefinition.class,
required = false),
-        @XmlElement(name = "consulConfiguration", type = RibbonConfigurationDefinition.class,
required = false),
-        @XmlElement(name = "etcdConfiguration", type = RibbonConfigurationDefinition.class,
required = false),
+        @XmlElement(name = "consulConfiguration", type = ConsulConfigurationDefinition.class,
required = false),
+        @XmlElement(name = "dnsConfiguration", type = DnsConfigurationDefinition.class, required
= false),
+        @XmlElement(name = "etcdConfiguration", type = EtcdConfigurationDefinition.class,
required = false),
         @XmlElement(name = "template", type = CamelProducerTemplateFactoryBean.class, required
= false),
         @XmlElement(name = "consumerTemplate", type = CamelConsumerTemplateFactoryBean.class,
required = false),
         @XmlElement(name = "proxy", type = CamelProxyFactoryBean.class, required = false),

http://git-wip-us.apache.org/repos/asf/camel/blob/1019bb16/components/camel-dns/src/main/java/org/apache/camel/component/dns/DnsConfiguration.java
----------------------------------------------------------------------
diff --git a/components/camel-dns/src/main/java/org/apache/camel/component/dns/DnsConfiguration.java
b/components/camel-dns/src/main/java/org/apache/camel/component/dns/DnsConfiguration.java
new file mode 100644
index 0000000..3b5b41c
--- /dev/null
+++ b/components/camel-dns/src/main/java/org/apache/camel/component/dns/DnsConfiguration.java
@@ -0,0 +1,52 @@
+/**
+ * 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.dns;
+
+
+import org.apache.camel.spi.UriParam;
+import org.apache.camel.spi.UriParams;
+
+@UriParams
+public class DnsConfiguration {
+    @UriParam(defaultValue = "_tcp")
+    String proto = "_tcp";
+
+    @UriParam
+    String domain;
+
+    public String getProto() {
+        return proto;
+    }
+
+    /**
+     * The transport protocol of the desired service.
+     */
+    public void setProto(String proto) {
+        this.proto = proto;
+    }
+
+    public String getDomain() {
+        return domain;
+    }
+
+    /**
+     * The domain name;
+     */
+    public void setDomain(String domain) {
+        this.domain = domain;
+    }
+}

http://git-wip-us.apache.org/repos/asf/camel/blob/1019bb16/components/camel-dns/src/main/java/org/apache/camel/component/dns/processor/remote/DnsServiceCallProcessor.java
----------------------------------------------------------------------
diff --git a/components/camel-dns/src/main/java/org/apache/camel/component/dns/processor/remote/DnsServiceCallProcessor.java
b/components/camel-dns/src/main/java/org/apache/camel/component/dns/processor/remote/DnsServiceCallProcessor.java
new file mode 100644
index 0000000..f469428
--- /dev/null
+++ b/components/camel-dns/src/main/java/org/apache/camel/component/dns/processor/remote/DnsServiceCallProcessor.java
@@ -0,0 +1,42 @@
+/**
+ * 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.dns.processor.remote;
+
+import org.apache.camel.ExchangePattern;
+import org.apache.camel.component.dns.DnsConfiguration;
+import org.apache.camel.impl.remote.DefaultServiceCallProcessor;
+import org.apache.camel.spi.ServiceCallServer;
+import org.apache.camel.spi.ServiceCallServerListStrategy;
+
+/**
+ * @author lburgazzoli
+ */
+public class DnsServiceCallProcessor extends DefaultServiceCallProcessor<ServiceCallServer>
{
+    public DnsServiceCallProcessor(String name, String scheme, String uri, ExchangePattern
exchangePattern, DnsConfiguration conf) {
+        super(name, scheme, uri, exchangePattern);
+    }
+
+    @Override
+    public void setServerListStrategy(ServiceCallServerListStrategy<ServiceCallServer>
serverListStrategy) {
+        if (!(serverListStrategy instanceof DnsServiceCallServerListStrategy)) {
+            throw new IllegalArgumentException("ServerListStrategy is not an instance of
DnsServiceCallServerListStrategy");
+        }
+
+        super.setServerListStrategy(serverListStrategy);
+    }
+}

http://git-wip-us.apache.org/repos/asf/camel/blob/1019bb16/components/camel-dns/src/main/java/org/apache/camel/component/dns/processor/remote/DnsServiceCallProcessorFactory.java
----------------------------------------------------------------------
diff --git a/components/camel-dns/src/main/java/org/apache/camel/component/dns/processor/remote/DnsServiceCallProcessorFactory.java
b/components/camel-dns/src/main/java/org/apache/camel/component/dns/processor/remote/DnsServiceCallProcessorFactory.java
new file mode 100644
index 0000000..6c285a6
--- /dev/null
+++ b/components/camel-dns/src/main/java/org/apache/camel/component/dns/processor/remote/DnsServiceCallProcessorFactory.java
@@ -0,0 +1,68 @@
+/**
+ * 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.dns.processor.remote;
+
+import java.util.Map;
+import java.util.Optional;
+
+import org.apache.camel.ExchangePattern;
+import org.apache.camel.component.dns.DnsConfiguration;
+import org.apache.camel.impl.remote.DefaultServiceCallProcessor;
+import org.apache.camel.impl.remote.DefaultServiceCallProcessorFactory;
+import org.apache.camel.spi.ProcessorFactory;
+import org.apache.camel.spi.RouteContext;
+import org.apache.camel.spi.ServiceCallServer;
+import org.apache.camel.spi.ServiceCallServerListStrategy;
+import org.apache.camel.util.ObjectHelper;
+
+/**
+ * {@link ProcessorFactory} that creates the Etcd implementation of the ServiceCall EIP.
+ */
+public class DnsServiceCallProcessorFactory extends DefaultServiceCallProcessorFactory<DnsConfiguration,
ServiceCallServer> {
+    @Override
+    protected DnsConfiguration createConfiguration(RouteContext routeContext) throws Exception
{
+        return new DnsConfiguration();
+    }
+
+    @Override
+    protected DefaultServiceCallProcessor createProcessor(
+            String name,
+            String component,
+            String uri,
+            ExchangePattern mep,
+            DnsConfiguration conf,
+            Map<String, String> properties) throws Exception {
+
+        return new DnsServiceCallProcessor(name, component, uri, mep, conf);
+    }
+
+    @Override
+    protected Optional<ServiceCallServerListStrategy> builtInServerListStrategy(DnsConfiguration
conf, String name) throws Exception {
+        ServiceCallServerListStrategy strategy = null;
+        if (ObjectHelper.equal("ondemand", name, true)) {
+            strategy = new DnsServiceCallServerListStrategies.OnDemand(conf);
+        }
+
+        return Optional.ofNullable(strategy);
+    }
+
+    @Override
+    protected ServiceCallServerListStrategy<ServiceCallServer> createDefaultServerListStrategy(DnsConfiguration
conf) throws Exception {
+        return new DnsServiceCallServerListStrategies.OnDemand(conf);
+    }
+}

http://git-wip-us.apache.org/repos/asf/camel/blob/1019bb16/components/camel-dns/src/main/java/org/apache/camel/component/dns/processor/remote/DnsServiceCallServer.java
----------------------------------------------------------------------
diff --git a/components/camel-dns/src/main/java/org/apache/camel/component/dns/processor/remote/DnsServiceCallServer.java
b/components/camel-dns/src/main/java/org/apache/camel/component/dns/processor/remote/DnsServiceCallServer.java
new file mode 100644
index 0000000..11fe753
--- /dev/null
+++ b/components/camel-dns/src/main/java/org/apache/camel/component/dns/processor/remote/DnsServiceCallServer.java
@@ -0,0 +1,37 @@
+/**
+ * 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.dns.processor.remote;
+
+import java.util.Comparator;
+
+import org.apache.camel.impl.remote.DefaultServiceCallServer;
+import org.xbill.DNS.SRVRecord;
+
+public class DnsServiceCallServer extends DefaultServiceCallServer {
+    public static final Comparator<SRVRecord> COMPARATOR = comparator();
+
+    public DnsServiceCallServer(SRVRecord record) {
+        super(record.getTarget().toString(true), record.getPort());
+    }
+
+    public static Comparator<SRVRecord> comparator() {
+        Comparator<SRVRecord> byPriority = (e1, e2) -> Integer.compare(e2.getPriority(),
e1.getPriority());
+        Comparator<SRVRecord> byWeight = (e1, e2) -> Integer.compare(e2.getWeight(),
e1.getWeight());
+
+        return byPriority.thenComparing(byWeight);
+    }
+}

http://git-wip-us.apache.org/repos/asf/camel/blob/1019bb16/components/camel-dns/src/main/java/org/apache/camel/component/dns/processor/remote/DnsServiceCallServerListStrategies.java
----------------------------------------------------------------------
diff --git a/components/camel-dns/src/main/java/org/apache/camel/component/dns/processor/remote/DnsServiceCallServerListStrategies.java
b/components/camel-dns/src/main/java/org/apache/camel/component/dns/processor/remote/DnsServiceCallServerListStrategies.java
new file mode 100644
index 0000000..e69ff17
--- /dev/null
+++ b/components/camel-dns/src/main/java/org/apache/camel/component/dns/processor/remote/DnsServiceCallServerListStrategies.java
@@ -0,0 +1,77 @@
+/**
+ * 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.dns.processor.remote;
+
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.List;
+import java.util.Objects;
+import java.util.stream.Collectors;
+
+import org.apache.camel.component.dns.DnsConfiguration;
+import org.apache.camel.spi.ServiceCallServer;
+import org.xbill.DNS.Lookup;
+import org.xbill.DNS.Record;
+import org.xbill.DNS.SRVRecord;
+
+
+public final class DnsServiceCallServerListStrategies {
+    private DnsServiceCallServerListStrategies() {
+    }
+
+    public static final class OnDemand extends DnsServiceCallServerListStrategy {
+        private final DnsServiceLookupFactory lookupFactory;
+
+        public OnDemand(DnsConfiguration configuration) throws Exception {
+            super(configuration);
+            this.lookupFactory = new DnsServiceLookupFactory(configuration);
+        }
+
+        @Override
+        public List<ServiceCallServer> getUpdatedListOfServers(String name) {
+            final Lookup lookup = lookupFactory.apply(name);
+            final Record[] records = lookup.run();
+
+            List<ServiceCallServer> servers;
+            if (Objects.nonNull(records) && lookup.getResult() == Lookup.SUCCESSFUL)
{
+                servers = Arrays.stream(records)
+                    .filter(SRVRecord.class::isInstance)
+                    .map(SRVRecord.class::cast)
+                    .sorted(DnsServiceCallServer.COMPARATOR)
+                    .map(DnsServiceCallServer::new)
+                    .collect(Collectors.toList());
+            } else {
+                servers = Collections.emptyList();
+            }
+
+            return servers;
+        }
+
+        @Override
+        public String toString() {
+            return "OnDemand";
+        }
+    }
+
+    // *************************************************************************
+    // Helpers
+    // *************************************************************************
+
+    public static DnsServiceCallServerListStrategy onDemand(DnsConfiguration configuration)
throws Exception {
+        return new OnDemand(configuration);
+    }
+}

http://git-wip-us.apache.org/repos/asf/camel/blob/1019bb16/components/camel-dns/src/main/java/org/apache/camel/component/dns/processor/remote/DnsServiceCallServerListStrategy.java
----------------------------------------------------------------------
diff --git a/components/camel-dns/src/main/java/org/apache/camel/component/dns/processor/remote/DnsServiceCallServerListStrategy.java
b/components/camel-dns/src/main/java/org/apache/camel/component/dns/processor/remote/DnsServiceCallServerListStrategy.java
new file mode 100644
index 0000000..a58852b
--- /dev/null
+++ b/components/camel-dns/src/main/java/org/apache/camel/component/dns/processor/remote/DnsServiceCallServerListStrategy.java
@@ -0,0 +1,35 @@
+/**
+ * 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.dns.processor.remote;
+
+import org.apache.camel.component.dns.DnsConfiguration;
+import org.apache.camel.impl.remote.DefaultServiceCallServerListStrategy;
+import org.apache.camel.spi.ServiceCallServer;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class DnsServiceCallServerListStrategy extends DefaultServiceCallServerListStrategy<ServiceCallServer>
{
+    private final DnsConfiguration configuration;
+
+    public DnsServiceCallServerListStrategy(DnsConfiguration configuration) {
+        this.configuration = configuration;
+    }
+
+    protected DnsConfiguration getConfiguration() {
+        return configuration;
+    }
+}

http://git-wip-us.apache.org/repos/asf/camel/blob/1019bb16/components/camel-dns/src/main/java/org/apache/camel/component/dns/processor/remote/DnsServiceLookupFactory.java
----------------------------------------------------------------------
diff --git a/components/camel-dns/src/main/java/org/apache/camel/component/dns/processor/remote/DnsServiceLookupFactory.java
b/components/camel-dns/src/main/java/org/apache/camel/component/dns/processor/remote/DnsServiceLookupFactory.java
new file mode 100644
index 0000000..49d6b21
--- /dev/null
+++ b/components/camel-dns/src/main/java/org/apache/camel/component/dns/processor/remote/DnsServiceLookupFactory.java
@@ -0,0 +1,59 @@
+/**
+ * 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.dns.processor.remote;
+
+import java.util.Map;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.function.Function;
+
+import org.apache.camel.RuntimeCamelException;
+import org.apache.camel.component.dns.DnsConfiguration;
+import org.xbill.DNS.Lookup;
+import org.xbill.DNS.TextParseException;
+import org.xbill.DNS.Type;
+
+public class DnsServiceLookupFactory implements Function<String, Lookup> {
+    private final DnsConfiguration configuration;
+    private final Map<String, Lookup> cache;
+
+    public  DnsServiceLookupFactory(DnsConfiguration configuration) {
+        this.configuration = configuration;
+        cache = new ConcurrentHashMap<>();
+    }
+
+    @Override
+    public Lookup apply(String name) {
+        Lookup lookup = cache.get(name);
+        if (lookup == null) {
+            synchronized (cache) {
+                lookup = cache.computeIfAbsent(name, this::createLookup);
+            }
+        }
+
+        return lookup;
+    }
+
+    private Lookup createLookup(String name) {
+        try {
+            return new Lookup(
+                String.format("%s.%s.%s", name, configuration.getProto(), configuration.getDomain()),
+                Type.SRV);
+        } catch (TextParseException e) {
+            throw new RuntimeCamelException(e);
+        }
+    }
+}

http://git-wip-us.apache.org/repos/asf/camel/blob/1019bb16/components/camel-dns/src/main/resources/META-INF/services/org/apache/camel/model/ServiceCallDefinition
----------------------------------------------------------------------
diff --git a/components/camel-dns/src/main/resources/META-INF/services/org/apache/camel/model/ServiceCallDefinition
b/components/camel-dns/src/main/resources/META-INF/services/org/apache/camel/model/ServiceCallDefinition
new file mode 100644
index 0000000..d0bd19b
--- /dev/null
+++ b/components/camel-dns/src/main/resources/META-INF/services/org/apache/camel/model/ServiceCallDefinition
@@ -0,0 +1,18 @@
+#
+# 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.dns.processor.remote.DnsServiceCallProcessorFactory

http://git-wip-us.apache.org/repos/asf/camel/blob/1019bb16/components/camel-spring/src/main/java/org/apache/camel/spring/CamelContextFactoryBean.java
----------------------------------------------------------------------
diff --git a/components/camel-spring/src/main/java/org/apache/camel/spring/CamelContextFactoryBean.java
b/components/camel-spring/src/main/java/org/apache/camel/spring/CamelContextFactoryBean.java
index 7527881..a9da06b 100644
--- a/components/camel-spring/src/main/java/org/apache/camel/spring/CamelContextFactoryBean.java
+++ b/components/camel-spring/src/main/java/org/apache/camel/spring/CamelContextFactoryBean.java
@@ -57,6 +57,7 @@ import org.apache.camel.model.RouteDefinition;
 import org.apache.camel.model.ThreadPoolProfileDefinition;
 import org.apache.camel.model.dataformat.DataFormatsDefinition;
 import org.apache.camel.model.remote.ConsulConfigurationDefinition;
+import org.apache.camel.model.remote.DnsConfigurationDefinition;
 import org.apache.camel.model.remote.EtcdConfigurationDefinition;
 import org.apache.camel.model.remote.KubernetesConfigurationDefinition;
 import org.apache.camel.model.remote.RibbonConfigurationDefinition;
@@ -156,6 +157,7 @@ public class CamelContextFactoryBean extends AbstractCamelContextFactoryBean<Spr
     @XmlElements({
             @XmlElement(name = "hystrixConfiguration", type = HystrixConfigurationDefinition.class,
required = false),
             @XmlElement(name = "consulConfiguration", type = ConsulConfigurationDefinition.class,
required = false),
+            @XmlElement(name = "dnsConfiguration", type = DnsConfigurationDefinition.class,
required = false),
             @XmlElement(name = "etcdConfiguration", type = EtcdConfigurationDefinition.class,
required = false),
             @XmlElement(name = "kubernetesConfiguration", type = KubernetesConfigurationDefinition.class,
required = false),
             @XmlElement(name = "ribbonConfiguration", type = RibbonConfigurationDefinition.class,
required = false),

http://git-wip-us.apache.org/repos/asf/camel/blob/1019bb16/components/camel-spring/src/main/java/org/apache/camel/spring/handler/CamelNamespaceHandler.java
----------------------------------------------------------------------
diff --git a/components/camel-spring/src/main/java/org/apache/camel/spring/handler/CamelNamespaceHandler.java
b/components/camel-spring/src/main/java/org/apache/camel/spring/handler/CamelNamespaceHandler.java
index eae9f61..01c6246 100644
--- a/components/camel-spring/src/main/java/org/apache/camel/spring/handler/CamelNamespaceHandler.java
+++ b/components/camel-spring/src/main/java/org/apache/camel/spring/handler/CamelNamespaceHandler.java
@@ -34,6 +34,7 @@ import org.apache.camel.model.FromDefinition;
 import org.apache.camel.model.HystrixConfigurationDefinition;
 import org.apache.camel.model.SendDefinition;
 import org.apache.camel.model.remote.ConsulConfigurationDefinition;
+import org.apache.camel.model.remote.DnsConfigurationDefinition;
 import org.apache.camel.model.remote.EtcdConfigurationDefinition;
 import org.apache.camel.model.remote.KubernetesConfigurationDefinition;
 import org.apache.camel.model.remote.RibbonConfigurationDefinition;
@@ -147,6 +148,7 @@ public class CamelNamespaceHandler extends NamespaceHandlerSupport {
         addBeanDefinitionParser("propertyPlaceholder", CamelPropertyPlaceholderDefinition.class,
false, false);
         addBeanDefinitionParser("hystrixConfiguration", HystrixConfigurationDefinition.class,
false, false);
         addBeanDefinitionParser("consulConfiguration", ConsulConfigurationDefinition.class,
false, false);
+        addBeanDefinitionParser("dnsConfiguration", DnsConfigurationDefinition.class, false,
false);
         addBeanDefinitionParser("etcdConfiguration", EtcdConfigurationDefinition.class, false,
false);
         addBeanDefinitionParser("kubernetesConfiguration", KubernetesConfigurationDefinition.class,
false, false);
         addBeanDefinitionParser("ribbonConfiguration", RibbonConfigurationDefinition.class,
false, false);


Mime
View raw message