Show Table of Contents
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&period=5000"/> <setHeader headerName="CamelInfinispanKey"> <property>CamelTimerCounter</property> </setHeader> <setHeader headerName="CamelInfinispanValue"> <property>CamelTimerCounter</property> </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.

Where did the comment section go?
Red Hat's documentation publication system recently went through an upgrade to enable speedier, more mobile-friendly content. We decided to re-evaluate our commenting platform to ensure that it meets your expectations and serves as an optimal feedback mechanism. During this redesign, we invite your input on providing feedback on Red Hat documentation via the discussion platform.