Dynamic Replication agent | Community
Skip to main content
Level 5
March 14, 2023
Solved

Dynamic Replication agent

  • March 14, 2023
  • 2 replies
  • 954 views

Hi Experts,

 

AEM 6.5.10

 

1) Is there any way to create Replication agent through some APIs?

 

2) Is there any way programmatically to enable/disable Replication agent?

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
Best answer by lukasz-m

Hi @arvind-1,

Replication agents configuration are represented as a normal pages in AEM stored under specific location. Base on that please find answers for your questions:


1) Is there any way to create Replication agent through some APIs?

There is no specific API, however you can create replication agent using one of following options:

  1. Via GUI in AEM, all steps are described in details under below documentation:
    https://experienceleague.adobe.com/docs/experience-manager-65/deploying/configuring/replication.html?lang=en#configuring-your-replication-agents
  2. Via cURL, and again all the details you can find in official documentation:
    https://experienceleague.adobe.com/docs/experience-manager-65/administering/operations/curl.html?lang=en#create-an-agent
  3. Programmatically, using JCR, Sling and/or AEM java API. Below is a sample code snippet that is using PageManager, it's because as it has been written at the beginning Replication Agent is represented by page and PageManager is dedicated way of creating new page from code.
    import com.day.cq.wcm.api.PageManager; import com.day.cq.wcm.api.Page; import org.apache.sling.api.resource.ModifiableValueMap; PageManager pm = resourceResolver.adaptTo(PageManager.class); Page p = pm.create("/etc/replication/agents.author", "custom-agent", "/libs/cq/replication/templates/agent", "Custom agent", true); ModifiableValueMap mvm = p.getContentResource().adaptTo(ModifiableValueMap.class); // all props are String type mvm.put("enabled", "false"); mvm.put("logLevel", "info"); mvm.put("retryDelay", "60000"); mvm.put("serializationType", "durbo"); // encrypted admin password mvm.put("transportPassword", "{DES}8aadb625ced91ac483390ebc10640cdf"); mvm.put("transportUri", "http://localhost:4503/bin/receive?sling:authRequestLogin=1"); mvm.put("transportUser", "admin"); // ... place for other props, depending on agent type resourceResolver.commit();

2) Is there any way programmatically to enable/disable Replication agent?


Yes, it is possible. Similar to above case you can utilize JCR, Sling and/or AEM java API, like that:

import com.day.cq.wcm.api.PageManager; import com.day.cq.wcm.api.Page; import org.apache.sling.api.resource.ModifiableValueMap; PageManager pm = resourceResolver.adaptTo(PageManager.class); Page p = pm.getPage("/etc/replication/agents.author/publish"); ModifiableValueMap mvm = p.getContentResource().adaptTo(ModifiableValueMap.class); // boolean value, but in this specific case it is stored as a String mvm.put("enabled", "false"); resourceResolver.commit();

2 replies

Umesh_Thakur
Community Advisor
Community Advisor
March 14, 2023

) Is there any way to create Replication agent through some APIs?--- what do you mean?

 

2) Is there any way programmatically to enable/disable Replication agent?

Yes you can, but will be helpful if you can refine your requirement.

lukasz-m
Community Advisor
lukasz-mCommunity AdvisorAccepted solution
Community Advisor
March 14, 2023

Hi @arvind-1,

Replication agents configuration are represented as a normal pages in AEM stored under specific location. Base on that please find answers for your questions:


1) Is there any way to create Replication agent through some APIs?

There is no specific API, however you can create replication agent using one of following options:

  1. Via GUI in AEM, all steps are described in details under below documentation:
    https://experienceleague.adobe.com/docs/experience-manager-65/deploying/configuring/replication.html?lang=en#configuring-your-replication-agents
  2. Via cURL, and again all the details you can find in official documentation:
    https://experienceleague.adobe.com/docs/experience-manager-65/administering/operations/curl.html?lang=en#create-an-agent
  3. Programmatically, using JCR, Sling and/or AEM java API. Below is a sample code snippet that is using PageManager, it's because as it has been written at the beginning Replication Agent is represented by page and PageManager is dedicated way of creating new page from code.
    import com.day.cq.wcm.api.PageManager; import com.day.cq.wcm.api.Page; import org.apache.sling.api.resource.ModifiableValueMap; PageManager pm = resourceResolver.adaptTo(PageManager.class); Page p = pm.create("/etc/replication/agents.author", "custom-agent", "/libs/cq/replication/templates/agent", "Custom agent", true); ModifiableValueMap mvm = p.getContentResource().adaptTo(ModifiableValueMap.class); // all props are String type mvm.put("enabled", "false"); mvm.put("logLevel", "info"); mvm.put("retryDelay", "60000"); mvm.put("serializationType", "durbo"); // encrypted admin password mvm.put("transportPassword", "{DES}8aadb625ced91ac483390ebc10640cdf"); mvm.put("transportUri", "http://localhost:4503/bin/receive?sling:authRequestLogin=1"); mvm.put("transportUser", "admin"); // ... place for other props, depending on agent type resourceResolver.commit();

2) Is there any way programmatically to enable/disable Replication agent?


Yes, it is possible. Similar to above case you can utilize JCR, Sling and/or AEM java API, like that:

import com.day.cq.wcm.api.PageManager; import com.day.cq.wcm.api.Page; import org.apache.sling.api.resource.ModifiableValueMap; PageManager pm = resourceResolver.adaptTo(PageManager.class); Page p = pm.getPage("/etc/replication/agents.author/publish"); ModifiableValueMap mvm = p.getContentResource().adaptTo(ModifiableValueMap.class); // boolean value, but in this specific case it is stored as a String mvm.put("enabled", "false"); resourceResolver.commit();