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:
- 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
- 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
- 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();