Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Code Block
from("direct:put")
.setHeader(HazelcastConstants.OPERATION, constant(HazelcastConstants.PUT_OPERATION))	
.toF("hazelcast:%sfoo", HazelcastConstants.MAP_PREFIX);

...

Code Block
<route>
	<from uri="direct:put" />
	<setHeader headerName="hazelcast.operation.type">
		<constant>put</constant>
	</setHeader>
	<to uri="hazelcast:map:foo" />
</route>

Starting Camel version 2.8

Code Block

<route>
	<from uri="direct:put" /        <!-- If using version 2.8 and above set headerName to "CamelHazelcastOperationType" -->
	<setHeader headerName="CamelHazelcastOperationTypehazelcast.operation.type">
		<constant>put</constant>
	</setHeader>
	<to uri="hazelcast:map:foo" />
</route>

...

Code Block
from("direct:get")
.setHeader(HazelcastConstants.OPERATION, constant(HazelcastConstants.GET_OPERATION))	
.toF("hazelcast:%sfoo", HazelcastConstants.MAP_PREFIX)
.to("seda:out");

...

Code Block
<route>
	<from uri="direct:get" />
	<setHeader         <!-- If using version 2.8 and above set headerName to "CamelHazelcastOperationType" -->
	<setHeader headerName="hazelcast.operation.type">
		<constant>get</constant>
	</setHeader>
	<to uri="hazelcast:map:foo" />
	<to uri="seda:out" />
</route>
Sample for update:

Java DSL:Starting Camel version 2.8

Code Block
<route>
	<from uri=from("direct:getupdate" />
	<setHeader headerName="CamelHazelcastOperationType">
		<constant>get</constant>
	</setHeader>
	<to uri="hazelcast:map:foo" />
	<to uri="seda:out" />
</route>
Sample for update:

Java DSL:

Code Block

from("direct:update")
.setHeader(HazelcastConstants.OPERATION, constant(HazelcastConstants.UPDATE_OPERATION))
.)
.setHeader(HazelcastConstants.OPERATION, constant(HazelcastConstants.UPDATE_OPERATION))
.toF("hazelcast:%sfoo", HazelcastConstants.MAP_PREFIX);

...

Code Block
<route>
	<from uri="direct:update" />
	<setHeader headerName="hazelcast.operation.type">
		<constant>update</constant>
	</setHeader>
	<to uri="hazelcast:map:foo" />
</route>

Starting Camel version 2.8

Code Block

<route>
	<from uri="direct:update" /        <!-- If using version 2.8 and above set headerName to "CamelHazelcastOperationType" -->
	<setHeader headerName="CamelHazelcastOperationTypehazelcast.operation.type">
		<constant>update</constant>
	</setHeader>
	<to uri="hazelcast:map:foo" />
</route>

...

Code Block
<route>
	<from uri="direct:delete" />
	<setHeader headerName="hazelcast.operation.type">
		<constant>delete</constant>
	</setHeader>
	<to uri="hazelcast:map:foo" />
</route>

Starting Camel version 2.8

Code Block

<route>
	<from uri="direct:delete" /        <!-- If using version 2.8 and above set headerName to "CamelHazelcastOperationType" -->
	<setHeader headerName="CamelHazelcastOperationTypehazelcast.operation.type">
		<constant>delete</constant>
	</setHeader>
	<to uri="hazelcast:map:foo" />
</route>

...

Code Block
<route>
	<from uri="direct:query" />
	<setHeader headerName="hazelcast.operation.type">
		<constant>query</constant>
	</setHeader>
	<to uri="hazelcast:map:foo" />
	<to uri="seda:out" />
</route>

Starting Camel version 2.8

Code Block

<route>
	<from uri="direct:query" /        <!-- If using version 2.8 and above set headerName to "CamelHazelcastOperationType" -->
	<setHeader headerName="CamelHazelcastOperationTypehazelcast.operation.type">
		<constant>query</constant>
	</setHeader>
	<to uri="hazelcast:map:foo" />
	<to uri="seda:out" />
</route>

...

multimap cache producer - to("hazelcast:multimap:foo")

A multimap is a cache where you can store n values to one key. The multimap producer provides 4 operations (put, get, removevalue, delete).

Header Variables for the request message:

Name

Type

Description

hazelcast.operation.type

String

valid values are: put, get, removevalue, delete

hazelcast.objectId

String

the object id to store / find your object inside the cache

Warning

Header variables have changed in Camel 2.8

Hazelcast Component

Available as of Camel 2.7

The hazelcast: component allows you to work with the Hazelcast distributed data grid / cache. Hazelcast is a in memory data grid, entirely written in Java (single jar). It offers a great palette of different data stores like map, multi map (same key, n values), queue, list and atomic number. The main reason to use Hazelcast is its simple cluster support. If you have enabled multicast on your network you can run a cluster with hundred nodes with no extra configuration. Hazelcast can simply configured to add additional features like n copies between nodes (default is 1), cache persistence, network configuration (if needed), near cache, enviction and so on. For more information consult the Hazelcast documentation on http://www.hazelcast.com/documentation.jsp.

Maven users will need to add the following dependency to their pom.xml for this component:

...


<dependency>
    <groupId>org.apache.camel</groupId>
    <artifactId>camel-hazelcast</artifactId>
    <version>x.x.x</version>
    <!-- use the same version as your Camel core version -->
</dependency>

URI format

Code Block

hazelcast:[ map | multimap | queue | seda | set | atomicvalue | instance]:cachename[?options]
Warning

You have to use the second prefix to define which type of data store you want to use.

Sections

  1. Usage of #map
  2. Usage of #multimap
  3. Usage of #queue
  4. Usage of #list
  5. Usage of #seda
  6. Usage of atomic number
  7. Usage of #cluster support (instance)

...

Usage of Map

map cache producer - to("hazelcast:map:foo")

If you want to store a value in a map you can use the map cache producer. The map cache producer provides 5 multimap is a cache where you can store n values to one key. The multimap producer provides 4 operations (put, get, updateremovevalue, delete, query). For the first 4 you have to provide the operation inside the "hazelcast.operation.type" header variable. In Java DSL you can use the constants from org.apache.camel.component.hazelcast.HazelcastConstants.

Header Variables for the request message:

Name

Type

Description

hazelcast.operation.type

String

valid values are: put, delete, get, updateremovevalue, query delete

hazelcast.objectId

String

the object id to store / find your object inside the cache (not needed for the query operation)

Warning

Header variables have changed in Camel 2.8

...

Code Block
from("direct:put")
.setHeader(HazelcastConstants.OPERATION, constant(HazelcastConstants.PUT_OPERATION))	
.toF("hazelcast:%sfoo", HazelcastConstants.MAP_PREFIX);

...

Code Block
from("direct:get")
.setHeader(HazelcastConstants.OPERATION, constant(HazelcastConstants.GET_OPERATION))	
.toF("hazelcast:%sfoo", HazelcastConstants.MAP_PREFIX)
.to("seda:out");

...

Code Block
from("direct:delete")
.setHeader(HazelcastConstants.OPERATION, constant(HazelcastConstants.DELETE_OPERATION))
.toF("hazelcast:%sbar", HazelcastConstants.MULTIMAP_PREFIX); 

Spring DSL:

Code Block
<route>
	<from uri="direct:delete" />
	<log message="delete.."/>
        <!-- If using version 2.8 and above set headerName to "CamelHazelcastOperationType" -->
	<setHeader headerName="hazelcast.operation.type">
		<constant>delete</constant>
	</setHeader>
	<to uri="hazelcast:multimap:foo" />
</route>

...

Warning

Header variables have changed in Camel 2.8

Name

Type

Description

hazelcast.operation.type CamelHazelcastOperationType

String

valid values are: setvalue, get, increase, decrease, destroy Available as of Camel version 2.8

...

Code Block
from("direct:increment")
.setHeader(HazelcastConstants.OPERATION, constant(HazelcastConstants.INCREMENT_OPERATION))
.toF("hazelcast:%sfoo", HazelcastConstants.ATOMICNUMBER_PREFIX); 

Spring DSL:

Code Block
<route>
	<from uri="direct:increment" />
        <!-- If using version 2.8 and above set headerName to "CamelHazelcastOperationType" -->
	<setHeader headerName="hazelcast.operation.type">
		<constant>increment</constant>
	</setHeader>
	<to uri="hazelcast:atomicvalue:foo" />
</route>

...