This Confluence has been LDAP enabled, if you are an ASF Committer, please use your LDAP Credentials to login. Any problems file an INFRA jira ticket please.

Child pages
  • Spring XQuery Example
Skip to end of metadata
Go to start of metadata

Spring XQuery Example

The Spring XQuery example uses no Java code; its configured purely using a Spring XML configuration file. It parsers some files from a directory, transforms them using XQuery then sends them to a message queue. To make it easy to look at the generated files, we also have another route which consumes from the JMS queue and writes them to an output directory.

Running the example

To run the example we use the Camel Maven Plugin.

For example from the source or binary distribution the following should work

cd examples/camel-example-spring-xquery
mvn camel:run

You should now see the generated files in the target/outputFiles directory which are the transformed messages read from the JMS queue.

Code walk through

What this does is boot up the Spring ApplicationContext defined in the file META-INF/spring/camelContext.xml on the classpath. This is a regular Spring XML document which uses the Camel Xml Configuration to configure a CamelContext.

Also note at the end of this XML example file we explicitly configure the ActiveMQ component with details of how to connect to the broker.

The main part of the Spring XML file is here...

Error rendering macro 'code': Invalid value specified for parameter 'java.lang.NullPointerException'
<camelContext xmlns="">

  <!-- lets parse files, transform them with XQuery and send them to JMS -->
    <from uri="file:src/data?noop=true"/>
    <log message="Transforming input file ${header.CamelFileName}"/>
    <to uri="xquery:myTransform.xquery"/>
    <to uri="jms:MyQueue"/>

  <!-- now lets write messages from the queue to a directory -->
    <from uri="jms:MyQueue"/>
    <log message="Writing output file ${header.CamelFileName}"/>
    <to uri="file:target/outputFiles"/>


<!-- lets configure the default ActiveMQ broker URL -->
<bean id="jms" class="org.apache.camel.component.jms.JmsComponent">
  <property name="connectionFactory">
    <bean class="org.apache.activemq.ActiveMQConnectionFactory">
      <property name="brokerURL" value="vm://localhost?broker.persistent=false"/>
  • No labels