= DNS Component
:doctitle: DNS
:shortname: dns
:artifactid: camel-dns
:description: Perform DNS queries using DNSJava.
:since: 2.7
:supportlevel: Stable
:tabs-sync-option:
:component-header: Only producer is supported
//Manually maintained attributes
:camel-spring-boot-name: dns

*Since Camel {since}*

*{component-header}*

This is an additional component for Camel to run DNS queries, using
DNSJava. The component is a thin layer on top of
http://www.xbill.org/dnsjava/[DNSJava].
The component offers the following operations:

* `ip`: to resolve a domain by its ip
* `lookup`: to lookup information about the domain
* `dig`: to run DNS queries

[NOTE]
====
*Requires SUN JVM*

The DNSJava library requires running on the SUN JVM.
====

Maven users will need to add the following dependency to their `pom.xml`
for this component:

[source,xml]
----
<dependency>
    <groupId>org.apache.camel</groupId>
    <artifactId>camel-dns</artifactId>
    <version>x.x.x</version>
    <!-- use the same version as your Camel core version -->
</dependency>
----

== URI format

The URI scheme for a DNS component is as follows

-------------------------
dns://operation[?options]
-------------------------


// component-configure options: START

// component-configure options: END

// component options: START
include::partial$component-configure-options.adoc[]
include::partial$component-endpoint-options.adoc[]
// component options: END

// endpoint options: START

// endpoint options: END

// component headers: START
include::partial$component-endpoint-headers.adoc[]
// component headers: END

== Examples

=== IP lookup

[source,xml]
----
<route id="IPCheck">
    <from uri="direct:start"/>
    <to uri="dns:ip"/>
</route>
----

This looks up a domain's IP. For example, _www.example.com_ resolves to
192.0.32.10.

The IP address to lookup must be provided in the header with key `"dns.domain"`.

=== DNS lookup

[source,xml]
----
<route id="IPCheck">
    <from uri="direct:start"/>
    <to uri="dns:lookup"/>
</route>
----

This returns a set of DNS records associated with a domain. +
 The name to lookup must be provided in the header with key
`"dns.name"`.

=== DNS Dig

Dig is a Unix command-line utility to run DNS queries.

[source,xml]
----
<route id="IPCheck">
    <from uri="direct:start"/>
    <to uri="dns:dig"/>
</route>
----

The query must be provided in the header with key `"dns.query"`.


=== Dns Activation Policy

The `DnsActivationPolicy` can be used to dynamically start and stop routes based on dns state.

If you have instances of the same component running in different regions, you can configure a route in each region to activate only if dns is pointing to its region.

For example, you may have an instance in NYC and an instance in SFO. You would configure a service CNAME service.example.com to point to nyc-service.example.com to bring NYC instance up and SFO instance down. When you change the CNAME service.example.com to point to sfo-service.example.com -- nyc instance would stop its routes and sfo will bring its routes up. This allows you to switch regions without restarting actual components.

[source,xml]
----
 <bean id="dnsActivationPolicy" class="org.apache.camel.component.dns.policy.DnsActivationPolicy">
     <property name="hostname" value="service.example.com" />
     <property name="resolvesTo" value="nyc-service.example.com" />
     <property name="ttl" value="60000" />
     <property name="stopRoutesOnException" value="false" />
 </bean>

 <route id="routeId" autoStartup="false" routePolicyRef="dnsActivationPolicy">
 </route>
----


include::spring-boot:partial$starter.adoc[]
