Cross site and cross applications with Red Hat OpenShift and Red Hat Data Grid

Learn how to develop applications using Quarkus, .NET Core 7, and Golang that are distributed in two different Red Hat OpenShift clusters and share data with each other through Red Hat Data Grid via cross-site replication.

Let's create a cache called employees, this cache will be used by the sample applications to share employee records across sites.

Configure cache in site-1

  1. On the Data Grid operator page, select the Cache tab then Create Cache (Figure 7).
    Select Cache tab in Data Grid Operator
    Figure 7: Select Cache tab in Data Grid Operator.
  2. Select the configure via: YAML view and use the content below as an example:
  3. apiVersion: infinispan.org/v2alpha1
    kind: Cache
    metadata:
      name: employees
      namespace: rhdg-xsite
    spec:
      clusterName: dg
      name: employees
      template: |
        replicatedCache:
          mode: "ASYNC"
          statistics: "true"
          encoding:
            key:
              mediaType: "text/plain; charset=UTF-8"
            value:
              mediaType: "application/json; charset=UTF-8"
          locking:
            isolation: "REPEATABLE_READ"
            acquireTimeout: "0"
          expiration:
            lifespan: "600000"
            maxIdle: "300000"
          backups:
            site-2:
              backup:
                strategy: "SYNC"
                takeOffline:
                  minWait: "120000"
      updates:
        strategy: retain
    
  4. Note: The above cache is configured to: 
    • Objects stored in the cache have a string key.
    •  Objects stored in the cache have the application/json format
    • Keep objects in the cache for a maximum of 10 minutes.
    • If the objects are not accessed for a period of 5 minutes, they will be removed from the cache.
    • Objects are replicated to the backup site, in this case to the cache configured on site-2.
  5. Click Create.

Configure cache in site-2

  1. Repeat step 1 shown for site-1.
  2. For step 2, use the example below to create the cache, then select Create:
    apiVersion: infinispan.org/v2alpha1
    kind: Cache
    metadata:
      name: employees
      namespace: rhdg-xsite
    spec:
      clusterName: dg
      name: employees
      template: |
        replicatedCache:
          mode: "ASYNC"
          statistics: "true"
          encoding:
            key:
              mediaType: "text/plain; charset=UTF-8"
            value:
              mediaType: "application/json; charset=UTF-8"
          locking:
            isolation: "REPEATABLE_READ"
            acquireTimeout: "0"
          expiration:
            lifespan: "600000"
            maxIdle: "300000"
          backups:
            site-1:
              backup:
                strategy: "SYNC"
                takeOffline:
                  minWait: "120000"
      updates:
        strategy: retain

Our cluster is now configured with a cache capable of replicating data between different OpenShift clusters.

Previous resource
Overview: Cross site and cross applications with Red Hat OpenShift and Red Hat Data Grid
Next resource
The sample application