Fuse 6 is no longer supported
As of February 2025, Red Hat Fuse 6 is no longer supported. If you are using Fuse 6, please upgrade to Red Hat build of Apache Camel.此内容没有您所选择的语言版本。
Chapter 59. Hazelcast Component
Hazelcast Component 复制链接链接已复制到粘贴板!
复制链接链接已复制到粘贴板!
Available as of Apache 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/docs.jsp.
Maven users will need to add the following dependency to their
pom.xml
for this component:
URI format 复制链接链接已复制到粘贴板!
复制链接链接已复制到粘贴板!
hazelcast:[ map | multimap | queue | topic | seda | set | atomicvalue | instance | list]:cachename[?options]
hazelcast:[ map | multimap | queue | topic | seda | set | atomicvalue | instance | list]:cachename[?options]
Options 复制链接链接已复制到粘贴板!
复制链接链接已复制到粘贴板!
Name
|
Required
|
Description
|
hazelcastInstance
|
No
|
Camel 2.14: The hazelcast instance reference which can be used for hazelcast endpoint. If you don't specify the instance reference, camel use the default hazelcast instance from the camel-hazelcast instance.
|
hazelcastInstanceName
|
No
|
|
defaultOperation
|
-1
|
Camel 2.15: To specify a default operation to use, if no operation header has been provided.
|
Warning
You have to use the second prefix to define which type of data store you want to use.
Sections 复制链接链接已复制到粘贴板!
复制链接链接已复制到粘贴板!
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 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
Header variables have changed in Apache Camel 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");
template.sendBodyAndHeader("direct:[put|get|update|delete|query]", "my-foo", HazelcastConstants.OBJECT_ID, "4711");
Sample for put: 复制链接链接已复制到粘贴板!
复制链接链接已复制到粘贴板!
Java DSL:
from("direct:put") .setHeader(HazelcastConstants.OPERATION, constant(HazelcastConstants.PUT_OPERATION)) .toF("hazelcast:%sfoo", HazelcastConstants.MAP_PREFIX);
from("direct:put")
.setHeader(HazelcastConstants.OPERATION, constant(HazelcastConstants.PUT_OPERATION))
.toF("hazelcast:%sfoo", HazelcastConstants.MAP_PREFIX);
Spring DSL:
Sample for get: 复制链接链接已复制到粘贴板!
复制链接链接已复制到粘贴板!
Java DSL:
from("direct:get") .setHeader(HazelcastConstants.OPERATION, constant(HazelcastConstants.GET_OPERATION)) .toF("hazelcast:%sfoo", HazelcastConstants.MAP_PREFIX) .to("seda:out");
from("direct:get")
.setHeader(HazelcastConstants.OPERATION, constant(HazelcastConstants.GET_OPERATION))
.toF("hazelcast:%sfoo", HazelcastConstants.MAP_PREFIX)
.to("seda:out");
Spring DSL:
Sample for update: 复制链接链接已复制到粘贴板!
复制链接链接已复制到粘贴板!
Java DSL:
from("direct:update") .setHeader(HazelcastConstants.OPERATION, constant(HazelcastConstants.UPDATE_OPERATION)) .toF("hazelcast:%sfoo", HazelcastConstants.MAP_PREFIX);
from("direct:update")
.setHeader(HazelcastConstants.OPERATION, constant(HazelcastConstants.UPDATE_OPERATION))
.toF("hazelcast:%sfoo", HazelcastConstants.MAP_PREFIX);
Spring DSL:
Sample for delete: 复制链接链接已复制到粘贴板!
复制链接链接已复制到粘贴板!
Java DSL:
from("direct:delete") .setHeader(HazelcastConstants.OPERATION, constant(HazelcastConstants.DELETE_OPERATION)) .toF("hazelcast:%sfoo", HazelcastConstants.MAP_PREFIX);
from("direct:delete")
.setHeader(HazelcastConstants.OPERATION, constant(HazelcastConstants.DELETE_OPERATION))
.toF("hazelcast:%sfoo", HazelcastConstants.MAP_PREFIX);
Spring DSL:
Sample for query 复制链接链接已复制到粘贴板!
复制链接链接已复制到粘贴板!
Java DSL:
from("direct:query") .setHeader(HazelcastConstants.OPERATION, constant(HazelcastConstants.QUERY_OPERATION)) .toF("hazelcast:%sfoo", HazelcastConstants.MAP_PREFIX) .to("seda:out");
from("direct:query")
.setHeader(HazelcastConstants.OPERATION, constant(HazelcastConstants.QUERY_OPERATION))
.toF("hazelcast:%sfoo", HazelcastConstants.MAP_PREFIX)
.to("seda:out");
Spring DSL:
For the query operation Hazelcast offers a SQL like syntax to query your distributed map.
String q1 = "bar > 1000"; template.sendBodyAndHeader("direct:query", null, HazelcastConstants.QUERY, q1);
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 |
---|---|---|
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
Header variables have changed in Apache 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, 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:
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 |
---|---|---|
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 Apache Camel 2.8
Header Variables for the request message in Apache Camel 2.8:
Name | Type | Description |
---|---|---|
CamelHazelcastOperationType
|
String
|
valid values are: put, delete, get, update, query Available as of Apache Camel 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");
template.sendBodyAndHeader("direct:[put|get|update|delete|query]", "my-foo", HazelcastConstants.OBJECT_ID, "4711");
Sample for put: 复制链接链接已复制到粘贴板!
复制链接链接已复制到粘贴板!
Java DSL:
from("direct:put") .setHeader(HazelcastConstants.OPERATION, constant(HazelcastConstants.PUT_OPERATION)) .toF("hazelcast:%sfoo", HazelcastConstants.MAP_PREFIX);
from("direct:put")
.setHeader(HazelcastConstants.OPERATION, constant(HazelcastConstants.PUT_OPERATION))
.toF("hazelcast:%sfoo", HazelcastConstants.MAP_PREFIX);
Spring DSL:
Sample for get: 复制链接链接已复制到粘贴板!
复制链接链接已复制到粘贴板!
Java DSL:
from("direct:get") .setHeader(HazelcastConstants.OPERATION, constant(HazelcastConstants.GET_OPERATION)) .toF("hazelcast:%sfoo", HazelcastConstants.MAP_PREFIX) .to("seda:out");
from("direct:get")
.setHeader(HazelcastConstants.OPERATION, constant(HazelcastConstants.GET_OPERATION))
.toF("hazelcast:%sfoo", HazelcastConstants.MAP_PREFIX)
.to("seda:out");
Spring DSL:
Sample for update: 复制链接链接已复制到粘贴板!
复制链接链接已复制到粘贴板!
Java DSL:
from("direct:update") .setHeader(HazelcastConstants.OPERATION, constant(HazelcastConstants.UPDATE_OPERATION)) .toF("hazelcast:%sfoo", HazelcastConstants.MAP_PREFIX);
from("direct:update")
.setHeader(HazelcastConstants.OPERATION, constant(HazelcastConstants.UPDATE_OPERATION))
.toF("hazelcast:%sfoo", HazelcastConstants.MAP_PREFIX);
Spring DSL:
Sample for delete: 复制链接链接已复制到粘贴板!
复制链接链接已复制到粘贴板!
Java DSL:
from("direct:delete") .setHeader(HazelcastConstants.OPERATION, constant(HazelcastConstants.DELETE_OPERATION)) .toF("hazelcast:%sfoo", HazelcastConstants.MAP_PREFIX);
from("direct:delete")
.setHeader(HazelcastConstants.OPERATION, constant(HazelcastConstants.DELETE_OPERATION))
.toF("hazelcast:%sfoo", HazelcastConstants.MAP_PREFIX);
Spring DSL:
Sample for query 复制链接链接已复制到粘贴板!
复制链接链接已复制到粘贴板!
Java DSL:
from("direct:query") .setHeader(HazelcastConstants.OPERATION, constant(HazelcastConstants.QUERY_OPERATION)) .toF("hazelcast:%sfoo", HazelcastConstants.MAP_PREFIX) .to("seda:out");
from("direct:query")
.setHeader(HazelcastConstants.OPERATION, constant(HazelcastConstants.QUERY_OPERATION))
.toF("hazelcast:%sfoo", HazelcastConstants.MAP_PREFIX)
.to("seda:out");
Spring DSL:
For the query operation Hazelcast offers a SQL like syntax to query your distributed map.
String q1 = "bar > 1000"; template.sendBodyAndHeader("direct:query", null, HazelcastConstants.QUERY, q1);
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 |
---|---|---|
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
Header variables have changed in Apache 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, 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:
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 |
---|---|---|
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 Apache 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:
from("direct:put") .setHeader(HazelcastConstants.OPERATION, constant(HazelcastConstants.PUT_OPERATION)) .to(String.format("hazelcast:%sbar", HazelcastConstants.MULTIMAP_PREFIX));
from("direct:put")
.setHeader(HazelcastConstants.OPERATION, constant(HazelcastConstants.PUT_OPERATION))
.to(String.format("hazelcast:%sbar", HazelcastConstants.MULTIMAP_PREFIX));
Spring DSL:
Sample for removevalue: 复制链接链接已复制到粘贴板!
复制链接链接已复制到粘贴板!
Java DSL:
from("direct:removevalue") .setHeader(HazelcastConstants.OPERATION, constant(HazelcastConstants.REMOVEVALUE_OPERATION)) .toF("hazelcast:%sbar", HazelcastConstants.MULTIMAP_PREFIX);
from("direct:removevalue")
.setHeader(HazelcastConstants.OPERATION, constant(HazelcastConstants.REMOVEVALUE_OPERATION))
.toF("hazelcast:%sbar", HazelcastConstants.MULTIMAP_PREFIX);
Spring DSL:
To remove a value you have to provide the value you want to remove inside the message body. If you have a multimap object
} you have to put "my-foo" inside the message body to remove the "my-foo" value.
Sample for get: 复制链接链接已复制到粘贴板!
复制链接链接已复制到粘贴板!
Java DSL:
from("direct:get") .setHeader(HazelcastConstants.OPERATION, constant(HazelcastConstants.GET_OPERATION)) .toF("hazelcast:%sbar", HazelcastConstants.MULTIMAP_PREFIX) .to("seda:out");
from("direct:get")
.setHeader(HazelcastConstants.OPERATION, constant(HazelcastConstants.GET_OPERATION))
.toF("hazelcast:%sbar", HazelcastConstants.MULTIMAP_PREFIX)
.to("seda:out");
Spring DSL:
Sample for delete: 复制链接链接已复制到粘贴板!
复制链接链接已复制到粘贴板!
Java DSL:
from("direct:delete") .setHeader(HazelcastConstants.OPERATION, constant(HazelcastConstants.DELETE_OPERATION)) .toF("hazelcast:%sbar", HazelcastConstants.MULTIMAP_PREFIX);
from("direct:delete")
.setHeader(HazelcastConstants.OPERATION, constant(HazelcastConstants.DELETE_OPERATION))
.toF("hazelcast:%sbar", HazelcastConstants.MULTIMAP_PREFIX);
Spring DSL:
you can call them in your test class with:
template.sendBodyAndHeader("direct:[put|get|removevalue|delete]", "my-foo", HazelcastConstants.OBJECT_ID, "4711");
template.sendBodyAndHeader("direct:[put|get|removevalue|delete]", "my-foo", HazelcastConstants.OBJECT_ID, "4711");
multimap cache consumer - from("hazelcast:multimap: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:
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
Header variables have changed in Apache 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 multimap Version 2.8 |
Usage of Queue 复制链接链接已复制到粘贴板!
复制链接链接已复制到粘贴板!
Queue producer to("hazelcast:queue:foo") 复制链接链接已复制到粘贴板!
复制链接链接已复制到粘贴板!
The queue producer provides 6 operations (add, put, poll, peek, offer, removevalue).
Sample for add: 复制链接链接已复制到粘贴板!
复制链接链接已复制到粘贴板!
from("direct:add") .setHeader(HazelcastConstants.OPERATION, constant(HazelcastConstants.ADD_OPERATION)) .toF("hazelcast:%sbar", HazelcastConstants.QUEUE_PREFIX);
from("direct:add")
.setHeader(HazelcastConstants.OPERATION, constant(HazelcastConstants.ADD_OPERATION))
.toF("hazelcast:%sbar", HazelcastConstants.QUEUE_PREFIX);
Sample for put: 复制链接链接已复制到粘贴板!
复制链接链接已复制到粘贴板!
from("direct:put") .setHeader(HazelcastConstants.OPERATION, constant(HazelcastConstants.PUT_OPERATION)) .toF("hazelcast:%sbar", HazelcastConstants.QUEUE_PREFIX);
from("direct:put")
.setHeader(HazelcastConstants.OPERATION, constant(HazelcastConstants.PUT_OPERATION))
.toF("hazelcast:%sbar", HazelcastConstants.QUEUE_PREFIX);
Sample for poll: 复制链接链接已复制到粘贴板!
复制链接链接已复制到粘贴板!
from("direct:poll") .setHeader(HazelcastConstants.OPERATION, constant(HazelcastConstants.POLL_OPERATION)) .toF("hazelcast:%sbar", HazelcastConstants.QUEUE_PREFIX);
from("direct:poll")
.setHeader(HazelcastConstants.OPERATION, constant(HazelcastConstants.POLL_OPERATION))
.toF("hazelcast:%sbar", HazelcastConstants.QUEUE_PREFIX);
Sample for peek: 复制链接链接已复制到粘贴板!
复制链接链接已复制到粘贴板!
from("direct:peek") .setHeader(HazelcastConstants.OPERATION, constant(HazelcastConstants.PEEK_OPERATION)) .toF("hazelcast:%sbar", HazelcastConstants.QUEUE_PREFIX);
from("direct:peek")
.setHeader(HazelcastConstants.OPERATION, constant(HazelcastConstants.PEEK_OPERATION))
.toF("hazelcast:%sbar", HazelcastConstants.QUEUE_PREFIX);
Sample for offer: 复制链接链接已复制到粘贴板!
复制链接链接已复制到粘贴板!
from("direct:offer") .setHeader(HazelcastConstants.OPERATION, constant(HazelcastConstants.OFFER_OPERATION)) .toF("hazelcast:%sbar", HazelcastConstants.QUEUE_PREFIX);
from("direct:offer")
.setHeader(HazelcastConstants.OPERATION, constant(HazelcastConstants.OFFER_OPERATION))
.toF("hazelcast:%sbar", HazelcastConstants.QUEUE_PREFIX);
Sample for removevalue: 复制链接链接已复制到粘贴板!
复制链接链接已复制到粘贴板!
from("direct:removevalue") .setHeader(HazelcastConstants.OPERATION, constant(HazelcastConstants.REMOVEVALUE_OPERATION)) .toF("hazelcast:%sbar", HazelcastConstants.QUEUE_PREFIX);
from("direct:removevalue")
.setHeader(HazelcastConstants.OPERATION, constant(HazelcastConstants.REMOVEVALUE_OPERATION))
.toF("hazelcast:%sbar", HazelcastConstants.QUEUE_PREFIX);
Queue consumer from("hazelcast:queue:foo") 复制链接链接已复制到粘贴板!
复制链接链接已复制到粘贴板!
The queue consumer provides 2 operations (add, remove).
Usage of Topic 复制链接链接已复制到粘贴板!
复制链接链接已复制到粘贴板!
Topic producer – to(“hazelcast:topic:foo”) 复制链接链接已复制到粘贴板!
复制链接链接已复制到粘贴板!
The topic producer provides only one operation (publish).
Sample for publish 复制链接链接已复制到粘贴板!
复制链接链接已复制到粘贴板!
from("direct:add") .setHeader(HazelcastConstants.OPERATION, constant(HazelcastConstants.PUBLISH_OPERATION)) .toF("hazelcast:%sbar", HazelcastConstants.PUBLISH_OPERATION);
from("direct:add")
.setHeader(HazelcastConstants.OPERATION, constant(HazelcastConstants.PUBLISH_OPERATION))
.toF("hazelcast:%sbar", HazelcastConstants.PUBLISH_OPERATION);
Topic consumer – from(“hazelcast:topic:foo”) 复制链接链接已复制到粘贴板!
复制链接链接已复制到粘贴板!
The topic consumer provides only one operation (received). This component is supposed to support multiple consumption as it's expected when it comes to topics so you are free to have as much consumers as you need on the same hazelcast topic.
Usage of List 复制链接链接已复制到粘贴板!
复制链接链接已复制到粘贴板!
List producer to("hazelcast:list:foo") 复制链接链接已复制到粘贴板!
复制链接链接已复制到粘贴板!
The list producer provides 4 operations (add, set, get, removevalue).
Sample for add: 复制链接链接已复制到粘贴板!
复制链接链接已复制到粘贴板!
from("direct:add") .setHeader(HazelcastConstants.OPERATION, constant(HazelcastConstants.ADD_OPERATION)) .toF("hazelcast:%sbar", HazelcastConstants.LIST_PREFIX);
from("direct:add")
.setHeader(HazelcastConstants.OPERATION, constant(HazelcastConstants.ADD_OPERATION))
.toF("hazelcast:%sbar", HazelcastConstants.LIST_PREFIX);
Sample for get: 复制链接链接已复制到粘贴板!
复制链接链接已复制到粘贴板!
from("direct:get") .setHeader(HazelcastConstants.OPERATION, constant(HazelcastConstants.GET_OPERATION)) .toF("hazelcast:%sbar", HazelcastConstants.LIST_PREFIX) .to("seda:out");
from("direct:get")
.setHeader(HazelcastConstants.OPERATION, constant(HazelcastConstants.GET_OPERATION))
.toF("hazelcast:%sbar", HazelcastConstants.LIST_PREFIX)
.to("seda:out");
Sample for setvalue: 复制链接链接已复制到粘贴板!
复制链接链接已复制到粘贴板!
from("direct:set") .setHeader(HazelcastConstants.OPERATION, constant(HazelcastConstants.SETVALUE_OPERATION)) .toF("hazelcast:%sbar", HazelcastConstants.LIST_PREFIX);
from("direct:set")
.setHeader(HazelcastConstants.OPERATION, constant(HazelcastConstants.SETVALUE_OPERATION))
.toF("hazelcast:%sbar", HazelcastConstants.LIST_PREFIX);
Sample for removevalue: 复制链接链接已复制到粘贴板!
复制链接链接已复制到粘贴板!
from("direct:removevalue") .setHeader(HazelcastConstants.OPERATION, constant(HazelcastConstants.REMOVEVALUE_OPERATION)) .toF("hazelcast:%sbar", HazelcastConstants.LIST_PREFIX);
from("direct:removevalue")
.setHeader(HazelcastConstants.OPERATION, constant(HazelcastConstants.REMOVEVALUE_OPERATION))
.toF("hazelcast:%sbar", HazelcastConstants.LIST_PREFIX);
Warning
Please note that set,get and removevalue and not yet supported by hazelcast, will be added in the future..
List consumer from("hazelcast:list:foo") 复制链接链接已复制到粘贴板!
复制链接链接已复制到粘贴板!
The list consumer provides 2 operations (add, remove).
Usage of SEDA 复制链接链接已复制到粘贴板!
复制链接链接已复制到粘贴板!
SEDA component differs from the rest components provided. It implements a work-queue in order to support asynchronous SEDA architectures, similar to the core "SEDA" component.
SEDA producer to("hazelcast:seda:foo") 复制链接链接已复制到粘贴板!
复制链接链接已复制到粘贴板!
The SEDA producer provides no operations. You only send data to the specified queue.
Name | default value | Description |
---|---|---|
transferExchange
|
false
|
Apache Camel 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");
from("direct:foo")
.to("hazelcast:seda:foo");
Spring DSL :
<route> <from uri="direct:start" /> <to uri="hazelcast:seda:foo" /> </route>
<route>
<from uri="direct:start" />
<to uri="hazelcast:seda:foo" />
</route>
SEDA consumer from("hazelcast:seda:foo") 复制链接链接已复制到粘贴板!
复制链接链接已复制到粘贴板!
The SEDA consumer provides no operations. You only retrieve data from the specified queue.
Name | default value | Description |
---|---|---|
pollInterval
|
1000
|
Deprecated since Camel 2.15. Use pollTimeout instead.
|
pollTimeout
|
1000
|
The timeout used when consuming from the SEDA queue. When a timeout occurs, the consumer can check whether it is allowed to continue running. Setting a lower value allows the consumer to react more quickly upon shutdown. |
concurrentConsumers
|
1
|
To use concurrent consumers polling from the SEDA queue. |
transferExchange
|
false
|
Camel 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. |
transacted
|
false
|
Camel 2.10.4: if set to true then the consumer runs in transaction mode, where the messages in the seda queue will only be removed if the transaction commits, which happens when the processing is complete. |
Java DSL :
from("hazelcast:seda:foo") .to("mock:result");
from("hazelcast:seda:foo")
.to("mock:result");
Spring DSL:
<route> <from uri="hazelcast:seda:foo" /> <to uri="mock:result" /> </route>
<route>
<from uri="hazelcast:seda:foo" />
<to uri="mock:result" />
</route>
Usage of Atomic Number 复制链接链接已复制到粘贴板!
复制链接链接已复制到粘贴板!
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
Header variables have changed in Apache Camel 2.8
Name | Type | Description |
---|---|---|
CamelHazelcastOperationType
|
String
|
valid values are: setvalue, get, increase, decrease, destroy Available as of Apache Camel version 2.8 |
Sample for set: 复制链接链接已复制到粘贴板!
复制链接链接已复制到粘贴板!
Java DSL:
from("direct:set") .setHeader(HazelcastConstants.OPERATION, constant(HazelcastConstants.SETVALUE_OPERATION)) .toF("hazelcast:%sfoo", HazelcastConstants.ATOMICNUMBER_PREFIX);
from("direct:set")
.setHeader(HazelcastConstants.OPERATION, constant(HazelcastConstants.SETVALUE_OPERATION))
.toF("hazelcast:%sfoo", HazelcastConstants.ATOMICNUMBER_PREFIX);
Spring DSL:
Provide the value to set inside the message body (here the value is 10):
template.sendBody("direct:set", 10);
Sample for get: 复制链接链接已复制到粘贴板!
复制链接链接已复制到粘贴板!
Java DSL:
from("direct:get") .setHeader(HazelcastConstants.OPERATION, constant(HazelcastConstants.GET_OPERATION)) .toF("hazelcast:%sfoo", HazelcastConstants.ATOMICNUMBER_PREFIX);
from("direct:get")
.setHeader(HazelcastConstants.OPERATION, constant(HazelcastConstants.GET_OPERATION))
.toF("hazelcast:%sfoo", HazelcastConstants.ATOMICNUMBER_PREFIX);
Spring DSL:
You can get the number with
long body = template.requestBody("direct:get", null, Long.class);
.
Sample for increment: 复制链接链接已复制到粘贴板!
复制链接链接已复制到粘贴板!
Java DSL:
from("direct:increment") .setHeader(HazelcastConstants.OPERATION, constant(HazelcastConstants.INCREMENT_OPERATION)) .toF("hazelcast:%sfoo", HazelcastConstants.ATOMICNUMBER_PREFIX);
from("direct:increment")
.setHeader(HazelcastConstants.OPERATION, constant(HazelcastConstants.INCREMENT_OPERATION))
.toF("hazelcast:%sfoo", HazelcastConstants.ATOMICNUMBER_PREFIX);
Spring DSL:
The actual value (after increment) will be provided inside the message body.
Sample for decrement: 复制链接链接已复制到粘贴板!
复制链接链接已复制到粘贴板!
Java DSL:
from("direct:decrement") .setHeader(HazelcastConstants.OPERATION, constant(HazelcastConstants.DECREMENT_OPERATION)) .toF("hazelcast:%sfoo", HazelcastConstants.ATOMICNUMBER_PREFIX);
from("direct:decrement")
.setHeader(HazelcastConstants.OPERATION, constant(HazelcastConstants.DECREMENT_OPERATION))
.toF("hazelcast:%sfoo", HazelcastConstants.ATOMICNUMBER_PREFIX);
Spring DSL:
The actual value (after decrement) will be provided inside the message body.
Sample for destroy 复制链接链接已复制到粘贴板!
复制链接链接已复制到粘贴板!
Warning
There's a bug inside Hazelcast. So this feature may not work properly. Will be fixed in 1.9.3.
Java DSL:
from("direct:destroy") .setHeader(HazelcastConstants.OPERATION, constant(HazelcastConstants.DESTROY_OPERATION)) .toF("hazelcast:%sfoo", HazelcastConstants.ATOMICNUMBER_PREFIX);
from("direct:destroy")
.setHeader(HazelcastConstants.OPERATION, constant(HazelcastConstants.DESTROY_OPERATION))
.toF("hazelcast:%sfoo", HazelcastConstants.ATOMICNUMBER_PREFIX);
Spring DSL:
Cluster support 复制链接链接已复制到粘贴板!
复制链接链接已复制到粘贴板!
Warning
This endpoint provides no producer!
instance consumer - from("hazelcast:instance:foo") 复制链接链接已复制到粘贴板!
复制链接链接已复制到粘贴板!
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:
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
Header variables have changed in Apache Camel 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 |
Using hazelcast reference 复制链接链接已复制到粘贴板!
复制链接链接已复制到粘贴板!
By its name 复制链接链接已复制到粘贴板!
复制链接链接已复制到粘贴板!
By instance 复制链接链接已复制到粘贴板!
复制链接链接已复制到粘贴板!
Publishing hazelcast instance as an OSGI service 复制链接链接已复制到粘贴板!
复制链接链接已复制到粘贴板!
If operating in an OSGI container and you would want to use one instance of hazelcast across all bundles in the same container. You can publish the instance as an OSGI service and bundles using the cache al need is to reference the service in the hazelcast endpoint.
Bundle B uses the instance 复制链接链接已复制到粘贴板!
复制链接链接已复制到粘贴板!