135.3. 캐시 생산자 매핑 - "hazelcast-map:foo")
값을 맵에 저장하려면 맵 캐시 생산자를 사용할 수 있습니다.
맵 캐시 생산자는 CamelHazelcastOperationType 헤더로 지정된 후속 작업을 제공합니다.
- put
- putIfAbsent
- get
- getAll
- keySet
- ContainsKey
- containsValue
- 삭제
- 업데이트
- query
- 지우기
- 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");
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>
135.3.2. 제품 상세 정보: 링크 복사링크가 클립보드에 복사되었습니다!
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>
135.3.3. 업데이트를 위한 샘플: 링크 복사링크가 클립보드에 복사되었습니다!
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>
135.3.4. 삭제 샘플: 링크 복사링크가 클립보드에 복사되었습니다!
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>
135.3.5. 쿼리샘플 링크 복사링크가 클립보드에 복사되었습니다!
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);