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">
			<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.
Red Hat logoGithubRedditYoutubeTwitter

Learn

Try, buy, & sell

Communities

About Red Hat Documentation

We help Red Hat users innovate and achieve their goals with our products and services with content they can trust.

Making open source more inclusive

Red Hat is committed to replacing problematic language in our code, documentation, and web properties. For more details, see the Red Hat Blog.

About Red Hat

We deliver hardened solutions that make it easier for enterprises to work across platforms and environments, from the core datacenter to the network edge.

© 2024 Red Hat, Inc.