This project demonstrates how JGroups cluster members discover each other using different discovery protocols.
JGroups is a toolkit for reliable messaging and cluster communication. Before members can exchange messages they must form a cluster, which requires each member to locate the others — a process called discovery.
Two cloud-specific discovery protocols are demonstrated:
-
DNS_PING(recommended) — performs a DNS A-record lookup against a headless KubernetesService, which returns one IP address per matching pod. Requires no API server access, only a headless service. -
KUBE_PING— queries the Kubernetes API for pods matching a label selector in the same namespace. Requires aServiceAccountwith permission to list pods, but needs no additional network infrastructure.
Each example runs a small application that joins a JGroups cluster and broadcasts a hello message every 5 seconds. View changes (members joining or leaving) are logged, making it easy to observe discovery and cluster formation in action.
Project requires JDK 25 to build.
./mvnw clean installThis builds the following images:
-
jgroups/jgroups-discovery-examples-dns-ping— TCP stack withDNS_PINGdiscovery -
jgroups/jgroups-discovery-examples-kube-ping— TCP stack withKUBE_PINGdiscovery
The following system properties control the application behaviour:
| Property | Default | Description |
|---|---|---|
|
|
Classpath path to the JGroups stack configuration file. |
|
|
Name of the JGroups cluster to join. |
These examples target OpenShift Local (CRC). Installing CRC guide.
-
Start OpenShift Local:
crc start
-
Configure the shell and log in:
eval $(crc oc-env) oc login -u developer -p developer https://api.crc.testing:6443
-
Create a project (replace
jgroups-discovery-exampleswith your preferred namespace throughout):oc new-project jgroups-discovery-examples
-
Build and publish the images to Quay.io:
./mvnw clean install podman login quay.io podman tag jgroups/jgroups-discovery-examples-dns-ping:0.0.1.Final-SNAPSHOT quay.io/rhusar/jgroups-discovery-examples-dns-ping:latest podman push quay.io/rhusar/jgroups-discovery-examples-dns-ping:latest podman tag jgroups/jgroups-discovery-examples-kube-ping:0.0.1.Final-SNAPSHOT quay.io/rhusar/jgroups-discovery-examples-kube-ping:latest podman push quay.io/rhusar/jgroups-discovery-examples-kube-ping:latest
NoteQuay.io repositories are private by default when first created. After pushing, make each repository public via Repository Settings → Repository Visibility → Public so OpenShift can pull the images without a pull secret.
KUBE_PING discovers cluster members by querying the Kubernetes API for pods in the namespace
matching a label selector. A ServiceAccount with a Role granting get/list on pods is required.
-
Apply the resources:
oc apply -f KUBE_PING/ServiceAccount.yaml oc apply -f KUBE_PING/Role.yaml oc apply -f KUBE_PING/RoleBinding.yaml oc apply -f KUBE_PING/Deployment.yaml
-
Verify the pod is running and check logs:
oc get pods oc logs -f deployment/jgroups-discovery-examples-kube-ping
-
Scale up to see cluster formation:
oc scale deployment jgroups-discovery-examples-kube-ping --replicas=3 oc logs -f deployment/jgroups-discovery-examples-kube-ping
-
Clean up:
oc delete -f KUBE_PING/Deployment.yaml oc delete -f KUBE_PING/RoleBinding.yaml oc delete -f KUBE_PING/Role.yaml oc delete -f KUBE_PING/ServiceAccount.yaml
DNS_PING discovers cluster members by performing a DNS query against a headless Kubernetes service,
which returns an A record per pod. No API server access is required.
-
Apply the resources:
oc apply -f DNS_PING/Service.yaml oc apply -f DNS_PING/Deployment.yaml
-
Verify the pod is running and check logs:
oc get pods oc logs -f deployment/jgroups-discovery-examples-dns-ping
-
Scale up to see cluster formation:
oc scale deployment jgroups-discovery-examples-dns-ping --replicas=3 oc logs -f deployment/jgroups-discovery-examples-dns-ping
Each new pod should trigger a view change logged across all members.
-
Clean up:
oc delete -f DNS_PING/Deployment.yaml oc delete -f DNS_PING/Service.yaml