XML Io Dsl
Since Camel 3.9
xml-io-dsl is the Camel optimized XML DSL with a very fast and low overhead XML parser. The classic XML DSL was loaded via JAXB that is heavy and overhead.
The JAXB parser is generic and can be used for parsing any XML. However, the
xml-io-dsl is a source code generated parser that is Camel specific and can only parse Camel
.xml route files (not classic Spring
<beans> XML files).
If you are using Camel XML DSL then its recommended using
xml-io-dsl instead of
xml-jaxb-dsl. You can use this in all of Camel’s runtime such as Spring Boot, Quarkus, Camel Main, and Camel K etc.
my-route.xml source file:
<routes xmlns="http://camel.apache.org/schema/spring"> <route> <from uri="timer:tick"/> <setBody> <constant>Hello Camel K!</constant> </setBody> <to uri="log:info"/> </route> </routes>
| You can omit the |
Can then be loaded and run with Camel CLI or Camel K.
kamel run my-route.xml
camel run my-route.xml
Since Camel 4.0.0
It is now possible with
xml-io-dsl to declare some beans to be bound to Camel Registry in similar way as with YAML DSL. Beans may be declared in XML and have their properties (also nested) defined. For example:
<camel> <bean name="beanFromProps" type="com.acme.MyBean"> <properties> <property key="field1" value="f1_p" /> <property key="field2" value="f2_p" /> <property key="nested.field1" value="nf1_p" /> <property key="nested.field2" value="nf2_p" /> </properties> </bean> </camel>
While keeping all the benefits of fast XML parser used by
xml-io-dsl, Camel can also process XML elements declared in other XML namespaces and process them separately. With this mechanism it is possible to include XML elements using Spring’s
This brings the flexibility of Spring Beans into Camel Main without actually running any Spring Application Context (or Spring Boot). When elements from Spring namespace are found, they are used to populate and configure an instance of
org.springframework.beans.factory.support.DefaultListableBeanFactory and leverage Spring dependency injection to wire the beans together. These beans are then exposed through normal Camel Registry and may be used by Camel routes.
Here’s an example
camel.xml file, which defines both the routes and beans used (referred to) by the route definition:
<camel> <beans xmlns="http://www.springframework.org/schema/beans"> <bean id="messageString" class="java.lang.String"> <constructor-arg index="0" value="Hello"/> </bean> <bean id="greeter" class="org.apache.camel.main.app.Greeter"> <description>Spring Bean</description> <property name="message"> <bean class="org.apache.camel.main.app.GreeterMessage"> <property name="msg" ref="messageString"/> </bean> </property> </bean> </beans> <route id="my-route"> <from uri="direct:start"/> <bean ref="greeter"/> <to uri="mock:finish"/> </route> </camel>
my-route route is referring to
greeter bean which is defined using Spring
More examples can be found in Camel JBang page.