LibraryToggle FramesPrintFeedback

Available as of Fuse Mediation Router 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>
hazelcast:[ map | multimap | queue | seda | set | atomicvalue | instance]:cachename[?options]
[Warning]Warning

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

If you want to store a value in a map you can use the map cache producer. The map cache producer provides 5 operations (put, get, update, 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, update, query
hazelcast.objectId String the object id to store / find your object inside the cache (not needed for the query operation)
[Warning]Warning

Header variables have changed in Fuse Mediation Router 2.8

Name Type Description
CamelHazelcastOperationType String valid values are: put, delete, get, update, query Version 2.8
CamelHazelcastObjectId String the object id to store / find your object inside the cache (not needed for the query operation) Version 2.8

You can call the samples with:

template.sendBodyAndHeader("direct:[put|get|update|delete|query]", "my-foo", HazelcastConstants.OBJECT_ID, "4711");

Hazelcast provides event listeners on their data grid. If you want to be notified if a cache will be manipulated, you can use the map consumer. There're 4 events: put, update, delete and envict. The event type will be stored in the "hazelcast.listener.action" header variable. The map consumer provides some additional information inside these variables:

Header Variables inside the response message:

Name Type Description
hazelcast.listener.time Long time of the event in millis
hazelcast.listener.type String the map consumer sets here "cachelistener"
hazelcast.listener.action String type of event - here added, updated, envicted and removed
hazelcast.objectId String the oid of the object
hazelcast.cache.name String the name of the cache - e.g. "foo"
hazelcast.cache.type String the type of the cache - here map
[Warning]Warning

Header variables have changed in Fuse Mediation Router 2.8

Name Type Description
CamelHazelcastListenerTime Long time of the event in millis Version 2.8
CamelHazelcastListenerType String the map consumer sets here "cachelistener" Version 2.8
CamelHazelcastListenerAction String type of event - here added, updated, envicted and removed. Version 2.8
CamelHazelcastObjectId String the oid of the object Version 2.8
CamelHazelcastCacheName String the name of the cache - e.g. "foo" Version 2.8
CamelHazelcastCacheType String the type of the cache - here map Version 2.8

The object value will be stored within put and update actions inside the message body.

Here's a sample:

fromF("hazelcast:%sfoo", HazelcastConstants.MAP_PREFIX)
.log("object...")
.choice()
    .when(header(HazelcastConstants.LISTENER_ACTION).isEqualTo(HazelcastConstants.ADDED))
         .log("...added")
         .to("mock:added")
    .when(header(HazelcastConstants.LISTENER_ACTION).isEqualTo(HazelcastConstants.ENVICTED))
         .log("...envicted")
         .to("mock:envicted")
    .when(header(HazelcastConstants.LISTENER_ACTION).isEqualTo(HazelcastConstants.UPDATED))
         .log("...updated")
         .to("mock:updated")
    .when(header(HazelcastConstants.LISTENER_ACTION).isEqualTo(HazelcastConstants.REMOVED))
         .log("...removed")
         .to("mock:removed")
    .otherwise()
         .log("fail!");

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]Warning

Header variables have changed in Fuse Mediation Router 2.8

Header Variables for the request message in Fuse Mediation Router 2.8:

Name Type Description
CamelHazelcastOperationType String valid values are: put, delete, get, update, query Available as of Fuse Mediation Router 2.8
CamelHazelcastObjectId String the object id to store / find your object inside the cache (not needed for the query operation) Version 2.8

You can call the samples with:

template.sendBodyAndHeader("direct:[put|get|update|delete|query]", "my-foo", HazelcastConstants.OBJECT_ID, "4711");

Hazelcast provides event listeners on their data grid. If you want to be notified if a cache will be manipulated, you can use the map consumer. There're 4 events: put, update, delete and envict. The event type will be stored in the "hazelcast.listener.action" header variable. The map consumer provides some additional information inside these variables:

Header Variables inside the response message:

Name Type Description
hazelcast.listener.time Long time of the event in millis
hazelcast.listener.type String the map consumer sets here "cachelistener"
hazelcast.listener.action String type of event - here added, updated, envicted and removed
hazelcast.objectId String the oid of the object
hazelcast.cache.name String the name of the cache - e.g. "foo"
hazelcast.cache.type String the type of the cache - here map
[Warning]Warning

Header variables have changed in Fuse Mediation Router 2.8

Name Type Description
CamelHazelcastListenerTime Long time of the event in millis Version 2.8
CamelHazelcastListenerType String the map consumer sets here "cachelistener" Version 2.8
CamelHazelcastListenerAction String type of event - here added, updated, envicted and removed. Version 2.8
CamelHazelcastObjectId String the oid of the object Version 2.8
CamelHazelcastCacheName String the name of the cache - e.g. "foo" Version 2.8
CamelHazelcastCacheType String the type of the cache - here map Version 2.8

The object value will be stored within put and update actions inside the message body.

Here's a sample:

fromF("hazelcast:%sfoo", HazelcastConstants.MAP_PREFIX)
.log("object...")
.choice()
    .when(header(HazelcastConstants.LISTENER_ACTION).isEqualTo(HazelcastConstants.ADDED))
         .log("...added")
         .to("mock:added")
    .when(header(HazelcastConstants.LISTENER_ACTION).isEqualTo(HazelcastConstants.ENVICTED))
         .log("...envicted")
         .to("mock:envicted")
    .when(header(HazelcastConstants.LISTENER_ACTION).isEqualTo(HazelcastConstants.UPDATED))
         .log("...updated")
         .to("mock:updated")
    .when(header(HazelcastConstants.LISTENER_ACTION).isEqualTo(HazelcastConstants.REMOVED))
         .log("...removed")
         .to("mock:removed")
    .otherwise()
         .log("fail!");

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]Warning

Header variables have changed in Fuse Mediation Router 2.8

Name Type Description
CamelHazelcastOperationType String valid values are: put, get, removevalue, delete Version 2.8
CamelHazelcastObjectId String the object id to store / find your object inside the cache Version 2.8

For the multimap cache this component provides the same listeners / variables as for the map cache consumer (except the update and enviction listener). The only difference is the multimap prefix inside the URI. Here is a sample:

fromF("hazelcast:%sbar", HazelcastConstants.MULTIMAP_PREFIX)
.log("object...")
.choice()
	.when(header(HazelcastConstants.LISTENER_ACTION).isEqualTo(HazelcastConstants.ADDED))
		.log("...added")
                .to("mock:added")
        //.when(header(HazelcastConstants.LISTENER_ACTION).isEqualTo(HazelcastConstants.ENVICTED))
        //        .log("...envicted")
        //        .to("mock:envicted")
        .when(header(HazelcastConstants.LISTENER_ACTION).isEqualTo(HazelcastConstants.REMOVED))
                .log("...removed")
                .to("mock:removed")
        .otherwise()
                .log("fail!");

Header Variables inside the response message:

Name Type Description
hazelcast.listener.time Long time of the event in millis
hazelcast.listener.type String the map consumer sets here "cachelistener"
hazelcast.listener.action String type of event - here added and removed (and soon envicted)
hazelcast.objectId String the oid of the object
hazelcast.cache.name String the name of the cache - e.g. "foo"
hazelcast.cache.type String the type of the cache - here multimap

Eviction will be added as feature, soon (this is a Hazelcast issue).

[Warning]Warning

Header variables have changed in Fuse Mediation Router 2.8

Name Type Description
CamelHazelcastListenerTime Long time of the event in millis Version 2.8
CamelHazelcastListenerType String the map consumer sets here "cachelistener" Version 2.8
CamelHazelcastListenerAction String type of event - here added and removed (and soon envicted) Version 2.8
CamelHazelcastObjectId String the oid of the object Version 2.8
CamelHazelcastCacheName String the name of the cache - e.g. "foo" Version 2.8
CamelHazelcastCacheType String the type of the cache - here multimap Version 2.8

The SEDA producer provides no operations. You only send data to the specified queue.

Name default value Description
transferExchange false Fuse Mediation Router 2.8.0: if set to true the whole Exchange will be transfered. If header or body contains not serializable objects, they will be skipped.

Java DSL :

from("direct:foo")
.to("hazelcast:seda:foo");

Spring DSL :

<route>
   <from uri="direct:start" />
   <to uri="hazelcast:seda:foo" />
</route>

[Warning]Warning

There is no consumer for this endpoint\!

An atomic number is an object that simply provides a grid wide number (long). The operations for this producer are setvalue (set the number with a given value), get, increase (+1), decrease (-1) and destroy.

Header Variables for the request message:

Name Type Description
hazelcast.operation.type String valid values are: setvalue, get, increase, decrease, destroy
[Warning]Warning

Header variables have changed in Fuse Mediation Router 2.8

Name Type Description
CamelHazelcastOperationType String valid values are: setvalue, get, increase, decrease, destroy Available as of Fuse Mediation Router version 2.8

[Warning]Warning

This endpoint provides no producer\!

Hazelcast makes sense in one single "server node", but it's extremly powerful in a clustered environment. The instance consumer fires if a new cache instance will join or leave the cluster.

Here's a sample:

fromF("hazelcast:%sfoo", HazelcastConstants.INSTANCE_PREFIX)
.log("instance...")
.choice()
	.when(header(HazelcastConstants.LISTENER_ACTION).isEqualTo(HazelcastConstants.ADDED))
		.log("...added")
		.to("mock:added")
	.otherwise()
		.log("...removed")
		.to("mock:removed");

Each event provides the following information inside the message header:

Header Variables inside the response message:

Name Type Description
hazelcast.listener.time Long time of the event in millis
hazelcast.listener.type String the map consumer sets here "instancelistener"
hazelcast.listener.action String type of event - here added or removed
hazelcast.instance.host String host name of the instance
hazelcast.instance.port Integer port number of the instance
[Warning]Warning

Header variables have changed in Fuse Mediation Router 2.8

Name Type Description
CamelHazelcastListenerTime Long time of the event in millis Version 2.8
CamelHazelcastListenerType String the map consumer sets here "instancelistener" Version 2.8
CamelHazelcastListenerActionn String type of event - here added or removed. Version 2.8
CamelHazelcastInstanceHost String host name of the instance Version 2.8
CamelHazelcastInstancePort Integer port number of the instance Version 2.8
Comments powered by Disqus