Replication and Sling Content Distribution in AEMaaCS

If you came from AEM 6.5, you’re used to replication agents you set up yourself, each with a queue you can open on the instance. AEM as a Cloud Service still publishes content, but the plumbing underneath has changed. Content doesn’t go straight from author to publish through a classic agent any more. It travels through Sling Content Distribution to a pipeline service on Adobe Developer, outside the AEM runtime.

That changes how you publish, how you confirm a change reached publish, and how you debug a stuck queue. Here I’ll cover the agents, the queue states, the Replication API, the Tree Activation step, and a process you can repeat whenever a queue goes red.

The examples use the project mysite, the package com.mysite.core, program 12345 and the development environment 67890.

Replication and Sling Content Distribution in AEMaaCS - AEMCQ5Tutorials

Table of contents

Why this matters

Replication is the point where an editor’s change becomes visible to visitors. When it fails quietly, author says the page is activated while the live site still serves the old version. On AEMaaCS you can’t log in to a publish node to find out why, so the Distribution console and the agent logs are all the evidence you get.

Who should read this

I wrote this for developers who publish through the Replication API, and for support teams who get the “why is my page not live?” ticket. You should already know OSGi services and how to deploy through Cloud Manager.

Prerequisites

You’ll need the mysite project, Cloud Manager access to program 12345 and author access to environment 67890. Read these first:

How replication works on AEMaaCS

Sling Content Distribution hands the content you replicate to a pipeline service on Adobe Developer. Your author instance never opens a connection to a publish instance. Once the pipeline accepts the content, it goes to every publish pod and the Dispatcher cache is cleared for the affected paths.

If you’re coming from 6.5, these are the main differences:

TopicAEM 6.5 (classic)AEM as a Cloud Service
TransportReplication agents send content to a publish instance you configureSling Content Distribution sends content to a pipeline service on Adobe Developer
AgentsYou create and edit agents under the replication configurationTwo predefined agents: publish (enabled by default) and preview (not enabled by default)
QueuesOne queue per agent, visible on each instanceTwo queues per agent (persisted and fully published), with no per-pod queues
Where you check statusTools console on the author or publish instanceTools > Deployment > Distribution on the author instance

The publish and preview agents

You get two predefined agents. The publish agent serves live visitors and is enabled by default. The preview agent feeds the preview tier that authors and reviewers use before go-live. It isn’t enabled by default, so switch it on before you try to use it.

In code, the Replication API only uses default-enabled agents. A call without a filter therefore publishes to publish and nothing else. To reach preview, pass an agent filter that matches its ID.

Note:- The overall replication status on a resource only reflects the agents that are enabled by default. A page published to preview only can show as not activated overall, so check the status for the preview agent explicitly. This one trips people up.

Replication queues: persisted and fully published

Every agent has a persisted queue and a fully published queue, and a page is only live once the fully published state catches up. On the publish agent card, I watch two values:

– Items Pending: the number of items still waiting in the queue.

– Last Item Processed: the time the queue last moved. If it stops advancing while items are still pending, the queue is stuck.

Queue stateWhat it meansWhat you do
Persisted, items pendingThe pipeline has your change and is working through the queueWait and watch Last Item Processed advance
Red statusAt least one item is failingOpen the queue, identify the failing item, and read the log for the cause
Items pending, no progressThe queue is stalledRun Test Connection, then inspect the queue head

Note:- If content can’t be published, the publication is reverted from the AEM Publish Service. Open the agent Status tab, find the queue with the red status, and look at its pending items to see what failed. You can clear single items or the whole queue.

Publishing from code with the Replication API

Call the Replicator service instead of writing your own HTTP calls to the pipeline. Keep each call under 100 paths, never more than 500 (larger calls fail with a ReplicationException), and under 10 MB of content excluding binaries. If you don’t need an atomic call, ReplicationOptions.setUseAtomicCalls(false) takes any number of paths and splits them into buckets for you. For bulk work, use the Tree Activation step described later.

The class below publishes a single path to the preview agent only. It runs as a service user rather than an administrative resource resolver, which is the pattern AEMaaCS expects. Save it as core/src/main/java/com/mysite/core/replication/PreviewPublisher.java:

package com.mysite.core.replication;

import com.day.cq.replication.AgentFilter;
import com.day.cq.replication.Agent;
import com.day.cq.replication.ReplicationActionType;
import com.day.cq.replication.ReplicationException;
import com.day.cq.replication.ReplicationOptions;
import com.day.cq.replication.Replicator;
import org.apache.sling.api.resource.LoginException;
import org.apache.sling.api.resource.Resource;
import org.apache.sling.api.resource.ResourceResolver;
import org.apache.sling.api.resource.ResourceResolverFactory;
import org.osgi.service.component.annotations.Component;
import org.osgi.service.component.annotations.Reference;

import javax.jcr.Session;
import java.util.Collections;

@Component(service = PreviewPublisher.class)
public class PreviewPublisher {

    static final String PREVIEW_AGENT_ID = "preview";
    static final String SUBSERVICE = "mysite-replication";

    @Reference
    private Replicator replicator;

    @Reference
    private ResourceResolverFactory resolverFactory;

    public void publishToPreview(String path) throws LoginException, ReplicationException {
        try (ResourceResolver resolver = resolverFactory.getServiceResourceResolver(
                Collections.singletonMap(ResourceResolverFactory.SUBSERVICE, SUBSERVICE))) {

            Resource resource = resolver.getResource(path);
            if (resource == null) {
                throw new IllegalArgumentException("No resource at " + path);
            }

            ReplicationOptions options = new ReplicationOptions();
            options.setFilter(new AgentFilter() {
                @Override
                public boolean isIncluded(Agent agent) {
                    return PREVIEW_AGENT_ID.equals(agent.getId());
                }
            });

            Session session = resolver.adaptTo(Session.class);
            replicator.replicate(session, ReplicationActionType.ACTIVATE, path, options);
        }
    }
}

The subservice name mysite-replication has to map to a real service user. Add a service user mapping in the config folder of the ui.config module, the same way you configure other OSGi services in your project:

// ui.config/src/main/content/jcr_root/apps/mysite/config/org.apache.sling.serviceusermapping.impl.ServiceUserMapperImpl.amended-mysite.cfg.json
{
  "user.mapping": [
    "mysite.core:mysite-replication=mysite-replication-service"
  ]
}

repoinit creates the user mysite-replication-service and gives it its ACLs. The security post in this module goes through that pattern in detail.

Bulk publishing with the Tree Activation step

Need to publish a subtree, like a whole site section or a language root? Use a workflow with the Tree Activation step. Adobe recommends it for bulk publishing and advises against writing your own bulk code. The step walks the tree and publishes in chunks, pauses automatically when the replication queue gets too long, and picks up where it left off if the system stops it. It takes comma-separated arguments:

ParameterDefaultWhat it does
agentIdpublishThe agent that receives the content: publish or preview
chunkSize50How many paths are bundled into one replication
maxQueueSize10The step pauses while the replication queue holds more items than this
maxTreeSize500000The maximum number of nodes for a tree to count as small
enableVersionfalseCreates a version of the content before it is published
dryRunfalseWhen true, replication is not actually called
filtersnoneonlyModified: new nodes and nodes modified since the last publish. onlyActivated: nodes that were published before the last publish

Take the argument string enableVersion=true,agentId=publish,filters=onlyModified. It publishes everything below the payload that is new or changed, and creates a version first. The payload path is the root of the walk, so there’s no argument for including children. On a large tree, I’d run it once with dryRun=true to see what it would do before replicating anything.

Hands-on: publish, verify and debug replication

The steps below use the mysite project and the development environment 67890. Each step ends with something you can check.

Step 1: Check the publish and preview agents

Log in to the author instance of environment 67890 and open Tools > Deployment > Distribution. Each agent shows up as a card. Open the publish card and check that the status tab shows the agent as enabled, then select Test Connection. A successful test means the pipeline can reach the agent. If it fails, stop here. No publish step will work until the connection does.

Next, open the preview card and confirm it’s enabled, because Step 3 depends on it.

Each agent is a card with its queue count. The panel that opens has Test Connection and Refresh in the toolbar, plus four tabs: Status, Logs, Settings and Distribute. A queue with nothing waiting shows Idle.

Note:- If your program also uses Edge Delivery Services, the Distribution page can show more agents, such as publish-edge and preview-edge. This lesson only deals with publish and preview.

Step 2: Publish a page and watch the queues

Open the Sites console, pick a page under /content/mysite/en and publish it with Quick Publish. Go back to the Distribution page and refresh the publish card. Items Pending should rise, then drop back to zero. Keep an eye on Last Item Processed, which should move forward while items are being processed.

Once the queue is empty, check the change on the live hostname. Load the page with curl and look for the text you changed:

curl -s https://www.mysite.example/content/mysite/en.html | grep -i "your changed text"

If the text is missing, check the queue states before you purge anything. Purging first just hides the clue.

Step 3: Publish to preview from a Java service

Reuse the PreviewPublisher class from the section above. Add a Sling servlet or a scheduled job that calls it with the path you want reviewers to see. It has to run as the subservice mapped in the config from the previous section. Then deploy to the development environment through the full-stack pipeline in program 12345.

When the pipeline finishes, check the preview agent status for the page. Read the status for the agent by ID, not the overall status, because the overall status ignores the preview agent:

ReplicationStatus status = resource.adaptTo(ReplicationStatus.class);
boolean previewed = status != null && status.getStatusForAgent(PREVIEW_AGENT_ID).isActivated();

Step 4: Run a Tree Activation for a subtree

Open Tools > Workflow > Models and select Create. Name the model so it’s obvious which project it belongs to, such as mysite-tree-activation, then select it and choose Edit. Delete the default step and drag a Process Step into the flow. Open its wrench icon and, on the Process tab, pick Publish Content Tree from the drop-down. That’s the label the Tree Activation process has in the list, and it isn’t the deprecated Publish Content Tree workflow. Enable Handler Advance so the workflow moves on once the step finishes, and set the arguments:

enableVersion=true,agentId=publish,filters=onlyModified

Save the model and start it on the payload /content/mysite/en.

Follow the progress under Tools > General > Jobs. The progress column shows counts such as 41/564 and moves forward each time you refresh.

Step 5: Read the logs and find the failure

Use the Logs tab on the Distribution page, or tail the logs as described in the tail logs tutorial. The step logs under the package com.day.cq.wcm.workflow.process.impl.treeactivation, and the last entry before an error tells you where it stopped.

The Logs tab is a plain text log. When a publish reaches the pipeline, you’ll see a line like this (shortened):

2026/12/01 09:15:02:877 - INFO - Request accepted with distribution package PackageMessage(reqType=ADD, pkgType=journal_filevault, pubAgentName=publish, userId=replication-service, paths=[/content/mysite/en/home], ...) at offset=90939948, queueSize=1, queueSizeDelay=0

reqType shows the action, such as ADD or DELETE, and paths shows what was sent. If there’s no Request accepted line for your path, the request never left author.

For more detail on the workflow step, raise the log level of that package with a Sling logging factory configuration in ui.config. The file name has a dash before the instance name:

// ui.config/src/main/content/jcr_root/apps/mysite/config/org.apache.sling.commons.log.LogManager.factory.config-mysite-replication.cfg.json
{
  "org.apache.sling.commons.log.level": "debug",
  "org.apache.sling.commons.log.names": ["com.day.cq.wcm.workflow.process.impl.treeactivation"]
}

Remove this configuration once you’re done debugging. Debug output is heavy.

Step 6: Clear a red queue item

When the publish card turns red, open the queue and note the path, time and error of the item at the head. Fix the cause first, for example a missing service user ACL or a path that no longer exists. Then clear that one item. Only clear the whole queue if you’re fine with losing the publishes waiting behind it. Afterwards, publish the affected paths again and confirm them on the live hostname.

Common mistakes and troubleshooting

Most replication problems fall into a handful of groups. Go through the table from the top before you touch any code.

SymptomLikely causeWhat to check or do
Author shows the page as published, live still shows old textThe fully published state has not caught up, or the Dispatcher still holds the old pageCheck both queue states, then invalidate the cache from author as described in the Dispatcher and CDN troubleshooting lesson
Items Pending keeps rising, Last Item Processed does not moveThe queue is stalled behind a failing itemRun Test Connection, then open the queue and inspect the item at the head
Publish card is redAt least one item is failingOpen the queue, read the error for the failing item, fix the cause, then clear and republish
A Quick Publish did not update previewQuick Publish sends content to the publish agentPublish to preview with the preview agent filter, or use the Tree Activation step with agentId=preview
Overall status says not activated after a preview-only publishThe overall status ignores agents that are not enabled by defaultRead the status for the preview agent by ID
Tree Activation fails in the middle of a runA path is missing, a service user lacks ACLs, or a batch failedRead the first error in the log and the wrapped exception, then check the ACLs of the service user

Comparison: which publishing method to use

Pick the method based on the size of the change and who starts it. Editors use the authoring UI. Developers use code or workflows.

MethodScopeAgentsBest for
Quick Publish from the Sites consoleOne page or a small selectionPublish agentEditors publishing a page they just finished
Manage PublicationSelected pages, with optionsPublish agentEditors who need to choose what goes live together
Tree Activation workflow stepA subtree, in batchesAny agent you select with agentIdLarge sections, language roots, scheduled bulk publishing
Replication API (Replicator)Up to 100 paths per callPublish by default, preview with an AgentFilterCustom features that publish on a user action

Hands-on challenge

Add a Sling servlet at /bin/mysite/publish-status that takes a content path and returns JSON with two flags: activated on publish, and activated on preview. Publish one page to preview only with PreviewPublisher, then check that the servlet reports preview true and publish false for it. After that, break the service user mapping on purpose, deploy to environment 67890, and see whether the servlet’s error message is clear enough for an editor to report. Put the mapping back when you’re done.

Key takeaways

✅ Sling Content Distribution sends content to a pipeline on Adobe Developer, so author never talks directly to a publish node.
✅ There are two predefined agents: publish is on by default, preview isn’t.
✅ Each agent has persisted and fully published queues, and a page is live only once the fully published state catches up.
✅ Use the Replication API for small, targeted calls (under 100 paths each) and the Tree Activation step for subtrees.
✅ If the queue stalls, read the first failing item and its log line before you clear anything.

Knowledge check

Which agents does a Replication API call use when no agent filter is set?

Only the publish agent. The API uses only agents enabled by default, and preview isn’t one of them.

Which queue state tells you that visitors can see the change?

The fully published queue. Persisted only means the pipeline stored the change. Fully published means it reached every publish pod.

What is the recommended upper limit for paths per Replicator call, and what happens above the hard limit?

Keep each call under 100 paths. The hard limit is 500, and larger calls fail with a ReplicationException.

Why should you use the Tree Activation step for a subtree instead of your own loop?

The step walks the tree, chunks the content and logs each batch. If you write your own loop, you have to rebuild all three, and it’s easy to blow past the path and size limits.

A queue is red. What should you do before you clear anything?

Open the queue, read the error on the failing item and fix the cause. If you clear before you know why it failed, you hide the problem and may drop publishes you still need.

Frequently asked questions

Can I add classic replication agents on AEMaaCS, as I did on 6.5?

The documented model is the two predefined agents, publish and preview. Plan around those, not around the custom agents you had in 6.5.

Is there a replication queue on each publish pod?

No. Queues belong to the agent, not to a pod. You see the persisted and fully published states on the Distribution console.

Why does my overall status say not activated after I published to preview?

The overall status ignores agents that aren’t enabled by default, so read the status for the preview agent by its ID.

Continue your learning

References

Spread the love

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.