34.2. Configure Cross-Datacenter Replication Programmatically

The programmatic method to configure cross-datacenter replication in Red Hat JBoss Data Grid is as follows:

Procedure 34.1. Configure Cross-Datacenter Replication Programmatically

  1. Identify the Node Location

    Declare the site the node resides in:
  2. Configure JGroups

    Configure JGroups to use the RELAY protocol:
    globalConfiguration.transport().addProperty("configurationFile", jgroups-with-relay.xml);
  3. Set Up the Remote Site

    Set up JBoss Data Grid caches to replicate to the remote site:
    ConfigurationBuilder lon = new ConfigurationBuilder();
  4. Optional: Configure the Backup Caches

    JBoss Data Grid implicitly replicates data to a cache with same name as the remote site. If a backup cache on the remote site has a different name, users must specify a backupFor cache to ensure data is replicated to the correct cache.


    This step is optional and only required if the remote site's caches are named differently from the original caches.
    1. Configure the cache in site NYC to receive backup data from LON:
      ConfigurationBuilder NYCbackupOfLon = new ConfigurationBuilder();
    2. Configure the cache in site SFO to receive backup data from LON:
      ConfigurationBuilder SFObackupOfLon = new ConfigurationBuilder();
  5. Add the Contents of the Configuration File

    As a default, Red Hat JBoss Data Grid includes JGroups configuration files such as default-configs/default-jgroups-tcp.xml and default-configs/default-jgroups-udp.xml in the infinispan-embedded-{VERSION}.jar package.
    Copy the JGroups configuration to a new file (in this example, it is named jgroups-with-relay.xml) and add the provided configuration information to this file. Note that the relay.RELAY2 protocol configuration must be the last protocol in the configuration stack.
        <!-- Additional configuration information here --> 
        <relay.RELAY2 site="LON" 
                  relay_multicasts="false" /> 
  6. Configure the relay.xml File

    Set up the relay.RELAY2 configuration in the relay.xml file. This file describes the global cluster configuration.
            <site name="LON" 
                    <bridge config="jgroups-global.xml" 
            <site name="NYC" 
                    <bridge config="jgroups-global.xml" 
            <site name="SFO" 
                    <bridge config="jgroups-global.xml" 
  7. Configure the Global Cluster

    The file jgroups-global.xml referenced in relay.xml contains another JGroups configuration which is used for the global cluster: communication between sites.
    The global cluster configuration is usually TCP-based and uses the TCPPING protocol (instead of PING or MPING) to discover members. Copy the contents of default-configs/default-jgroups-tcp.xml into jgroups-global.xml and add the following configuration in order to configure TCPPING:
        <TCP bind_port="7800" <!-- Additional configuration information here --> /> 
        <TCPPING initial_hosts="lon.hostname[7800],nyc.hostname[7800],sfo.hostname[7800]"
                 ergonomics="false" /> 
              <!-- Rest of the protocols --> 
    Replace the hostnames (or IP addresses) in TCPPING.initial_hosts with those used for your site masters. The ports (7800 in this example) must match the TCP.bind_port.
    For more information about the TCPPING protocol, refer to the JBoss Data Grid Administration and Configuration Guide.