Versions Compared

Key

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

...

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

Anchor
map
map

Usage of Map

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

...

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

Using hazelcast reference

By its name

Code Block
languagexml
<bean id="hazelcastLifecycle" class="com.hazelcast.core.LifecycleService"
      factory-bean="hazelcastInstance" factory-method="getLifecycleService"
      destroy-method="shutdown" />

<bean id="config" class="com.hazelcast.config.Config">
    <constructor-arg type="java.lang.String" value="HZ.INSTANCE" />
</bean>

<bean id="hazelcastInstance" class="com.hazelcast.core.Hazelcast" factory-method="newHazelcastInstance">
    <constructor-arg type="com.hazelcast.config.Config" ref="config"/>
</bean>
<camelContext xmlns="http://camel.apache.org/schema/spring">
    <route id="testHazelcastInstanceBeanRefPut">
        <from uri="direct:testHazelcastInstanceBeanRefPut"/>
        <setHeader headerName="CamelHazelcastOperationType">
            <constant>put</constant>
        </setHeader>
        <to uri="hazelcast:map:testmap?hazelcastInstanceName=HZ.INSTANCE"/>
    </route>

    <route id="testHazelcastInstanceBeanRefGet">
        <from uri="direct:testHazelcastInstanceBeanRefGet" />
        <setHeader headerName="CamelHazelcastOperationType">
            <constant>get</constant>
        </setHeader>
        <to uri="hazelcast:map:testmap?hazelcastInstanceName=HZ.INSTANCE"/>
        <to uri="seda:out" />
    </route>
</camelContext>

...

Code Block
languagexml
<!-- referencing the hazelcastInstance as a service -->
<reference ref="hazelcastInstance" interface="com.hazelcast.core.HazelcastInstance" />

<camelContext xmlns="http://camel.apache.org/schema/blueprint">
    <route id="testHazelcastInstanceBeanRefPut">
        <from uri="direct:testHazelcastInstanceBeanRefPut"/>
        <setHeader headerName="CamelHazelcastOperationType">
            <constant>put</constant>
        </setHeader>
        <to uri="hazelcast:map:testmap?hazelcastInstance=#hazelcastInstance"/>
    </route>

    <route id="testHazelcastInstanceBeanRefGet">
        <from uri="direct:testHazelcastInstanceBeanRefGet" />
        <setHeader headerName="CamelHazelcastOperationType">
            <constant>get</constant>
        </setHeader>
        <to uri="hazelcast:map:testmap?hazelcastInstance=#hazelcastInstance"/>
        <to uri="seda:out" />
    </route>
</camelContext>

Anchor
replicatedmap
replicatedmap

Usage of Replicated map

Avalaible from Camel 2.16

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

A replicated map is a weakly consistent, distributed key-value data structure with no data partition. The replicatedmap producer provides 4 operations (put, get, delete, clear).

Header Variables for the request message:

Name

Type

Description

hazelcast.operation.type

String

valid values are: put, get, delete, clear

hazelcast.objectId

String

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

Warning

Header variables have changed in Camel 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

Sample for put:

Java DSL:

Code Block
from("direct:put")
.setHeader(HazelcastConstants.OPERATION, constant(HazelcastConstants.PUT_OPERATION))
.to(String.format("hazelcast:%sbar", HazelcastConstants.REPLICATEDMAP_PREFIX));

Spring DSL:

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

Java DSL:

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

Spring DSL:

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

Java DSL:

Code Block
from("direct:delete")
.setHeader(HazelcastConstants.OPERATION, constant(HazelcastConstants.DELETE_OPERATION))
.toF("hazelcast:%sbar", HazelcastConstants.REPLICATEDMAP_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:replicatedmap:foo" />
</route>

you can call them in your test class with:

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

replicatedmap cache consumer - from("hazelcast:replicatedmap:foo")

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:

Code Block
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 replicatedmap

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

Warning

Header variables have changed in Camel 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 replicatedmap Version 2.8