= Hazelcast Multimap Component
:doctitle: Hazelcast Multimap
:shortname: hazelcast-multimap
:artifactid: camel-hazelcast
:description: Perform operations on Hazelcast distributed multimap.
:since: 2.7
: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] Multimap component is one of Camel Hazelcast Components which allows you to access Hazelcast distributed multimap.


== Options

// 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


== 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:

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

|`CamelHazelcastOperationType` |`String` |valid values are: put, get, removevalue, delete, clear.

|`CamelHazelcastObjectId` |`String` |the object id to store / find your object inside the cache
|=======================================================================

=== Sample for *put*:

Java DSL:

[source,java]
------------------------------------------------------------------------------------
from("direct:put")
.setHeader(HazelcastConstants.OPERATION, constant(HazelcastOperation.PUT))
.to(String.format("hazelcast-%sbar", HazelcastConstants.MULTIMAP_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-multimap:foo" />
</route>
-----------------------------------------------------------------------------------------------

=== Sample for *removevalue*:

Java DSL:

[source,java]
--------------------------------------------------------------------------------------------
from("direct:removevalue")
.setHeader(HazelcastConstants.OPERATION, constant(HazelcastOperation.REMOVE_VALUE))
.toF("hazelcast-%sbar", HazelcastConstants.MULTIMAP_PREFIX);
--------------------------------------------------------------------------------------------

Spring DSL:

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

To remove a value you have to provide the value you want to remove
inside the message body. If you have a multimap object
\{`key: "4711" values: { "my-foo", "my-bar"`}} you have to put "my-foo"
inside the message body to remove the "my-foo" value.

=== Sample for *get*:

Java DSL:

[source,java]
------------------------------------------------------------------------------------
from("direct:get")
.setHeader(HazelcastConstants.OPERATION, constant(HazelcastOperation.GET))
.toF("hazelcast-%sbar", HazelcastConstants.MULTIMAP_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-multimap: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.MULTIMAP_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-multimap:foo" />
</route>
-----------------------------------------------------------------------------------------------

you can call them in your test class with:

[source,java]
------------------------------------------------------------------------------------------------------------------
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:

[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 multimap
|=======================================================================


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