AEM Cloud Service Replication API
Programmatic content publishing and unpublishing using the official AEM Replication API.
When to Use This Skill
Use the Replication API for programmatic content distribution:
- Custom OSGi services that publish content
- Workflow process steps requiring activation
- Automated publishing pipelines
- Integration with external systems
- Bulk operations (with proper constraints)
For UI-based publishing, use Manage Publication or Quick Publish instead.
Official API Documentation
Key Classes:
com.day.cq.replication.Replicator- Main replication servicecom.day.cq.replication.ReplicationOptions- Configuration optionscom.day.cq.replication.ReplicationStatus- Publication statuscom.day.cq.replication.ReplicationActionType- Action types (ACTIVATE, DEACTIVATE, DELETE, TEST)
Basic Replication: Single Path
Example: Activate a Page
Bulk Replication: Multiple Paths
CONSTRAINTS (per official Javadoc):
- Recommended limit: 100 paths per call for a transactional guarantee
- Above 100 paths: the system automatically splits into multiple non-transactional chunks — no extra options needed
- Payload size: 10 MB maximum (excluding binaries)
Note:
ReplicationOptions.setUseAtomicCalls()is@Deprecatedand marked "no longer required" in the Cloud Service Javadoc. Do not call it; the system handles auto-bucketing automatically.
Example: Bulk Activation
Best Practice: For large hierarchical content trees, use the Tree Activation workflow step instead of custom code.
Publishing to Preview Tier
The Preview tier requires explicit agent filtering.
Example: Publish to Preview
Note: Preview agent is disabled by default and must be configured in Cloud Manager.
Advanced Options: ReplicationOptions
Synchronous vs. Asynchronous Replication
Important: ReplicationListener only works with synchronous replication.
Suppress Status Updates
Suppress Versioning
Checking Replication Status
Example: Check if Page is Published
Batch Status Queries
Use ReplicationStatusProvider.getBatchReplicationStatus() when you need to check the publication state of multiple resources in a single call. It is more efficient than calling Replicator.getReplicationStatus() in a loop.
Javadoc: com.day.cq.replication.ReplicationStatusProvider
Required imports:
Permission Checks
Example: Validate User Can Replicate
Workflow Integration
Example: Workflow Process Step
Process Arguments (configured in workflow model):
- Can use
MetaDataMap argsto pass custom parameters like target tier
Listening to Replication Events
Use OSGi Event Handlers to react to replication events:
Event Properties:
paths- Array of replicated pathsaction- Replication action (Activate, Deactivate, etc.)userId- User who triggered replication
Best Practices
1. Respect Rate Limits
- ≤100 paths per call for transactional guarantee; system auto-splits if exceeded
- ≤10 MB payload size
2. Use Workflow for Large Operations
Don't build custom bulk publishing code. Use Tree Activation workflow step.
3. Validate Permissions
Always check permissions before replication to avoid exceptions.
4. Use Service Users
Never replicate with admin credentials. Map a sub-service name to the principal that holds crx:replicate via ServiceUserMapperImpl.amended config. Provision the principal with jcr:read + crx:replicate on /content via Repo Init scripts — see AEM Project Structure — Repo Init. See references/patterns.md [blocked] for the full service user setup example.
5. Publish Only What's Needed
Minimize replication volume to reduce queue pressure and pipeline load.
Common Patterns
See references/patterns.md [blocked] for complete implementations:
- Auto-Publish on Content Fragment Save — event-driven publish using
SlingConstants.TOPIC_RESOURCE_CHANGED - External Cache Purge After Publication — CDN invalidation via replication event handler
- Service User Setup for Replication — OSGi service user mapping and Repo Init provisioning
Troubleshooting
Issue: Replication Fails Silently
Check: Verify replication queues in Felix console (Sling Jobs console):
Look for failed jobs with topic: com/day/cq/replication
Issue: Permission Errors
Error: javax.jcr.AccessDeniedException
Solution: Verify service user has replication permissions:
Issue: Content Not Appearing
Check:
- Verify replication status:
replicator.getReplicationStatus() - Check logs for distribution errors
- Verify target tier (Preview vs. Publish)
References
- Official Javadoc: https://developer.adobe.com/experience-manager/reference-materials/cloud-service/javadoc/com/day/cq/replication/package-summary.html
- Adobe Docs: https://experienceleague.adobe.com/docs/experience-manager-cloud-service/content/operations/replication.html
- Sling Distribution: https://sling.apache.org/documentation/bundles/content-distribution.html


