Expand my Community achievements bar.

SOLVED

Dynamic Replication agent

Avatar

Level 6

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?

1 Accepted Solution

Avatar

Correct answer by
Community Advisor

Hi @arvind,

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...
  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?lan...
  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();

View solution in original post

2 Replies

Avatar

Community Advisor

) 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.

Avatar

Correct answer by
Community Advisor

Hi @arvind,

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...
  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?lan...
  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();