DEV Community

jerinraj5555
jerinraj5555

Posted on • Updated on

Replication in AEM(Adobe Experience Manager)

Replication is a process of activating/publishing a page and it's content from author to publish environment. AEM provide replication API to build a custom step that replicates content from the Author instance to the Publisher instance.

Replication using Replicator API
Initially, We need to create a Replicator instance by using @Reference annotation.

@Reference
private Replicator replicator;
Enter fullscreen mode Exit fullscreen mode

Next, We need to create a session instance and then pass this object to replicate API. Here I have shared a sample code snippet for creating a session instance.

ResourceResolver resolver = request.getResourceResolver();
        session = resolver.adaptTo(Session.class);
Enter fullscreen mode Exit fullscreen mode

Finally, we need to pass the session instance and path to the replication API.
Here I have shared an example that will activate/deactivate web page based on a flag.

  private void managePageActivation(Session session, String path,boolean isReplicate) 
     {

    try {
            if (isReplicate) {
                replicator.replicate(session, ReplicationActionType.ACTIVATE, path);
                log.info("Page activated: ", path);
            } else {
                replicator.replicate(session, ReplicationActionType.DEACTIVATE, path);
                log.info("Page De-activated: ", path);
            }

    } catch (ReplicationException e) {
            log.info("Replication failed "+e.getMessage(), path);
            e.printStackTrace();
    }
}

Enter fullscreen mode Exit fullscreen mode

In the above function will do the following things,

  • The function will accept session instance, web page link and status for identifying which operation to be performed(Activation or Deactivation). The path is look like this /content/your-project/xxxx/en/user

  • Then we will call the replicate(Session session, ReplicationActionType type, String path) to replicate the content to the publish instance.
  • In my next post, I will explain how to activate/deactivate the content(asset and web page) by reading the path from an excel file.

    I would like to hear your thoughts and suggestions from you to make it better.

    Top comments (1)

    Collapse
     
    leka profile image
    ABASK05

    Thanks for the post. i wanna replicate folder and its sub pages. i am sending the folder path in replicate method, but its not activating the sub pages, how can i achieve that? could u pls help