...
Name | Type | Description |
---|---|---|
|
| valid values are: put, get, removevalue, delete From Camel 2.16: 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, delete, get, update, query Available as of Camel 2.8 |
|
| 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:
Code Block |
---|
template.sendBodyAndHeader("direct:[put|get|update|delete|query]", "my-foo", HazelcastConstants.OBJECT_ID, "4711");
|
Sample for put:
Java DSL:
Code Block |
---|
from("direct:put")
.setHeader(HazelcastConstants.OPERATION, constant(HazelcastConstants.PUT_OPERATION))
.toF("hazelcast:%sfoo", HazelcastConstants.MAP_PREFIX);
|
Spring DSL:
Code Block |
---|
<route>
<from uri="direct:put" />
<!-- If using version 2.8 and above set headerName to "CamelHazelcastOperationType" -->
<setHeader headerName="hazelcast.operation.type">
<constant>put</constant>
</setHeader>
<to uri="hazelcast:map:foo" />
</route>
|
Sample for get:
Java DSL:
Code Block |
---|
from("direct:get")
.setHeader(HazelcastConstants.OPERATION, constant(HazelcastConstants.GET_OPERATION))
.toF("hazelcast:%sfoo", HazelcastConstants.MAP_PREFIX)
.to("seda:out");
|
Spring DSL:
Code Block |
---|
<route>
<from uri="direct:get" />
<!-- 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:
Code Block |
---|
from("direct:update")
.setHeader(HazelcastConstants.OPERATION, constant(HazelcastConstants.UPDATE_OPERATION))
.toF("hazelcast:%sfoo", HazelcastConstants.MAP_PREFIX);
|
Spring DSL:
Code Block |
---|
<route>
<from uri="direct:update" />
<!-- If using version 2.8 and above set headerName to "CamelHazelcastOperationType" -->
<setHeader headerName="hazelcast.operation.type">
<constant>update</constant>
</setHeader>
<to uri="hazelcast:map:foo" />
</route>
|
Sample for delete:
Java DSL:
Code Block |
---|
from("direct:delete")
.setHeader(HazelcastConstants.OPERATION, constant(HazelcastConstants.DELETE_OPERATION))
.toF("hazelcast:%sfoo", HazelcastConstants.MAP_PREFIX);
|
Spring DSL:
Code Block |
---|
<route>
<from uri="direct:delete" />
<!-- If using version 2.8 and above set headerName to "CamelHazelcastOperationType" -->
<setHeader headerName="hazelcast.operation.type">
<constant>delete</constant>
</setHeader>
<to uri="hazelcast:map:foo" />
</route>
|
Sample for query
Java DSL:
Code Block |
---|
from("direct:query")
.setHeader(HazelcastConstants.OPERATION, constant(HazelcastConstants.QUERY_OPERATION))
.toF("hazelcast:%sfoo", HazelcastConstants.MAP_PREFIX)
.to("seda:out");
|
Spring DSL:
Code Block |
---|
<route>
<from uri="direct:query" />
<!-- If using version 2.8 and above set headerName to "CamelHazelcastOperationType" -->
<setHeader headerName="hazelcast.operation.type">
<constant>query</constant>
</setHeader>
<to uri="hazelcast:map:foo" />
<to uri="seda:out" />
</route>
|
For the query operation Hazelcast offers a SQL like syntax to query your distributed map.
Code Block |
---|
String q1 = "bar > 1000";
template.sendBodyAndHeader("direct:query", null, HazelcastConstants.QUERY, q1);
|
map cache consumer - from("hazelcast:map:foo")
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 |
---|---|---|
|
| time of the event in millis |
|
| the map consumer sets here "cachelistener" |
|
| type of event - here added, updated, envicted and removed |
|
| the oid of the object |
|
| the name of the cache - e.g. "foo" |
|
| the type of the cache - here map |
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, updated, envicted and removed. 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 map Version 2.8 |
The object value will be stored within put and update actions inside the message body.
Here's a sample:
Code Block |
---|
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!");
|
...
Usage of Multi Map
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 |
---|---|---|
|
| valid values are: put, get, removevalue, delete |
|
| the object id to store / find your object inside the cache |
...
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.MULTIMAP_PREFIX)); |
...
To remove a value you have to provide the value you want to remove inside the message body. If you have a multimap object {key: "4711" values: { "my-foo", "my-bar"
}} you have to put "my-foo" inside the message body to remove the "my-foo" value.
Sample for get:
Java DSL:
Code Block |
---|
from("direct:get") .setHeader(HazelcastConstants.OPERATION, constant(HazelcastConstants.GET_OPERATION)) .toF("hazelcast:%sbar", HazelcastConstants.MULTIMAP_PREFIX) .to("seda:out"); |
...
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:multimap: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.MULTIMAP_PREFIX); |
...
Code Block |
---|
from("direct:add") .setHeader(HazelcastConstants.OPERATION, constant(HazelcastConstants.ADD_OPERATION)) .toF("hazelcast:%sbar", HazelcastConstants.QUEUE_PREFIX); |
Sample for put:
Code Block |
---|
from("direct:put") .setHeader(HazelcastConstants.OPERATION, constant(HazelcastConstants.PUT_OPERATION)) .toF("hazelcast:%sbar", HazelcastConstants.QUEUE_PREFIX); |
...
Code Block |
---|
from("direct:add") .setHeader(HazelcastConstants.OPERATION, constant(HazelcastConstants.ADD_OPERATION)) .toF("hazelcast:%sbar", HazelcastConstants.LIST_PREFIX); |
Sample for get:
Code Block |
---|
from("direct:get") .setHeader(HazelcastConstants.OPERATION, constant(HazelcastConstants.GET_OPERATION)) .toF("hazelcast:%sbar", HazelcastConstants.LIST_PREFIX) .to("seda:out"); |
...
Provide the value to set inside the message body (here the value is 10): template.sendBody("direct:set", 10);
Sample for get:
Java DSL:
Code Block |
---|
from("direct:get") .setHeader(HazelcastConstants.OPERATION, constant(HazelcastConstants.GET_OPERATION)) .toF("hazelcast:%sfoo", HazelcastConstants.ATOMICNUMBER_PREFIX); |
...
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)); |
...
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"); |
...
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); |
...