= Defining Camel routes

Camel Quarkus supports several domain specific languages (DSLs) to define Camel Routes.

== Java DSL

Extending `org.apache.camel.builder.RouteBuilder` and using the fluent builder methods available there
is the most common way of defining Camel Routes.
Here is an example from the https://github.com/apache/camel-quarkus-examples/tree/main/timer-log[timer-log] quicksstart:

[source,java]
----
import org.apache.camel.builder.RouteBuilder;

public class TimerRoute extends RouteBuilder {

    @Override
    public void configure() throws Exception {
        from("timer:foo?period=1000")
                .log("Hello World");
    }
}
----

=== Endpoint DSL

Since Camel 3.0, you can use fluent builders also for defining Camel endpoints.
The following is equivalent with the previous example:

[source,java]
----
import org.apache.camel.builder.RouteBuilder;
import static org.apache.camel.builder.endpoint.StaticEndpointBuilders.timer;

public class TimerRoute extends RouteBuilder {

    @Override
    public void configure() throws Exception {
        from(timer("foo").period(1000))
                .log("Hello World");
    }
}
----

[NOTE]
====
Builder methods for all Camel components are available via `camel-quarkus-core`,
but you still need to add the given component's extension as a dependency for the route to work properly.
In case of the above example, it would be `camel-quarkus-timer`.
====

== XML DSL

In order to configure Camel routes, rests or templates in XML, you must add a Camel XML parser dependency to the classpath.
Since Camel Quarkus 1.8.0, `xref:reference/extensions/xml-io-dsl.adoc[camel-quarkus-xml-io-dsl]` is the best choice.

With Camel Main, you can set a property that points to the location of resources XML files such as routes, xref:manual::rest-dsl.adoc[REST DSL] and xref:manual::route-template.adoc[Route templates]:

[source,properties]
----
camel.main.routes-include-pattern = routes/routes.xml, file:src/main/routes/rests.xml, file:src/main/rests/route-template.xml
----

[NOTE]
====
Path globbing like `camel.main.routes-include-pattern = *./routes.xml` currently does not work in native mode.
====


.Route
[source,xml]
----
<routes xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xmlns="http://camel.apache.org/schema/spring"
        xsi:schemaLocation="
            http://camel.apache.org/schema/spring
            http://camel.apache.org/schema/spring/camel-spring.xsd">

    <route id="xml-route">
        <from uri="timer:from-xml?period=1000"/>
        <log message="Hello XML!"/>
    </route>

</routes>
----

[WARNING]
====
Spring XML with `<beans>` or Blueprint XML with `<blueprint>` elements are not supported.
====

The route XML should be in the simplified version like:

.Rest DSL
[source,xml]
----
<rests xmlns="http://camel.apache.org/schema/spring">
    <rest id="greeting" path="/greeting">
        <get uri="/hello">
            <setBody>
                <constant>Hello World!</constant>
            </setBody>
        </get>
    </rest>
</rests>
----

.Route Templates
[source,xml]
----
<routeTemplates xmlns="http://camel.apache.org/schema/spring">
    <routeTemplate id="myTemplate">
        <templateParameter name="name"/>
        <templateParameter name="greeting"/>
        <templateParameter name="myPeriod" defaultValue="3s"/>
        <route>
            <from uri="timer:{{name}}?period={{myPeriod}}"/>
            <setBody><simple>{{greeting}} ${body}</simple></setBody>
            <log message="${body}"/>
        </route>
    </routeTemplate>
</routeTemplates>
----

== Other route DSLs

Since Camel Quarkus 1.8.0, you can also use
xref:reference/extensions/java-joor-dsl.adoc[Java jOOR],
xref:reference/extensions/groovy-dsl.adoc[Groovy],
xref:reference/extensions/yaml-dsl.adoc[YAML],
xref:reference/extensions/kotlin-dsl.adoc[Kotlin] or
xref:reference/extensions/js-dsl.adoc[JavaScript] for defining Camel routes.

Except for YAML, these DSLs are supported only in JVM mode, because they load and compile the routes at runtime.

== What's next?

We recommend to continue with xref:user-guide/configuration.adoc[Configuration].
