How to Create a Cluster Aware OSGi Service


How do I create an OSGi service that is aware of whether it is running on a CQ5/CRX cluster slave node or a master node?


In CQ5, you can use the ClusterAware interface which will automatically handle periodically checking the descriptor for you.  This makes things easier if the node is elected as master:


import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

@Component(metatype = false, policy = ConfigurationPolicy.IGNORE)
public class MyClusterAwareService implements ClusterAware {
  public void unbindRepository() {"No Repository is bound or Repository is unbound");

  public void bindRepository(String repositoryId, String clusterId, boolean isMaster) {"Bound to Repository {} Node {} (Cluster: {})",
      new Object[] { (isMaster ? "Master" : "Slave"), repositoryId, clusterId });

  private void doSomething(boolean isMaster) {
    //TODO: your code here

Note: the ClusterAware feature only applies to CQ5.3 with Feature Pack 34071 installed, CQ5.4 or later version.

Applies to

CQ 5.3

CQ 5.4

CRX 2.1

CRX 2.2

** If you want to use this in CQ5.3 you need 5.3 Feature Pack 34071 and CRX hotfix  If you don't have these hotfixes then you can request them via daycare.


AEM 5.6.1 onward use new topology api. Details at


Få hjälp snabbare och enklare

Ny användare?