Saturday, June 13, 2020

Sling Content Distribution in AEM (Part 2) — Reverse Distribution

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

sling-reverse-distribution
This will help us to sync the data generated in farms of publishers into the Author instances.

REVERSE DISTRIBUTION - CONFIGURATIONS

sling-reverse-distribution

  • configure a “queue” agent and package exporter on publisher(source instance)
org.apache.sling.distribution.agent.impl.QueueDistributionAgentFactory-reverse.json            
    name="reverse"

org.apache.sling.distribution.packaging.impl.exporter.AgentDistributionPackageExporterFactory-reverse
    name="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.json            
    name="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

sling-content-distribution-aem



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)

distribution-agent-aem


distribution-agent-aem



Save the configurations , the agent is created now but the status is paused 

distribution-agent-aem


Resume the agent by clicking on the resume button on the agent detail page.

distribution-agent-aem


distribution-agent-aem

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 )

distribution-agent-aem


Save the configurations, Queue Distribution Agent is enabled now

distribution-agent-aem


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

distribution-agent-aem


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

distribution-agent-aem.

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)

distribution-agent-aem

Now the content is queued to the publisher distribution queue

distribution-agent-aem


curl -u admin:admin http://localhost:4502/libs/sling/distribution/services/agents/reverse -d "action=PULL" (PULL the content from publisher queue to author)

distribution-agent-aem

 Now the content is pulled to author

distribution-agent-aem

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

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

distribution-agent-aem

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)

distribution-agent-aem

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

distribution-agent-aem


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)

distribution-agent-aem


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.


6 comments:

  1. Hey could you please provide detailed steps for sync distribution?

    ReplyDelete
    Replies
    1. I am planning to post a tutorial on sling content distribution ASAP.

      Delete
  2. Hi Thanks for your blog, really helpful. I tried reverse content distribution but somehow user is not getting replicated back from publish to Author under /home/users. Any idea??

    ReplyDelete
  3. Hey i am not able to replicate user under reverse content distribution. Any advise?

    ReplyDelete
    Replies
    1. Hi - Let me review this and update, may be blog specific to user sync

      Delete
    2. Thanks for your reply. I need to run a workflow in Author as user creates in Publish. So i need to do reverse content distribution, so that it can trigger the workflow. In case of user sync, it's not triggering the workflow in AEM. Please advise.

      Delete