Friday, May 22, 2020

Sling Content Distribution in AEM (Part 1) — Forward Distribution

The Sling Content Distribution (SCD) module allows one to distribute Sling resources between different Sling instances. This can be used to distribute/sync content between AEM Author and Publishers for different scenarios.

In this tutorial let us see how to enable sling content distribution to distribute/sync content between AEM author and publishers.


  • allowing distribution of content among different Sling instances.
  • "distribution" - the ability of picking one or more resources on a certain Sling instance in order to copy and persist them onto another Sling instance. 
  • The Sling Content Distribution module is able to distribute content by:
"pushing" from Sling instance A to Sling instance B - Forward distribution
"pulling" from Sling instance B to Sling instance A - Reverse distribution
"synchronizing" Sling instances A and B via a (third) coordinating instance - Sync distribution
  • Agent - creating one or more packages of resources from the source(s), dispatching such packages to one or more queues and of processing such queued packages by persisting them into the target instance(s)
  • exporting - process of creating one or more packages, operation may either happen locally to the agent (the "push" scenario) or remotely (the "pull" scenario).
  • importing  - process of persisting one or more packages, operation may either happen locally (the "pull" scenario) or remotely (the "push" scenario). 



Forward distribution - Create/update content

Execute the below curl command in Author to Distribute content modification(new or modified) under /content/sample1 to publisher

curl -v -u admin:admin http://localhost:4502/libs/sling/distribution/services/agents/publish -d “action=ADD” -d “path=/content/sample1”

Forward distribution - Delete content

Execute the below curl command in Author to Distribute content deletions under /content/sample1 to publisher

curl -v -u admin:admin http://localhost:4502/libs/sling/distribution/services/agents/publish -d “action= DELETE” -d “path=/content/sample1”

Reverse distribution - Create/update content

Execute the below curl command in Publisher to add the distribution content to the Reverse Distribution Queue

curl -u admin:admin http://localhost:4503/libs/sling/distribution/services/agents/reverse -d “action=ADD” -d “path=/content/sample1”

 Execute the below curl command in Author to PULL the Distribution content from publisher
curl -u admin:admin http://localhost:4502/libs/sling/distribution/services/agents/publish-reverse -d “action=PULL”

Sync Distribution

Execute the below curl command in Publisher to add the distribution content to the Sync Distribution Queue

curl -u admin:admin http://localhost:4503/libs/sling/distribution/services/agents/reverse-pubsync -d "action=ADD" -d "path=/content/sample1"

Execute the below curl command in Author to PULL the content from publisher and distribute to the publishers in the farm other than the publisher initiated the content changes.(the changes wont't be persisted to Author)

curl -u admin:admin http://localhost:4502/libs/sling/distribution/services/agents/pubsync -d "action=PULL"


Trigger Factories to trigger the distribution on specific agent based on the events. The Triggers helps us to automate the distribution based on some events or specific interval.
  • DistributionEventDistributeDistributionTrigger - DistributionTrigger for chain distribution upon a certain DistributionEventTopics
  • JcrEventDistributionTrigger - A JCR observation based DistributionTrigger, trigger the distribution based on JCR events on specific nodes
  • PersistedJcrEventDistributionTrigger - DistributionTrigger that listens for certain events and persists them under a specific path in the repo
  • RemoteEventDistributionTrigger - DistributionTrigger to trigger distribution upon reception of server sent events on a certain URL
  • ResourceEventDistributionTrigger - DistributionTrigger for triggering a specific handler (e.g. agent) upon node / properties being changed under a certain path
  • ScheduledDistributionTrigger - DistributionTrigger to schedule distributions on a certain DistributionAgent, trigger the distribution based on specific interval.
Let us now see the details on Forward Distribution


  • A forward distribution setup allows one to transfer content from a source instance(Author) to a farm of target instances(Publish)
  • That is done by pushing the content from source to target


  • configure a local importer on publish
  • configure a "forward" agent on author pointing to the URL of the importer on publish




  • Configure Forward Agent in Author 
  • Configure Local Importer in Publisher
  • Enable Triggers – Scheduled/JCREvent
  • Test – CURL/UI/Triggers

Configure Forward Agent in Author

Configure a Forward Agent in Author that will distribute the content from Author to publishers importer endpoints based on the configuration.

Access http://localhost:4502/aem/start.html, Tools - Deployments - Distribution


Modify the default Forward Agent with name publish or create new agent of type Forward Distribution


Service Name - Service name is optional, if required create a service user with required permission
Change the lo level if required
Allowed Roots - Configure the content Roots the agent allowed to distribute
Importer Endpoints - List of publisher endpoints to which packages are sent,
http://localhost:4503/libs/sling/distribution/services/importers/default(default is the Local Importer name in publisher)

Ensure the Forward Agent Component is active


If the component is in un-satisfied state, verify the individual services in un-satisfied state and fix the configuration errors


Configure Local Importer in Publisher

Configure a local importer "Apache Sling Distribution Importer - Local Package Importer Factory" to receive the content from Author, publisher enabled with local importer  with the name "default" the same can be used 


If require define new local importer by accessing http://localhost:4503/system/console/configMgr/ (the importer end point in Author Forward Agent should be modified based on the Local Importer name)

Now the Forward Agent is ready to distribute the content to publishers


The agent can be disabled or paused from the configuration page also the Queue status and logs can be monitored

Let us test the forward distribution through curl command.

Modify the content under /content/we-retail in Author


Execute the below curl command in Author

curl -v -u admin:admin http://localhost:4502/libs/sling/distribution/services/agents/publish -d "action=ADD" -d "path=/content/we-retail/jcr:content"


Now the content is distributed to publish instance


The content distribution can also be triggered through Forward Agent Configuration Page


Let us now see how to automate the reverse distribution through triggers


Configure a JCR Event Trigger in Author to add the JCR changes under the configured path to the Forward Agent Queue.

Enter name - "forward-sync"
Path for which the changes are distributed - "/content/we-retail"
Service Name - Enter the service name with required access, i am using the default one for demo(socialpubsync-distributionService), the trigger will not be activated without configuring the service user
Use deep distribution - Enable this if want to distribute the subtree of the configured node on any events


Now link the trigger to the "Apache Sling Distribution Agent - Forward Agents Factory" configured with the name "publish" in the earlier step, Triggers - (name=forward-sync)


Now the content modification from Author under /content/we-retail node will be synced to publisher on modification.

The "Apache Sling Distribution Trigger - Scheduled Triggers Factory" can be configured to distribute the content on regular interval(link the trigger to the forward agent, either one of the - JCR or Scheduled trigger can be linked to agent)


The sling content distribution helps us to distribute the content between Author and publish instances. The Distribution triggers can be configured to automate the distribution of content between Author and Publishers. The Forward Distribution agent will help us to distribute the content from Author to Publishers. Let us continue with the Reverse Distribution in next tutorial.

No comments:

Post a Comment