$npx -y skills add adobe/skills --skill sling-distributionMonitor and react to content distribution events using Sling Distribution API (org.apache.sling.distribution). Covers distribution event handling, queue monitoring, and distribution lifecycle tracking.
| 1 | # AEM Cloud Service Sling Distribution Event Handling |
| 2 | |
| 3 | Monitor and react to content distribution lifecycle events using the Sling Distribution API. |
| 4 | |
| 5 | ## When to Use This Skill |
| 6 | |
| 7 | Use Sling Distribution event handling for: |
| 8 | - **Monitoring distribution lifecycle**: Track package creation, queueing, and delivery |
| 9 | - **Custom post-distribution actions**: Cache warming, notifications, analytics |
| 10 | - **Distribution auditing**: Log and track all distribution events |
| 11 | - **Failure handling**: React to dropped packages and distribution failures |
| 12 | - **Integration workflows**: Trigger external systems after successful distribution |
| 13 | |
| 14 | **For programmatic publishing**, use the [Replication API](../replication/SKILL.md) instead. |
| 15 | |
| 16 | ## Official API Documentation |
| 17 | |
| 18 | **Javadoc**: https://developer.adobe.com/experience-manager/reference-materials/cloud-service/javadoc/org/apache/sling/distribution/package-summary.html |
| 19 | |
| 20 | **Key Packages**: |
| 21 | - `org.apache.sling.distribution` - Core distribution interfaces |
| 22 | - `org.apache.sling.distribution.event` - Event topics and properties |
| 23 | - `org.apache.sling.distribution.queue` - Queue monitoring |
| 24 | |
| 25 | ## Understanding Sling Distribution in Cloud Service |
| 26 | |
| 27 | ### What is Sling Distribution? |
| 28 | |
| 29 | Sling Distribution is the **underlying transport mechanism** for content replication in AEM Cloud Service. When you use the Replication API (`Replicator.replicate()`), Sling Distribution handles: |
| 30 | |
| 31 | 1. **Package Creation**: Content is assembled into distribution packages |
| 32 | 2. **Queueing**: Packages are queued for delivery |
| 33 | 3. **Transport**: Packages are sent to Adobe Developer pipeline service |
| 34 | 4. **Import**: Target tier imports and applies the content |
| 35 | |
| 36 | ### Architecture Flow |
| 37 | |
| 38 | ``` |
| 39 | Replication API Call |
| 40 | ↓ |
| 41 | [AGENT_PACKAGE_CREATED] - Package assembled |
| 42 | ↓ |
| 43 | [AGENT_PACKAGE_QUEUED] - Package added to queue |
| 44 | ↓ |
| 45 | [AGENT_PACKAGE_DISTRIBUTED] - Package sent to pipeline |
| 46 | ↓ |
| 47 | [IMPORTER_PACKAGE_IMPORTED] - Package imported on target tier |
| 48 | ``` |
| 49 | |
| 50 | **OR** |
| 51 | |
| 52 | ``` |
| 53 | [AGENT_PACKAGE_DROPPED] - Package failed and was removed |
| 54 | ``` |
| 55 | |
| 56 | ## Distribution Event Topics |
| 57 | |
| 58 | ### Available Event Topics |
| 59 | |
| 60 | Sling Distribution fires events at each stage of the distribution lifecycle: |
| 61 | |
| 62 | | Event Topic | When It Fires | Use Case | |
| 63 | |-------------|---------------|----------| |
| 64 | | `AGENT_PACKAGE_CREATED` | After package creation | Track what's being published | |
| 65 | | `AGENT_PACKAGE_QUEUED` | After package is queued | Monitor queue depth | |
| 66 | | `AGENT_PACKAGE_DISTRIBUTED` | After successful distribution | Trigger post-publish actions | |
| 67 | | `AGENT_PACKAGE_DROPPED` | When package fails and is dropped | Handle failures, alert on-call | |
| 68 | | `IMPORTER_PACKAGE_IMPORTED` | After successful import on target | Confirm content is live | |
| 69 | |
| 70 | ### Event Topic Constants |
| 71 | |
| 72 | ```java |
| 73 | import org.apache.sling.distribution.event.DistributionEventTopics; |
| 74 | |
| 75 | // Event topic strings |
| 76 | DistributionEventTopics.AGENT_PACKAGE_CREATED // Package created |
| 77 | DistributionEventTopics.AGENT_PACKAGE_QUEUED // Package queued |
| 78 | DistributionEventTopics.AGENT_PACKAGE_DISTRIBUTED // Package distributed |
| 79 | DistributionEventTopics.AGENT_PACKAGE_DROPPED // Package dropped |
| 80 | DistributionEventTopics.IMPORTER_PACKAGE_IMPORTED // Package imported |
| 81 | ``` |
| 82 | |
| 83 | ## Listening to Distribution Events |
| 84 | |
| 85 | ### Example: Basic Distribution Event Logger |
| 86 | |
| 87 | ```java |
| 88 | import org.apache.sling.distribution.event.DistributionEventTopics; |
| 89 | import org.apache.sling.distribution.event.DistributionEventProperties; |
| 90 | import org.osgi.service.component.annotations.Component; |
| 91 | import org.osgi.service.event.Event; |
| 92 | import org.osgi.service.event.EventHandler; |
| 93 | import org.slf4j.Logger; |
| 94 | import org.slf4j.LoggerFactory; |
| 95 | |
| 96 | @Component( |
| 97 | service = EventHandler.class, |
| 98 | property = { |
| 99 | org.osgi.service.event.EventConstants.EVENT_TOPIC + "=" + |
| 100 | DistributionEventTopics.AGENT_PACKAGE_CREATED, |
| 101 | org.osgi.service.event.EventConstants.EVENT_TOPIC + "=" + |
| 102 | DistributionEventTopics.AGENT_PACKAGE_QUEUED, |
| 103 | org.osgi.service.event.EventConstants.EVENT_TOPIC + "=" + |
| 104 | DistributionEventTopics.AGENT_PACKAGE_DISTRIBUTED, |
| 105 | org.osgi.service.event.EventConstants.EVENT_TOPIC + "=" + |
| 106 | DistributionEventTopics.AGENT_PACKAGE_DROPPED, |
| 107 | org.osgi.service.event.EventConstants.EVENT_TOPIC + "=" + |
| 108 | DistributionEventTopics.IMPORTER_PACKAGE_IMPORTED |
| 109 | } |
| 110 | ) |
| 111 | public class DistributionEventLogger implements EventHandler { |
| 112 | |
| 113 | private static final Logger LOG = LoggerFactory.getLogger(DistributionEventLogger.class); |
| 114 | |
| 115 | @Override |
| 116 | public void handleEvent(Event event) { |
| 117 | String topic = event.getTopic(); |
| 118 | |
| 119 | // Extract event properties |
| 120 | String componentName = (String) event.getProperty( |
| 121 | DistributionEventProperties.DISTRIBUTI |