5.2. Routing with Camel in JBoss Data Grid

Camel routing is a chain of processors that move messages in the background. The following is an example of a route that retrieves a value from the cache for a specific key.
from("direct:start")
    .setHeader(InfinispanConstants.OPERATION, constant(InfinispanConstants.GET))
    .setHeader(InfinispanConstants.KEY, constant("123"))
    .to("infinispan://localhost?cacheContainer=#cacheContainer");
Routing can also be performed using XML configuration. The following example demonstrates camel-jbossdatagrid's local-camel-producer, a camel route that uses the camel-jbossdatagrid component to send data to an embedded cache created by the local-cache module.
<camelContext id="local-producer" xmlns="http://camel.apache.org/schema/blueprint">
    <route>
        <from uri="timer://local?fixedRate=true&amp;period=5000"/>
        <setHeader headerName="CamelInfinispanKey">
            <constant>CamelTimerCounter</constant>
        </setHeader>
        <setHeader headerName="CamelInfinispanValue">
            <constant>CamelTimerCounter</constant>
        </setHeader>
        <to uri="infinispan://foo?cacheContainer=#cacheManager"/>
        <to uri="log:local-put?showAll=true"/>
    </route>
</camelContext>
The provided example requires the cacheManager to be instantiated.
The cacheManager bean for Spring XML can be instantiated as follows:
<bean id="cacheManager" class="org.infinispan.manager.DefaultCacheManager" init-method="start" destroy-method="stop">
    <constructor-arg type="java.lang.String" value="infinispan.xml"/>
</bean>
The following demonstrates how to instantiate the cacheManager bean using Blueprint XML.
<bean id="cacheManager" class="org.infinispan.manager.DefaultCacheManager" init-method="start" destroy-method="stop">
    <argument value="infinispan.xml" />
</bean>

Note

Both the Spring XML and Blueprint XML examples use the configuration file infinispan.xml for configuration of the cache. This file must be present on the classpath.