# Voldemort Adapter

The Voldemort extension for Spring Integration provides:

- Outbound Channel Adapter

- Inbound Channel Adapter

- Message Store

Each one of the components listed above requires to pass an implementation of voldemort.client.StoreClient as constructor parameter. This way Voldemort Adapter does not need to introduce all configuration options required to build native store client and enables developers to choose the concrete implementation of hereby interface.

    <bean id="config" class="voldemort.client.ClientConfig">
        <property name="bootstrapUrls" value="tcp://localhost:6666" />
    <bean>

    <bean id="clientFactory" class="voldemort.client.SocketStoreClientFactory" destroy-method="close">
        <constructor-arg name="config" ref="config" />
    </bean>

    <bean id="storeClient" factory-bean="clientFactory" factory-method="getStoreClient">
        <constructor-arg value="test-store" />
    </bean>

## Common Configuration Attributes

Certain configuration parameters that are shared amongst inbound and outbound adapters have been described below.

### Common Adapter Attributes

Attribute Name | Description
--- | ---
`id` | Identifies the underlying Spring bean definition, which is an instance of either `EventDrivenConsumer` or `PollingConsumer` depending on whether the component's input channel is a `SubscribableChannel` or `PollableChannel`. Optional.
`channel` | Reference to a message channel that will be utilized to "receive from" or "send to" messages depending on the adapter type (e.g. inbound or outbound). Required.
`store-client` | Native Voldemort store client (implementation of voldemort.client.StoreClient interface). Required.
`auto-startup` | Lifecycle attribute signaling if this component should be started during application context startup. Defaults to `true`. Optional.

## Outbound Channel Adapter

The Voldemort Outbound channel adapter allows to persist data transferred through message channel in the underlying key-value store.

    <int-voldemort:outbound-channel-adapter id="voldemortOutbound"
                                            channel="voldemortOutboundChannel"
                                            store-client="storeClient"
                                            store-key="constant-key"
                                            store-key-expression="payload.id"
                                            persist-mode="DELETE"
                                            order="1"
                                            auto-startup="true" />

Specifies the key for Voldemort store. If an expression is needed, use `store-key-expression` attribute. Both options are mutually exclusive. Required.

Spring Expression Language statement used to determine desired entry key in Voldemort store. Default expression equals `headers.voldemort_key` (see `VoldemortHeaders.KEY`). This option is mutually exclusive with `store-key` attribute. Required.

Defines default persist mode for outbound channel adapter. Normally values are added or updated in the Voldemort database. Hereby behavior can be overridden on a message level using `VoldemortHeaders.PERSIST_MODE` header (see `PersistMode` enumeration). Supported options: `PUT` or `DELETE`. Optional.

Specifies the order for invocation when this endpoint is connected as a subscriber to SubscribableChannel. Optional.

## Inbound Channel Adapter

An inbound channel adapter allows to poll records from the Voldemort database and process them inside Spring Integration flow.

    <int-voldemort:inbound-channel-adapter id="voldemortInbound"
               channel="voldemortInboundChannel"
               store-client="storeClient"
               message-converter="messageConverter"
               search-key="lukasz"
               search-key-expression="@keyProducer.value"
               delete-after-poll="true"
               extract-value="true"
               auto-startup="true" />

String key that is being searched. This option is mutually exclusive with `search-key-expression` attribute. Required.

Spring Expression Language statement that returns desired entry key. Useful for keys of non string type. This option is mutually exclusive with `search-key` attribute. Required.

Indicates whether returned object should be removed from Voldemort database after polling into Spring Integration channel. Defaults to `false`. Optional.

Flag controlling value extraction from Voldemort's `voldemort.versioning.Versioned` object. Defaults to `true`. Optional.

## Message Store

Message Store allows to persist Spring Integration messages in Voldemort database. Hereby module provides `VoldemortMessageStore` which is an implementation of both the `MessageStore` strategy (mainly used by QueueChannel and ClaimCheck patterns) and the `MessageGroupStore` strategy (mainly used by Aggregator and Resequencer patterns).

    <bean id="voldemortMessageStore" class="org.springframework.integration.voldemort.store.VoldemortMessageStore">
        <constructor-arg name="client" ref="storeClient" />
    </bean>

    <int:aggregator input-channel="inputChannel" output-channel="outputChannel" message-store="voldemortMessageStore" />