Replicated Caching Example

Replicated Caching Example

Replicated caching gives you a complete copy of your data in each member in the distributed system that hosts the replicated region.

Any change made by any distributed system member is automatically forwarded into the replicated region. You can use this to keep a complete copy in one place for such things as high availability and synchronization with an outside data store. In a client/server installation, backup servers that replicate primary server data can take over when the primary fails, with no data loss. Read more about replicated regions in Distributed and Replicated Regions.

Running the Example

This example shows a producer/consumer system. The producer acts as a data feed, putting data into the region using a replicated proxy. A replicated proxy does not store anything in its own cache but sends it to any replicated regions it finds in its distributed system.

The consumer region is configured as replicated so anything the producer adds or updates is automatically copied to the consumer. The consumer region has a listener that reports all updates to standard out, so you can see when the copies arrive. A GemFire cache listener handles changes to the data region.

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 terminal session, start the consumer:

    $ java -cp "$GEMFIRE/lib/server-dependencies.jar:$GEMFIRE/SampleCode/quickstart/classes" quickstart.PushConsumer
  2. After that session starts, in another session, start the producer:

    $ java -cp "$GEMFIRE/lib/server-dependencies.jar:$GEMFIRE/SampleCode/quickstart/classes" quickstart.PushProducer

Example Source Files

Program and cache configuration source files for the producer and consumer, including the listener,, declared in the PushConsumer.xml file.

Table 1. Cache configuration files, located in SampleCode/quickstart/xml
PushProducer.xml Configures a producer region for a data replication example.
PushConsumer.xml Configures a consumer region for a data replication example.

Table 2. Java program files, located in SampleCode/quickstart/quickstart Puts data into the region using a replicated proxy. Automatically copies producer updates. A CacheListener that reports consumer cache events.

Related Javadocs

See also:
  • com.gemstone.gemfire.cache.CacheFactory
  • com.gemstone.gemfire.cache.Cache
  • com.gemstone.gemfire.cache.Region
  • REPLICATE and REPLICATE_PROXY in com.gemstone.gemfire.cache.RegionShortcut