135.3. Map cache producer - to("hazelcast-map:foo")
如果要在映射中存储值,可以使用映射缓存制作者。
映射缓存制作器提供 CamelHazelcastOperationType 标头指定的操作:
- put
- putIfAbsent
- get
- getAll
- keySet
- containsKey
- containsValue
- delete
- update
- query
- clear
- evict
- evictAll
所有操作都位于 "hazelcast.operation.type" 标头变量中。在 Java DSL 中,您可以使用 org.apache.camel.component.hazelcast.Hazelcast.HazelcastOperation
中的恒定性。
请求消息的标头变量:
名称 | 类型 | 描述 |
---|---|---|
|
| 如上所述。 |
|
| 存储 / 的对象 ID,在缓存中找到您的对象(查询操作不需要) |
put 和 putIfAbsent 操作提供驱除机制:
名称 | 类型 | 描述 |
---|---|---|
|
| TTL 的值。 |
|
| 单位值(DAYS / HOURS / MINUTES / …. |
您可以使用以下方法调用示例:
template.sendBodyAndHeader("direct:[put|get|update|delete|query|evict]", "my-foo", HazelcastConstants.OBJECT_ID, "4711");
135.3.1. 放置 的示例:
Java DSL:
from("direct:put") .setHeader(HazelcastConstants.OPERATION, constant(HazelcastOperation.PUT)) .toF("hazelcast-%sfoo", HazelcastConstants.MAP_PREFIX);
Spring DSL:
<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>
使用驱除 放置 示例:
Java DSL:
from("direct:put") .setHeader(HazelcastConstants.OPERATION, constant(HazelcastOperation.PUT)) .setHeader(HazelcastConstants.TTL_VALUE, constant(Long.valueOf(1))) .setHeader(HazelcastConstants.TTL_UNIT, constant(TimeUnit.MINUTES)) .toF("hazelcast-%sfoo", HazelcastConstants.MAP_PREFIX);
Spring DSL:
<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> <setHeader headerName="HazelcastConstants.TTL_VALUE"> <simple resultType="java.lang.Long">1</simple> </setHeader> <setHeader headerName="HazelcastConstants.TTL_UNIT"> <simple resultType="java.util.concurrent.TimeUnit">TimeUnit.MINUTES</simple> </setHeader> <to uri="hazelcast-map:foo" /> </route>