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.
\n\nReplication using Replicator API
\nInitially, We need to create a Replicator instance by using @Reference annotation.
\n
@Reference\nprivate Replicator replicator;\n
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.
\n
ResourceResolver resolver = request.getResourceResolver();\n session = resolver.adaptTo(Session.class);\n
Finally, we need to pass the session instance and path to the replication API.
\nHere I have shared an example that will activate/deactivate web page based on a flag.
\n
private void managePageActivation(Session session, String path,boolean isReplicate) \n {\n\n try {\n if (isReplicate) {\n replicator.replicate(session, ReplicationActionType.ACTIVATE, path);\n log.info("Page activated: ", path);\n } else {\n replicator.replicate(session, ReplicationActionType.DEACTIVATE, path);\n log.info("Page De-activated: ", path);\n }\n\n } catch (ReplicationException e) {\n log.info("Replication failed "+e.getMessage(), path);\n e.printStackTrace();\n }\n}\n\n
In the above function will do the following things,
\n
\nThen we will call the replicate(Session session, ReplicationActionType type, String path) to replicate the content to the publish instance.\n\n
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.
\n\nI would like to hear your thoughts and suggestions from you to make it better.
\n\n\n