126.2. マップキャッシュプロデューサー - 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.HazelcastOperation
の定数を使用できます。
リクエストメッセージのヘッダー変数:
名前 | タイプ | 説明 |
---|---|---|
|
| すでに説明したとおりです。 |
|
| キャッシュ内でオブジェクトを保存/検索するためのオブジェクト ID (クエリー操作には必要ありません) |
put および putIfAbsent 操作は、エビクションメカニズムを提供します。
名前 | タイプ | 説明 |
---|---|---|
|
| TTL の値。 |
|
| 時間単位の値 ( DAYS / HOURS / MINUTES / …. |
サンプルは次の方法で呼び出すことができます。
template.sendBodyAndHeader("direct:[put|get|update|delete|query|evict]", "my-foo", HazelcastConstants.OBJECT_ID, "4711");
126.2.1. put のサンプル:
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>
エビクションを使用した put のサンプル:
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>
126.2.2. get のサンプル:
Java DSL の場合
from("direct:get") .setHeader(HazelcastConstants.OPERATION, constant(HazelcastOperation.GET)) .toF("hazelcast-%sfoo", HazelcastConstants.MAP_PREFIX) .to("seda:out");
Spring DSL:
<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>
126.2.3. update のサンプル:
Java DSL の場合
from("direct:update") .setHeader(HazelcastConstants.OPERATION, constant(HazelcastOperation.UPDATE)) .toF("hazelcast-%sfoo", HazelcastConstants.MAP_PREFIX);
Spring DSL:
<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>
126.2.4. delete のサンプル:
Java DSL の場合
from("direct:delete") .setHeader(HazelcastConstants.OPERATION, constant(HazelcastOperation.DELETE)) .toF("hazelcast-%sfoo", HazelcastConstants.MAP_PREFIX);
Spring DSL:
<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>
126.2.5. query のサンプル
Java DSL の場合
from("direct:query") .setHeader(HazelcastConstants.OPERATION, constant(HazelcastOperation.QUERY)) .toF("hazelcast-%sfoo", HazelcastConstants.MAP_PREFIX) .to("seda:out");
Spring DSL:
<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>
クエリー操作の場合、Hazelcast は、分散マップをクエリーするための SQL のような構文を提供します。
String q1 = "bar > 1000"; template.sendBodyAndHeader("direct:query", null, HazelcastConstants.QUERY, q1);