This tutorial is the continuation of earlier tutorial on Sling Content Distribution in AEM, refer the following URL for part1 tutorial - https://www.albinsblog.com/2020/05/sling-content-distribution-sync-use.html
In this tutorial let us see the details on Sling Reverse Distribution on AEM.
REVERSE DISTRIBUTION - DEFINITION
- A reverse distribution setup allows one to transfer content from a farm of source instances(publisher) to a target instance(author).
- That is done by pulling the content from source instances(publisher) into the target instance(author).
This will help us to sync the data generated in farms of publishers into the Author instances.
REVERSE DISTRIBUTION - CONFIGURATIONS
- configure a “queue” agent and package exporter on publisher(source instance)
org.apache.sling.distribution.agent.impl.QueueDistributionAgentFactory-reverse.jsonname="reverse"org.apache.sling.distribution.packaging.impl.exporter.AgentDistributionPackageExporterFactory-reversename="reverse"agent.target="(name=reverse)"
- configure a “reverse" agent on author(target instance) pointing to the URL of the exporter on publish, multiple publisher endpoints can be configured
org.apache.sling.distribution.agent.impl.ReverseDistributionAgentFactory-reverse.jsonname="reverse"packageExporter.endpoints=["http://localhost:4503/libs/sling/distribution/services/exporters/reverse"]
REVERSE DISTRIBUTION - DEMO
- Configure Reverse Agent in Author
- Configure Queue agent and exporter on Publisher
- Enable Triggers – Scheduled/JCREvent
- Test – CURL/Triggers
Configure Reverse Agent in Author
Configure a Reverse Agent in Author that will PULL distribution content from publishers endpoints based on the configuration.
Access http://localhost:4502/aem/start.html, Tools - Deployments - Distribution
Create new Distribution agent of type - Reverse Distribution
Enter a name - "reverse"
Title - "reverse"
Check "Enabled"
Service Name - Service name is optional, if required create a service user with required permission
Change the lo level if required
Add exporter endpoint URL's - the URL point to the publisher, multiple endpoint URL's can be configured, http://localhost:4503/libs/sling/distribution/services/exporters/reverse(reverse is the Queue Distribution agent name of publisher)
Save the configurations , the agent is created now but the status is paused
Resume the agent by clicking on the resume button on the agent detail page.
The agent is now ready to Pull the distribution content from publisher.
Configure Queue agent and exporter on Publisher
Configure a queue agent that places the changes into the queues and an exporter that exports packages from the queue agent.
Access http://localhost:4503/aem/start.html, Tools - Deployments - Distribution
Create new Distribution agent of type - Queue
Enter a name - "reverse"
Title - "reverse"
Check "Enabled"
Service Name - Service name is optional, if required create a service user with required permission
Change the lo level if required
Allowed Roots - Add the root paths the agent is responsible for distribution e.g /content/we-retail(if required multiple root paths can be configured )
Save the configurations, Queue Distribution Agent is enabled now
Let us now configure Exporter
Enter name - "reverse"
The target reference for the DistributionAgent that will be used to export packages - "(name=reverse)", here "reverse" is the queue agent name configured in the previous step
Now the initial configurations are ready, let us test the reverse distribution scenario through curl commands
Modify some content under /content/we-retail node in publisher
Execute the below curl commands
curl -u admin:admin http://localhost:4503/libs/sling/distribution/services/agents/reverse -d "action=ADD" -d "path=/content/we-retail/jcr:content" (add the modified content to publisher Distribution queue)
Now the content is queued to the publisher distribution queue
curl -u admin:admin http://localhost:4502/libs/sling/distribution/services/agents/reverse -d "action=PULL" (PULL the content from publisher queue to author)
Now the content is pulled to author
Configure a JCR Event Trigger in Publisher
Configure a JCR Event Trigger in Publisher to add the JCR changes under the configured path to the Distribution queue
Access http://localhost:4503/system/console/configMgr/org.apache.sling.distribution.trigger.impl.JcrEventDistributionTriggerFactory
Enter name - "reverse-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 - Queue Agents Factory" configured with the name "reverse" in the earlier step, Triggers - (name=reverse-sync)
Configure a Scheduled Event Trigger in Author
Configure a Scheduled Event Trigger in Author to pull the content from publishers Distribution Queue
Enter name - "reverse-sync"
Distribution Type - "PULL"Distributed Path, the path to be distributed periodically- "/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
Interval in Seconds - he number of seconds between distribution requests. Default 30 seconds
Interval in Seconds - he number of seconds between distribution requests. Default 30 seconds
Now link the trigger to the "Apache Sling Distribution Agent - Reverse Agents Factory" configured with the name "reverse" in the earlier step, Triggers - (name=reverse-sync)
Now the content modification from publisher under /content/we-retail node will be synced to author on every 30 seconds
This concludes the reverse distribution configuration between publisher and author, the content changes from publisher is pulled to author. We can configure multiple publisher endpoints in the Author reverse distribution agent to pull the content changes . The triggers can be configured in Author and Publishers to completely automate the reverse distribution of the contents. Let us continue with distribution sync in next tutorial.