Durable Event Messaging Example

Durable Event Messaging Example

With durable messaging configured for a client, servers save specified events in queue while the client is disconnected and then play them back when the client reconnects.

You can select which continuous queries or interest registrations are durable, so the server only queues events you really need to retain if your client goes down.

Running the Example

This example runs a server that updates its cache. It has a durable client that registers durable interest in some keys and non-durable interest in others. You start the client, stop it, and start it again while the server is updating the cache, so you can see that the durable events are saved by the server and played back when the client reconnects. The client has an asynchronous listener that reports local cache activity to standard out, so you can see what is going on.
Note: To run this example, you must have terminal sessions configured for the QuickStart examples, as described in Setting Up Your Environment for Running the Examples.
  1. In one session, start the server:

    $ java -cp "$GEMFIRE/SampleCode/quickstart/classes:$GEMFIRE/lib/server-dependencies.jar" quickstart.DurableServer
  2. In another session, start the durable client:

    $ java -cp "$GEMFIRE/SampleCode/quickstart/classes:$GEMFIRE/lib/server-dependencies.jar" quickstart.DurableClient
  3. After the client starts, press Enter in the server session once or twice to see the events arrive at the client side.

  4. Press Enter in the client session to exit the client application.

  5. When the client is stopped, in the server session, press Enter twice to create new events.

  6. Restart the client application.

    You see the events that the server stored for the durable interest played back to the client.

  7. Press Enter to exit the client again.

  8. Type exit and press Enter to exit the server.

Example Source Files

Program and cache configuration source files for the client and server, including the listener declared in the client and server xml files.

Table 1. Cache configuration files, located in SampleCode/quickstart/xml
DurableServer.xml Configures a cache to serve Durable caching clients. The example region also is configured with a loader and listener.
DurableClient.xml Configures a region as a client region in a Durable cache.

Table 2. Java program files, located in SampleCode/quickstart/quickstart
DurableServer.java The server to which the DurableClient connects
DurableClient.java The client that connects to the DurableServer.java.
SimpleCacheListener.java A CacheListener that reports cache events.

Related Javadocs

See also:
  • durable-client-id and durable-client-timeout in com.gemstone.gemfire.distributed.DistributedSystem
  • readyForEvents and close methods in com.gemstone.gemfire.cache.client.ClientCache
  • methods for registering and unregistering interest in com.gemstone.gemfire.cache.Region