= Hazelcast Replicated Map Component
:doctitle: Hazelcast Replicated Map
:shortname: hazelcast-replicatedmap
:artifactid: camel-hazelcast
:description: Perform operations on Hazelcast replicated map.
:since: 2.16
:supportlevel: Stable
:component-header: Both producer and consumer are supported
//Manually maintained attributes
:group: Hazelcast
:camel-spring-boot-name: hazelcast

*Since Camel {since}*

*{component-header}*

The http://www.hazelcast.com/[Hazelcast] instance component is one of Camel Hazelcast Components which allows you to consume join/leave events of the cache instance in the cluster.
A replicated map is a weakly consistent, distributed key-value data structure with no data partition.
 
 
// component-configure options: START

// component-configure options: END

// component options: START
include::partial$component-configure-options.adoc[]
include::partial$component-endpoint-options.adoc[]
// component options: END

// endpoint options: START

// endpoint options: END


== replicatedmap cache producer

The replicatedmap producer provides 6 operations:

* put
* get
* delete
* clear
* containsKey
* containsValue

// component headers: START
include::partial$component-endpoint-headers.adoc[]
// component headers: END

=== Sample for *put*:

Java DSL:

[source,java]
------------------------------------------------------------------------------------
from("direct:put")
.setHeader(HazelcastConstants.OPERATION, constant(HazelcastOperation.PUT))
.to(String.format("hazelcast-%sbar", HazelcastConstants.REPLICATEDMAP_PREFIX));
------------------------------------------------------------------------------------

Spring DSL:

[source,xml]
-----------------------------------------------------------------------------------------------
<route>
    <from uri="direct:put" />
    <log message="put.."/>
    <setHeader name="hazelcast.operation.type">
        <constant>put</constant>
    </setHeader>
    <to uri="hazelcast-replicatedmap:foo" />
</route>
-----------------------------------------------------------------------------------------------

=== Sample for *get*:

Java DSL:

[source,java]
------------------------------------------------------------------------------------
from("direct:get")
.setHeader(HazelcastConstants.OPERATION, constant(HazelcastOperation.GET))
.toF("hazelcast-%sbar", HazelcastConstants.REPLICATEDMAP_PREFIX)
.to("seda:out");
------------------------------------------------------------------------------------

Spring DSL:

[source,xml]
-----------------------------------------------------------------------------------------------
<route>
    <from uri="direct:get" />
    <log message="get.."/>
    <setHeader name="hazelcast.operation.type">
        <constant>get</constant>
    </setHeader>
    <to uri="hazelcast-replicatedmap:foo" />
    <to uri="seda:out" />
</route>
-----------------------------------------------------------------------------------------------

=== Sample for *delete*:

Java DSL:

[source,java]
---------------------------------------------------------------------------------------
from("direct:delete")
.setHeader(HazelcastConstants.OPERATION, constant(HazelcastOperation.DELETE))
.toF("hazelcast-%sbar", HazelcastConstants.REPLICATEDMAP_PREFIX);
---------------------------------------------------------------------------------------

Spring DSL:

[source,xml]
-----------------------------------------------------------------------------------------------
<route>
    <from uri="direct:delete" />
    <log message="delete.."/>
    <setHeader name="hazelcast.operation.type">
        <constant>delete</constant>
    </setHeader>
    <to uri="hazelcast-replicatedmap:foo" />
</route>
-----------------------------------------------------------------------------------------------

you can call them in your test class with:

[source,java]
------------------------------------------------------------------------------------------------------------
template.sendBodyAndHeader("direct:[put|get|delete|clear]", "my-foo", HazelcastConstants.OBJECT_ID, "4711");
------------------------------------------------------------------------------------------------------------

== replicatedmap cache consumer

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:

[source,java]
--------------------------------------------------------------------------------------------------
fromF("hazelcast-%sbar", HazelcastConstants.MULTIMAP_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.REMOVED))
                .log("...removed")
                .to("mock:removed")
        .otherwise()
                .log("fail!");
--------------------------------------------------------------------------------------------------

Header Variables inside the response message:

[width="100%",cols="10%,10%,80%",options="header",]
|=======================================================================
|Name |Type |Description

|`CamelHazelcastListenerTime` |`Long` |time of the event in millis

|`CamelHazelcastListenerType` |`String` |the map consumer sets here "cachelistener"

|`CamelHazelcastListenerAction` |`String` |type of event - here *added* and *removed* (and soon *envicted*)

|`CamelHazelcastObjectId` |`String` | the oid of the object

|`CamelHazelcastCacheName` |`String` |the name of the cache - e.g. "foo"

|`CamelHazelcastCacheType` |`String` |the type of the cache - here replicatedmap
|=======================================================================


include::spring-boot:partial$starter.adoc[]
