...
- Usage of #map
- Usage of #multimap
- Usage of #queue
- Usage of #topic
- Usage of #list
- Usage of #seda
- Usage of atomic number
- Usage of #cluster support (instance)
- Usage of #replicatedmap
Anchor | ||||
---|---|---|---|---|
|
Usage of Map
map cache producer - to("hazelcast:map:foo")
...
Name | Type | Description |
---|---|---|
|
| time of the event in millis Version 2.8 |
|
| the map consumer sets here "instancelistener" Version 2.8 |
|
| type of event - here added or removed. Version 2.8 |
|
| host name of the instance Version 2.8 |
|
| port number of the instance Version 2.8 |
Using hazelcast reference
By its name
Code Block | ||
---|---|---|
| ||
<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 | ||
---|---|---|
| ||
<!-- 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 | ||||
---|---|---|---|---|
|
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 |
---|---|---|
|
| valid values are: put, get, delete, clear |
|
| the object id to store / find your object inside the cache |
Warning |
---|
Header variables have changed in Camel 2.8 |
Name | Type | Description |
---|---|---|
|
| valid values are: put, get, removevalue, delete Version 2.8 |
|
| 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 |
---|---|---|
|
| time of the event in millis |
|
| the map consumer sets here "cachelistener" |
|
| type of event - here added and removed (and soon envicted) |
|
| the oid of the object |
|
| the name of the cache - e.g. "foo" |
|
| 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 |
---|---|---|
|
| time of the event in millis Version 2.8 |
|
| the map consumer sets here "cachelistener" Version 2.8 |
|
| type of event - here added and removed (and soon envicted) Version 2.8 |
|
| the oid of the object Version 2.8 |
|
| the name of the cache - e.g. "foo" Version 2.8 |
|
| the type of the cache - here replicatedmap Version 2.8 |