GemFire Support Spring Integration provides support for VMWare vFabric GemFire
Introduction VMWare vFabric GemFire (GemFire) is a distributed data management platform providing a key-value data grid along with advanced distributed system features such as event processing, continuous querying, and remote function execution. This guide assumes some familiarity with GemFire and its API. Spring integration provides support for GemFire by providing inbound adapters for entry and continuous query events, and an outbound adapter to write entries to the cache. Spring integration leverages the Spring Gemfire project, providing a thin wrapper over its components. To configure the 'int-gfe' namespace, include the following elements within the headers of your XML configuration file:
Inbound Channel Adapter The inbound-channel-adapter produces messages on a channel triggered by a GemFire EntryEvent. GemFire generates events whenever an entry is CREATED, UPDATED, DESTROYED, or INVALIDATED in the associated region. The inbound channel adapter allows you to filter on a subset of these events. For example, you may want to only produce messages in response to an entry being CREATED. In addition, the inbound channel adapter can evaluate a SpEL expression if, for example, you want your message payload to contain an event property such as the new entry value. ]]> In the above configuration, we are creating a GemFire Cache and Region using Spring GemFire's 'gfe' namespace. The inbound-channel-adapter requires a reference to the GemFire region for which the adapter will be listening for events. Optional attributes include cache-events which can contain a comma separated list of event types for which a message will be produced on the input channel. By default all event types are enabled. Note that this adapter conforms to Spring integration conventions. If no channel attribute is provided, the channel will be created from the id attribute. This adapter also supports an error-channel. If expression is not provided the message payload will be a GemFire EntryEvent
Continuous Query Inbound Channel Adapter The cq-inbound-channel-adapter produces messages a channel triggered by a GemFire continuous query or CqEvent event. Spring GemFire introduced continuous query support in release 1.1, including a QueryListenerContainer which provides a nice abstraction over the GemFire native API. This adapter requires a reference to a QueryListenerContainer, and creates a listener for a given query and executes the query. The continuous query acts as an event source that will fire whenever its result set changes state. GemFire queries are written in OQL and are scoped to the entire cache (not just one region). Additionally, continuous queries require a remote (i.e., running in a separate process or remote host) cache server. Please consult the GemFire documentation for more information on implementing continuous queries. ]]> In the above configuration, we are creating a GemFire client cache (recall a cache server is required for this implementation and its address is configured as a sub-element of the pool), a client region and a QueryListenerContainer using Spring GemFire. The continuous query inbound channel adapter requires a query-listener-container attribute which contains a reference to the QueryListenerContainer. Optionally, it accepts an expression attribute which uses SpEL to transform the CqEvent or extract an individual property as needed. The cq-inbound-channel-adapter also supports a query-events attribute, containing a comma separated list of event types for which a message will be produced on the input channel (all events are enabled by default), query-name which provides an optional query name, and expression which works as described in the above section. Note that this adapter conforms to Spring integration conventions. If no channel attribute is provided, the channel will be created from the id attribute. This adapter also supports an error-channel
Outbound Channel Adapter The outbound-channel-adapter writes cache entries mapped from the message payload. In its simplest form, it expects a payload of type java.util.Map and puts the map entries into its configured region. ]]> Given the above configuration, an exception will be thrown if the payload is not a Map. Additionally, the outbound channel adapter can be configured to create a map of cache entries using SpEL of course. ]]> In the above configuration, the inner element cache-entries is semantically equivalent to Spring 'map' element. The adapter interprets the key and value attributes as SpEL expressions with the message as the evaluation context. Note that this contain arbitrary cache entries (not only those derived from the message) and that literal values must be enclosed in single quotes. In the above example, if the message sent to cacheChannel has a String payload with a value "Hello", two entries [HELLO:hello, foo:bar] will be written (created or updated) in the cache region. This adapter also supports the order attribute which may be useful if it is bound to a PublishSubscribeChannel.