[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"skill:01M736KRWP2WFMSQQDHWTASTQQ":3,"skill-same:01M736KRWP2WFMSQQDHWTASTQQ":46},{"skillNo":4,"name":5,"nameZh":6,"description":7,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":16,"categories":17,"keywords":18,"publishedAt":19,"linkOnly":20,"markdownContent":21,"markdownBody":22,"frontMatter":23,"refName":24,"commitSha":25,"skillDirectory":26,"forksCount":14,"repositoryHtmlUrl":27,"repositoryHomepageUrl":6,"ownerHtmlUrl":28,"ownerBlogUrl":29,"ownerDescription":30,"updatedAt":31,"install":32,"resources":45},"01M736KRWP2WFMSQQDHWTASTQQ","sling-distribution",null,"Monitor and react to content distribution events using Sling Distribution API (org.apache.sling.distribution).\nCovers distribution event handling, queue monitoring, and distribution lifecycle tracking.","kalash33\u002Fkstack","kalash33","https:\u002F\u002Favatars.githubusercontent.com\u002Fu\u002F90259149?v=4","01M7365X8Q0B73NYHA730SMZWN","Kalash Poddar","01M7365X9D0JK47C3Q0YCCK9Z2",0,"Apache-2.0","https:\u002F\u002Fgithub.com\u002Fkalash33\u002Fkstack\u002Fblob\u002Fmain\u002Fskills\u002Fadobe-sling-distribution\u002FSKILL.md",[],[],"2026-11-11 15:11:14",false,"---\nname: sling-distribution\nlicense: Apache-2.0\ndescription: |\n  Monitor and react to content distribution events using Sling Distribution API (org.apache.sling.distribution).\n  Covers distribution event handling, queue monitoring, and distribution lifecycle tracking.\n---\n\n# AEM Cloud Service Sling Distribution Event Handling\n\nMonitor and react to content distribution lifecycle events using the Sling Distribution API.\n\n## When to Use This Skill\n\nUse Sling Distribution event handling for:\n- **Monitoring distribution lifecycle**: Track package creation, queueing, and delivery\n- **Custom post-distribution actions**: Cache warming, notifications, analytics\n- **Distribution auditing**: Log and track all distribution events\n- **Failure handling**: React to dropped packages and distribution failures\n- **Integration workflows**: Trigger external systems after successful distribution\n\n**For programmatic publishing**, use the [Replication API](..\u002Freplication\u002FSKILL.md) instead.\n\n## Official API Documentation\n\n**Javadoc**: https:\u002F\u002Fdeveloper.adobe.com\u002Fexperience-manager\u002Freference-materials\u002Fcloud-service\u002Fjavadoc\u002Forg\u002Fapache\u002Fsling\u002Fdistribution\u002Fpackage-summary.html\n\n**Key Packages**:\n- `org.apache.sling.distribution` - Core distribution interfaces\n- `org.apache.sling.distribution.event` - Event topics and properties\n- `org.apache.sling.distribution.queue` - Queue monitoring\n\n## Understanding Sling Distribution in Cloud Service\n\n### What is Sling Distribution?\n\nSling Distribution is the **underlying transport mechanism** for content replication in AEM Cloud Service. When you use the Replication API (`Replicator.replicate()`), Sling Distribution handles:\n\n1. **Package Creation**: Content is assembled into distribution packages\n2. **Queueing**: Packages are queued for delivery\n3. **Transport**: Packages are sent to Adobe Developer pipeline service\n4. **Import**: Target tier imports and applies the content\n\n### Architecture Flow\n\n```\nReplication API Call\n       ↓\n[AGENT_PACKAGE_CREATED] - Package assembled\n       ↓\n[AGENT_PACKAGE_QUEUED] - Package added to queue\n       ↓\n[AGENT_PACKAGE_DISTRIBUTED] - Package sent to pipeline\n       ↓\n[IMPORTER_PACKAGE_IMPORTED] - Package imported on target tier\n```\n\n**OR**\n\n```\n[AGENT_PACKAGE_DROPPED] - Package failed and was removed\n```\n\n## Distribution Event Topics\n\n### Available Event Topics\n\nSling Distribution fires events at each stage of the distribution lifecycle:\n\n| Event Topic | When It Fires | Use Case |\n|-------------|---------------|----------|\n| `AGENT_PACKAGE_CREATED` | After package creation | Track what's being published |\n| `AGENT_PACKAGE_QUEUED` | After package is queued | Monitor queue depth |\n| `AGENT_PACKAGE_DISTRIBUTED` | After successful distribution | Trigger post-publish actions |\n| `AGENT_PACKAGE_DROPPED` | When package fails and is dropped | Handle failures, alert on-call |\n| `IMPORTER_PACKAGE_IMPORTED` | After successful import on target | Confirm content is live |\n\n### Event Topic Constants\n\n```java\nimport org.apache.sling.distribution.event.DistributionEventTopics;\n\n\u002F\u002F Event topic strings\nDistributionEventTopics.AGENT_PACKAGE_CREATED      \u002F\u002F Package created\nDistributionEventTopics.AGENT_PACKAGE_QUEUED       \u002F\u002F Package queued\nDistributionEventTopics.AGENT_PACKAGE_DISTRIBUTED  \u002F\u002F Package distributed\nDistributionEventTopics.AGENT_PACKAGE_DROPPED      \u002F\u002F Package dropped\nDistributionEventTopics.IMPORTER_PACKAGE_IMPORTED  \u002F\u002F Package imported\n```\n\n## Listening to Distribution Events\n\n### Example: Basic Distribution Event Logger\n\n```java\nimport org.apache.sling.distribution.event.DistributionEventTopics;\nimport org.apache.sling.distribution.event.DistributionEventProperties;\nimport org.osgi.service.component.annotations.Component;\nimport org.osgi.service.event.Event;\nimport org.osgi.service.event.EventHandler;\nimport org.slf4j.Logger;\nimport org.slf4j.LoggerFactory;\n\n@Component(\n    service = EventHandler.class,\n    property = {\n        org.osgi.service.event.EventConstants.EVENT_TOPIC + \"=\" + \n            DistributionEventTopics.AGENT_PACKAGE_CREATED,\n        org.osgi.service.event.EventConstants.EVENT_TOPIC + \"=\" + \n            DistributionEventTopics.AGENT_PACKAGE_QUEUED,\n        org.osgi.service.event.EventConstants.EVENT_TOPIC + \"=\" + \n            DistributionEventTopics.AGENT_PACKAGE_DISTRIBUTED,\n        org.osgi.service.event.EventConstants.EVENT_TOPIC + \"=\" + \n            DistributionEventTopics.AGENT_PACKAGE_DROPPED,\n        org.osgi.service.event.EventConstants.EVENT_TOPIC + \"=\" + \n            DistributionEventTopics.IMPORTER_PACKAGE_IMPORTED\n    }\n)\npublic class DistributionEventLogger implements EventHandler {\n    \n    private static final Logger LOG = LoggerFactory.getLogger(DistributionEventLogger.class);\n    \n    @Override\n    public void handleEvent(Event event) {\n        String topic = event.getTopic();\n        \n        \u002F\u002F Extract event properties\n        String componentName = (String) event.getProperty(\n            DistributionEventProperties.DISTRIBUTION_COMPONENT_NAME\n        );\n        String componentKind = (String) event.getProperty(\n            DistributionEventProperties.DISTRIBUTION_COMPONENT_KIND\n        );\n        String distributionType = (String) event.getProperty(\n            DistributionEventProperties.DISTRIBUTION_TYPE\n        );\n        String packageId = (String) event.getProperty(\n            DistributionEventProperties.DISTRIBUTION_PACKAGE_ID\n        );\n        String[] paths = (String[]) event.getProperty(\n            DistributionEventProperties.DISTRIBUTION_PATHS\n        );\n        Long timestamp = (Long) event.getProperty(\n            DistributionEventProperties.DISTRIBUTION_ENQUEUE_TIMESTAMP\n        );\n        \n        LOG.info(\"Distribution Event: topic={}, component={}, type={}, packageId={}, paths={}, timestamp={}\",\n            topic, componentName, distributionType, packageId, \n            paths != null ? String.join(\",\", paths) : \"null\",\n            timestamp\n        );\n    }\n}\n```\n\n## Event Properties\n\n### Available Event Properties\n\nEvery distribution event contains these properties:\n\n| Property | Type | Description |\n|----------|------|-------------|\n| `DISTRIBUTION_COMPONENT_NAME` | String | Name of component generating the event |\n| `DISTRIBUTION_COMPONENT_KIND` | String | Kind of component (agent, importer, etc.) |\n| `DISTRIBUTION_TYPE` | String | Type of distribution request (ADD, DELETE, etc.) |\n| `DISTRIBUTION_PACKAGE_ID` | String | Unique package identifier |\n| `DISTRIBUTION_PATHS` | String[] | Content paths being distributed |\n| `DISTRIBUTION_DEEP_PATHS` | String[] | Deep paths (full subtree) |\n| `DISTRIBUTION_ENQUEUE_TIMESTAMP` | Long | When item was enqueued (milliseconds) |\n\n### Accessing Event Properties\n\n```java\nimport org.apache.sling.distribution.event.DistributionEventProperties;\n\n@Override\npublic void handleEvent(Event event) {\n    \u002F\u002F Component information\n    String componentName = (String) event.getProperty(\n        DistributionEventProperties.DISTRIBUTION_COMPONENT_NAME\n    );\n    String componentKind = (String) event.getProperty(\n        DistributionEventProperties.DISTRIBUTION_COMPONENT_KIND\n    );\n    \n    \u002F\u002F Distribution details\n    String type = (String) event.getProperty(\n        DistributionEventProperties.DISTRIBUTION_TYPE\n    );\n    String packageId = (String) event.getProperty(\n        DistributionEventProperties.DISTRIBUTION_PACKAGE_ID\n    );\n    \n    \u002F\u002F Content paths\n    String[] paths = (String[]) event.getProperty(\n        DistributionEventProperties.DISTRIBUTION_PATHS\n    );\n    String[] deepPaths = (String[]) event.getProperty(\n        DistributionEventProperties.DISTRIBUTION_DEEP_PATHS\n    );\n    \n    \u002F\u002F Timing\n    Long enqueueTime = (Long) event.getProperty(\n        DistributionEventProperties.DISTRIBUTION_ENQUEUE_TIMESTAMP\n    );\n}\n```\n\n## Common Use Cases\n\n### Use Case 1: Alert on Distribution Failures\n\n```java\nimport org.apache.sling.distribution.event.DistributionEventTopics;\n\n@Component(\n    service = EventHandler.class,\n    property = {\n        org.osgi.service.event.EventConstants.EVENT_TOPIC + \"=\" + \n            DistributionEventTopics.AGENT_PACKAGE_DROPPED\n    }\n)\npublic class DistributionFailureAlertHandler implements EventHandler {\n    \n    private static final Logger LOG = LoggerFactory.getLogger(\n        DistributionFailureAlertHandler.class\n    );\n    \n    @Reference\n    private AlertService alertService;  \u002F\u002F Custom alert service\n    \n    @Override\n    public void handleEvent(Event event) {\n        String packageId = (String) event.getProperty(\n            DistributionEventProperties.DISTRIBUTION_PACKAGE_ID\n        );\n        String[] paths = (String[]) event.getProperty(\n            DistributionEventProperties.DISTRIBUTION_PATHS\n        );\n        \n        LOG.error(\"Distribution package dropped: packageId={}, paths={}\", \n            packageId, String.join(\",\", paths));\n        \n        \u002F\u002F Send alert to operations team\n        alertService.sendAlert(\n            \"CRITICAL: Distribution Failed\",\n            String.format(\"Package %s was dropped. Paths: %s\", \n                packageId, String.join(\",\", paths))\n        );\n    }\n}\n```\n\n### Use Case 2: CDN Cache Warming After Distribution\n\n```java\n@Component(\n    service = EventHandler.class,\n    property = {\n        org.osgi.service.event.EventConstants.EVENT_TOPIC + \"=\" + \n            DistributionEventTopics.IMPORTER_PACKAGE_IMPORTED\n    }\n)\npublic class CdnCacheWarmingHandler implements EventHandler {\n    \n    private static final Logger LOG = LoggerFactory.getLogger(\n        CdnCacheWarmingHandler.class\n    );\n    \n    @Reference\n    private HttpClient httpClient;\n    \n    @Override\n    public void handleEvent(Event event) {\n        String[] paths = (String[]) event.getProperty(\n            DistributionEventProperties.DISTRIBUTION_PATHS\n        );\n        String distributionType = (String) event.getProperty(\n            DistributionEventProperties.DISTRIBUTION_TYPE\n        );\n        \n        \u002F\u002F Only warm cache on ADD (activation)\n        if (\"ADD\".equals(distributionType) && paths != null) {\n            for (String path : paths) {\n                warmCache(path);\n            }\n        }\n    }\n    \n    private void warmCache(String path) {\n        try {\n            \u002F\u002F Convert JCR path to public URL\n            String publicUrl = \"https:\u002F\u002Fwww.example.com\" + \n                path.replace(\"\u002Fcontent\u002Fmysite\", \"\") + \".html\";\n            \n            LOG.info(\"Warming CDN cache for: {}\", publicUrl);\n            \n            HttpGet request = new HttpGet(publicUrl);\n            httpClient.execute(request);\n            \n        } catch (Exception e) {\n            LOG.error(\"Cache warming failed for path: \" + path, e);\n        }\n    }\n}\n```\n\n### Use Case 3: Distribution Analytics Tracking\n\n```java\n@Component(\n    service = EventHandler.class,\n    property = {\n        org.osgi.service.event.EventConstants.EVENT_TOPIC + \"=\" + \n            DistributionEventTopics.AGENT_PACKAGE_CREATED,\n        org.osgi.service.event.EventConstants.EVENT_TOPIC + \"=\" + \n            DistributionEventTopics.AGENT_PACKAGE_DISTRIBUTED,\n        org.osgi.service.event.EventConstants.EVENT_TOPIC + \"=\" + \n            DistributionEventTopics.AGENT_PACKAGE_DROPPED\n    }\n)\npublic class DistributionAnalyticsHandler implements EventHandler {\n    \n    @Reference\n    private AnalyticsService analyticsService;\n    \n    @Override\n    public void handleEvent(Event event) {\n        String topic = event.getTopic();\n        String packageId = (String) event.getProperty(\n            DistributionEventProperties.DISTRIBUTION_PACKAGE_ID\n        );\n        String[] paths = (String[]) event.getProperty(\n            DistributionEventProperties.DISTRIBUTION_PATHS\n        );\n        Long timestamp = (Long) event.getProperty(\n            DistributionEventProperties.DISTRIBUTION_ENQUEUE_TIMESTAMP\n        );\n        \n        \u002F\u002F Track metrics\n        if (DistributionEventTopics.AGENT_PACKAGE_CREATED.equals(topic)) {\n            analyticsService.trackEvent(\"distribution.package.created\", \n                Map.of(\"packageId\", packageId, \"pathCount\", paths.length));\n        } \n        else if (DistributionEventTopics.AGENT_PACKAGE_DISTRIBUTED.equals(topic)) {\n            long duration = System.currentTimeMillis() - timestamp;\n            analyticsService.trackEvent(\"distribution.package.distributed\", \n                Map.of(\"packageId\", packageId, \"duration\", duration));\n        }\n        else if (DistributionEventTopics.AGENT_PACKAGE_DROPPED.equals(topic)) {\n            analyticsService.trackEvent(\"distribution.package.failed\", \n                Map.of(\"packageId\", packageId, \"paths\", String.join(\",\", paths)));\n        }\n    }\n}\n```\n\n### Use Case 4: Slack Notifications for Production Publishes\n\n```java\n@Component(\n    service = EventHandler.class,\n    property = {\n        org.osgi.service.event.EventConstants.EVENT_TOPIC + \"=\" + \n            DistributionEventTopics.IMPORTER_PACKAGE_IMPORTED\n    }\n)\npublic class ProductionPublishNotificationHandler implements EventHandler {\n    \n    @Reference\n    private SlackService slackService;\n    \n    @Reference\n    private SlingSettingsService slingSettings;\n    \n    @Override\n    public void handleEvent(Event event) {\n        \u002F\u002F Only notify for production environment\n        if (!slingSettings.getRunModes().contains(\"prod\")) {\n            return;\n        }\n        \n        String[] paths = (String[]) event.getProperty(\n            DistributionEventProperties.DISTRIBUTION_PATHS\n        );\n        String componentName = (String) event.getProperty(\n            DistributionEventProperties.DISTRIBUTION_COMPONENT_NAME\n        );\n        \n        \u002F\u002F Only notify for publish agent (not preview)\n        if (!\"publish\".equals(componentName)) {\n            return;\n        }\n        \n        String message = String.format(\n            \":rocket: Content published to production: %s\",\n            String.join(\", \", paths)\n        );\n        \n        slackService.postToChannel(\"#content-releases\", message);\n    }\n}\n```\n\n### Use Case 5: Audit Log for All Distribution Events\n\n```java\nimport javax.jcr.Node;\nimport org.apache.sling.api.resource.ResourceResolver;\nimport org.apache.sling.api.resource.ResourceResolverFactory;\n\n@Component(\n    service = EventHandler.class,\n    property = {\n        org.osgi.service.event.EventConstants.EVENT_TOPIC + \"=\" + \n            DistributionEventTopics.AGENT_PACKAGE_CREATED,\n        org.osgi.service.event.EventConstants.EVENT_TOPIC + \"=\" + \n            DistributionEventTopics.AGENT_PACKAGE_QUEUED,\n        org.osgi.service.event.EventConstants.EVENT_TOPIC + \"=\" + \n            DistributionEventTopics.AGENT_PACKAGE_DISTRIBUTED,\n        org.osgi.service.event.EventConstants.EVENT_TOPIC + \"=\" + \n            DistributionEventTopics.AGENT_PACKAGE_DROPPED,\n        org.osgi.service.event.EventConstants.EVENT_TOPIC + \"=\" + \n            DistributionEventTopics.IMPORTER_PACKAGE_IMPORTED\n    }\n)\npublic class DistributionAuditHandler implements EventHandler {\n    \n    @Reference\n    private ResourceResolverFactory resolverFactory;\n    \n    @Override\n    public void handleEvent(Event event) {\n        try (ResourceResolver resolver = getServiceResolver()) {\n            \n            String topic = event.getTopic();\n            String packageId = (String) event.getProperty(\n                DistributionEventProperties.DISTRIBUTION_PACKAGE_ID\n            );\n            String[] paths = (String[]) event.getProperty(\n                DistributionEventProperties.DISTRIBUTION_PATHS\n            );\n            Long timestamp = (Long) event.getProperty(\n                DistributionEventProperties.DISTRIBUTION_ENQUEUE_TIMESTAMP\n            );\n            \n            \u002F\u002F Create audit log entry under \u002Fvar\u002Faudit\u002Fdistribution\n            String auditPath = \"\u002Fvar\u002Faudit\u002Fdistribution\u002F\" + \n                System.currentTimeMillis();\n            \n            Node auditNode = resolver.getResource(\"\u002Fvar\u002Faudit\u002Fdistribution\")\n                .adaptTo(Node.class)\n                .addNode(String.valueOf(System.currentTimeMillis()), \"nt:unstructured\");\n            \n            auditNode.setProperty(\"topic\", topic);\n            auditNode.setProperty(\"packageId\", packageId);\n            auditNode.setProperty(\"paths\", paths);\n            auditNode.setProperty(\"timestamp\", timestamp);\n            auditNode.setProperty(\"auditTime\", System.currentTimeMillis());\n            \n            resolver.commit();\n            \n        } catch (Exception e) {\n            LOG.error(\"Failed to create audit log\", e);\n        }\n    }\n    \n    private ResourceResolver getServiceResolver() throws Exception {\n        Map\u003CString, Object> param = Map.of(\n            ResourceResolverFactory.SUBSERVICE, \"distributionAuditor\"\n        );\n        return resolverFactory.getServiceResourceResolver(param);\n    }\n}\n```\n\n## Distribution Request Types\n\nWhen monitoring events, the `DISTRIBUTION_TYPE` property indicates the type of operation:\n\n| Request Type | Description | When Used |\n|--------------|-------------|-----------|\n| `ADD` | Content is being added\u002Factivated | Normal publishing |\n| `DELETE` | Content is being deleted | Unpublishing, deletion |\n| `PULL` | Content is being pulled from target | Reverse replication |\n| `INVALIDATE` | Cache invalidation only | CDN purge |\n| `TEST` | Connection test | Health checks |\n\n### Example: Handle Different Distribution Types\n\n```java\n@Override\npublic void handleEvent(Event event) {\n    String distributionType = (String) event.getProperty(\n        DistributionEventProperties.DISTRIBUTION_TYPE\n    );\n    String[] paths = (String[]) event.getProperty(\n        DistributionEventProperties.DISTRIBUTION_PATHS\n    );\n    \n    switch (distributionType) {\n        case \"ADD\":\n            LOG.info(\"Content activated: {}\", String.join(\",\", paths));\n            break;\n        case \"DELETE\":\n            LOG.info(\"Content deleted: {}\", String.join(\",\", paths));\n            break;\n        case \"INVALIDATE\":\n            LOG.info(\"Cache invalidated: {}\", String.join(\",\", paths));\n            break;\n        case \"TEST\":\n            LOG.debug(\"Distribution test executed\");\n            break;\n        default:\n            LOG.warn(\"Unknown distribution type: {}\", distributionType);\n    }\n}\n```\n\n## Best Practices\n\n### 1. Filter Events Appropriately\n\nOnly listen to events you need:\n\n```java\n\u002F\u002F Good: Listen to specific events\nproperty = {\n    org.osgi.service.event.EventConstants.EVENT_TOPIC + \"=\" + \n        DistributionEventTopics.AGENT_PACKAGE_DROPPED\n}\n\n\u002F\u002F Avoid: Listening to all events if not needed\n```\n\n### 2. Handle Events Asynchronously\n\nEvent handlers should be fast. Offload heavy processing:\n\n```java\n@Reference\nprivate JobManager jobManager;\n\n@Override\npublic void handleEvent(Event event) {\n    \u002F\u002F Queue a job for async processing\n    Map\u003CString, Object> jobProperties = new HashMap\u003C>();\n    jobProperties.put(\"packageId\", event.getProperty(\n        DistributionEventProperties.DISTRIBUTION_PACKAGE_ID));\n    \n    jobManager.addJob(\"com\u002Fmyapp\u002Fdistribution\u002Fprocess\", jobProperties);\n}\n```\n\n### 3. Use Service Users\n\nEvent handlers should use service users, not admin sessions:\n\n```xml\n\u003C!-- Service user mapping -->\n{\n  \"user.mapping\": [\n    \"com.myapp.core:distributionEventHandler=myapp-distribution-service\"\n  ]\n}\n```\n\n### 4. Handle Null Properties\n\nNot all properties are available in all events:\n\n```java\nString[] paths = (String[]) event.getProperty(\n    DistributionEventProperties.DISTRIBUTION_PATHS\n);\n\nif (paths != null && paths.length > 0) {\n    \u002F\u002F Process paths\n}\n```\n\n### 5. Log Appropriately\n\nUse appropriate log levels:\n\n```java\n\u002F\u002F INFO for normal flow\nLOG.info(\"Package distributed: {}\", packageId);\n\n\u002F\u002F WARN for unexpected situations\nLOG.warn(\"Package queued longer than expected: {}\", packageId);\n\n\u002F\u002F ERROR for failures\nLOG.error(\"Package dropped: {}\", packageId);\n```\n\n## Monitoring Distribution Queue\n\nWhile you can't directly query distribution queues via the API in Cloud Service, you can monitor via:\n\n1. **Events**: Track `AGENT_PACKAGE_QUEUED` and `AGENT_PACKAGE_DISTRIBUTED` events\n2. **Felix Console**: View Sling jobs at `\u002Fsystem\u002Fconsole\u002Fslingjobs`\n3. **Logs**: Check distribution logs in Cloud Manager\n\n### Example: Queue Depth Monitoring\n\n```java\nimport java.util.concurrent.ConcurrentHashMap;\nimport java.util.Map;\n\n@Component(\n    service = {EventHandler.class, QueueMonitor.class},\n    property = {\n        org.osgi.service.event.EventConstants.EVENT_TOPIC + \"=\" + \n            DistributionEventTopics.AGENT_PACKAGE_QUEUED,\n        org.osgi.service.event.EventConstants.EVENT_TOPIC + \"=\" + \n            DistributionEventTopics.AGENT_PACKAGE_DISTRIBUTED,\n        org.osgi.service.event.EventConstants.EVENT_TOPIC + \"=\" + \n            DistributionEventTopics.AGENT_PACKAGE_DROPPED\n    }\n)\npublic class QueueMonitor implements EventHandler {\n    \n    private final Map\u003CString, Long> queuedPackages = new ConcurrentHashMap\u003C>();\n    \n    @Override\n    public void handleEvent(Event event) {\n        String topic = event.getTopic();\n        String packageId = (String) event.getProperty(\n            DistributionEventProperties.DISTRIBUTION_PACKAGE_ID\n        );\n        \n        if (DistributionEventTopics.AGENT_PACKAGE_QUEUED.equals(topic)) {\n            queuedPackages.put(packageId, System.currentTimeMillis());\n            LOG.info(\"Queue depth: {}\", queuedPackages.size());\n            \n            \u002F\u002F Alert if queue is too deep\n            if (queuedPackages.size() > 50) {\n                LOG.warn(\"Distribution queue depth exceeds threshold: {}\", \n                    queuedPackages.size());\n            }\n        } \n        else if (DistributionEventTopics.AGENT_PACKAGE_DISTRIBUTED.equals(topic) ||\n                 DistributionEventTopics.AGENT_PACKAGE_DROPPED.equals(topic)) {\n            Long queuedTime = queuedPackages.remove(packageId);\n            \n            if (queuedTime != null) {\n                long duration = System.currentTimeMillis() - queuedTime;\n                LOG.info(\"Package processed in {}ms. Queue depth: {}\", \n                    duration, queuedPackages.size());\n            }\n        }\n    }\n    \n    public int getQueueDepth() {\n        return queuedPackages.size();\n    }\n}\n```\n\n## Troubleshooting\n\n### Issue: Event Handler Not Firing\n\n**Causes**:\n1. Wrong event topic constant\n2. Component not activated\n3. Event topic not registered\n\n**Solution**:\n```java\n\u002F\u002F Verify event topic matches exactly\nproperty = {\n    org.osgi.service.event.EventConstants.EVENT_TOPIC + \"=\" + \n        DistributionEventTopics.AGENT_PACKAGE_CREATED  \u002F\u002F Exact constant\n}\n\n\u002F\u002F Check component is active in Felix console\n\u002F\u002F \u002Fsystem\u002Fconsole\u002Fcomponents\n```\n\n### Issue: Missing Event Properties\n\n**Cause**: Not all properties are available in all events\n\n**Solution**: Always null-check:\n```java\nString[] paths = (String[]) event.getProperty(\n    DistributionEventProperties.DISTRIBUTION_PATHS\n);\n\nif (paths == null) {\n    LOG.warn(\"No paths in distribution event\");\n    return;\n}\n```\n\n### Issue: Event Handler Slowing Down Distribution\n\n**Cause**: Synchronous processing in event handler\n\n**Solution**: Use async job processing:\n```java\n@Reference\nprivate JobManager jobManager;\n\n@Override\npublic void handleEvent(Event event) {\n    \u002F\u002F Don't do heavy work here\n    jobManager.addJob(\"com\u002Fmyapp\u002Fprocess\", eventData);\n}\n```\n\n## Relationship with Replication API\n\n**Key Understanding**:\n- **Replication API** (`com.day.cq.replication.Replicator`) - What you call to publish content\n- **Sling Distribution Events** (`org.apache.sling.distribution.event`) - What fires during the distribution lifecycle\n\n**Workflow**:\n```\nYour Code: replicator.replicate(...)\n    ↓\nSling Distribution: Creates package → [AGENT_PACKAGE_CREATED]\n    ↓\nSling Distribution: Queues package → [AGENT_PACKAGE_QUEUED]\n    ↓\nSling Distribution: Sends package → [AGENT_PACKAGE_DISTRIBUTED]\n    ↓\nTarget Tier: Imports package → [IMPORTER_PACKAGE_IMPORTED]\n```\n\n## References\n\n- **Sling Distribution Javadoc**: https:\u002F\u002Fdeveloper.adobe.com\u002Fexperience-manager\u002Freference-materials\u002Fcloud-service\u002Fjavadoc\u002Forg\u002Fapache\u002Fsling\u002Fdistribution\u002Fpackage-summary.html\n- **Sling Distribution Docs**: https:\u002F\u002Fsling.apache.org\u002Fdocumentation\u002Fbundles\u002Fcontent-distribution.html\n- **Replication API Skill**: [replication\u002FSKILL.md](..\u002Freplication\u002FSKILL.md)\n- **Adobe AEM Replication**: https:\u002F\u002Fexperienceleague.adobe.com\u002Fdocs\u002Fexperience-manager-cloud-service\u002Fcontent\u002Foperations\u002Freplication.html\n","# AEM Cloud Service Sling Distribution Event Handling\n\nMonitor and react to content distribution lifecycle events using the Sling Distribution API.\n\n## When to Use This Skill\n\nUse Sling Distribution event handling for:\n- **Monitoring distribution lifecycle**: Track package creation, queueing, and delivery\n- **Custom post-distribution actions**: Cache warming, notifications, analytics\n- **Distribution auditing**: Log and track all distribution events\n- **Failure handling**: React to dropped packages and distribution failures\n- **Integration workflows**: Trigger external systems after successful distribution\n\n**For programmatic publishing**, use the [Replication API](..\u002Freplication\u002FSKILL.md) instead.\n\n## Official API Documentation\n\n**Javadoc**: https:\u002F\u002Fdeveloper.adobe.com\u002Fexperience-manager\u002Freference-materials\u002Fcloud-service\u002Fjavadoc\u002Forg\u002Fapache\u002Fsling\u002Fdistribution\u002Fpackage-summary.html\n\n**Key Packages**:\n- `org.apache.sling.distribution` - Core distribution interfaces\n- `org.apache.sling.distribution.event` - Event topics and properties\n- `org.apache.sling.distribution.queue` - Queue monitoring\n\n## Understanding Sling Distribution in Cloud Service\n\n### What is Sling Distribution?\n\nSling Distribution is the **underlying transport mechanism** for content replication in AEM Cloud Service. When you use the Replication API (`Replicator.replicate()`), Sling Distribution handles:\n\n1. **Package Creation**: Content is assembled into distribution packages\n2. **Queueing**: Packages are queued for delivery\n3. **Transport**: Packages are sent to Adobe Developer pipeline service\n4. **Import**: Target tier imports and applies the content\n\n### Architecture Flow\n\n```\nReplication API Call\n       ↓\n[AGENT_PACKAGE_CREATED] - Package assembled\n       ↓\n[AGENT_PACKAGE_QUEUED] - Package added to queue\n       ↓\n[AGENT_PACKAGE_DISTRIBUTED] - Package sent to pipeline\n       ↓\n[IMPORTER_PACKAGE_IMPORTED] - Package imported on target tier\n```\n\n**OR**\n\n```\n[AGENT_PACKAGE_DROPPED] - Package failed and was removed\n```\n\n## Distribution Event Topics\n\n### Available Event Topics\n\nSling Distribution fires events at each stage of the distribution lifecycle:\n\n| Event Topic | When It Fires | Use Case |\n|-------------|---------------|----------|\n| `AGENT_PACKAGE_CREATED` | After package creation | Track what's being published |\n| `AGENT_PACKAGE_QUEUED` | After package is queued | Monitor queue depth |\n| `AGENT_PACKAGE_DISTRIBUTED` | After successful distribution | Trigger post-publish actions |\n| `AGENT_PACKAGE_DROPPED` | When package fails and is dropped | Handle failures, alert on-call |\n| `IMPORTER_PACKAGE_IMPORTED` | After successful import on target | Confirm content is live |\n\n### Event Topic Constants\n\n```java\nimport org.apache.sling.distribution.event.DistributionEventTopics;\n\n\u002F\u002F Event topic strings\nDistributionEventTopics.AGENT_PACKAGE_CREATED      \u002F\u002F Package created\nDistributionEventTopics.AGENT_PACKAGE_QUEUED       \u002F\u002F Package queued\nDistributionEventTopics.AGENT_PACKAGE_DISTRIBUTED  \u002F\u002F Package distributed\nDistributionEventTopics.AGENT_PACKAGE_DROPPED      \u002F\u002F Package dropped\nDistributionEventTopics.IMPORTER_PACKAGE_IMPORTED  \u002F\u002F Package imported\n```\n\n## Listening to Distribution Events\n\n### Example: Basic Distribution Event Logger\n\n```java\nimport org.apache.sling.distribution.event.DistributionEventTopics;\nimport org.apache.sling.distribution.event.DistributionEventProperties;\nimport org.osgi.service.component.annotations.Component;\nimport org.osgi.service.event.Event;\nimport org.osgi.service.event.EventHandler;\nimport org.slf4j.Logger;\nimport org.slf4j.LoggerFactory;\n\n@Component(\n    service = EventHandler.class,\n    property = {\n        org.osgi.service.event.EventConstants.EVENT_TOPIC + \"=\" + \n            DistributionEventTopics.AGENT_PACKAGE_CREATED,\n        org.osgi.service.event.EventConstants.EVENT_TOPIC + \"=\" + \n            DistributionEventTopics.AGENT_PACKAGE_QUEUED,\n        org.osgi.service.event.EventConstants.EVENT_TOPIC + \"=\" + \n            DistributionEventTopics.AGENT_PACKAGE_DISTRIBUTED,\n        org.osgi.service.event.EventConstants.EVENT_TOPIC + \"=\" + \n            DistributionEventTopics.AGENT_PACKAGE_DROPPED,\n        org.osgi.service.event.EventConstants.EVENT_TOPIC + \"=\" + \n            DistributionEventTopics.IMPORTER_PACKAGE_IMPORTED\n    }\n)\npublic class DistributionEventLogger implements EventHandler {\n    \n    private static final Logger LOG = LoggerFactory.getLogger(DistributionEventLogger.class);\n    \n    @Override\n    public void handleEvent(Event event) {\n        String topic = event.getTopic();\n        \n        \u002F\u002F Extract event properties\n        String componentName = (String) event.getProperty(\n            DistributionEventProperties.DISTRIBUTION_COMPONENT_NAME\n        );\n        String componentKind = (String) event.getProperty(\n            DistributionEventProperties.DISTRIBUTION_COMPONENT_KIND\n        );\n        String distributionType = (String) event.getProperty(\n            DistributionEventProperties.DISTRIBUTION_TYPE\n        );\n        String packageId = (String) event.getProperty(\n            DistributionEventProperties.DISTRIBUTION_PACKAGE_ID\n        );\n        String[] paths = (String[]) event.getProperty(\n            DistributionEventProperties.DISTRIBUTION_PATHS\n        );\n        Long timestamp = (Long) event.getProperty(\n            DistributionEventProperties.DISTRIBUTION_ENQUEUE_TIMESTAMP\n        );\n        \n        LOG.info(\"Distribution Event: topic={}, component={}, type={}, packageId={}, paths={}, timestamp={}\",\n            topic, componentName, distributionType, packageId, \n            paths != null ? String.join(\",\", paths) : \"null\",\n            timestamp\n        );\n    }\n}\n```\n\n## Event Properties\n\n### Available Event Properties\n\nEvery distribution event contains these properties:\n\n| Property | Type | Description |\n|----------|------|-------------|\n| `DISTRIBUTION_COMPONENT_NAME` | String | Name of component generating the event |\n| `DISTRIBUTION_COMPONENT_KIND` | String | Kind of component (agent, importer, etc.) |\n| `DISTRIBUTION_TYPE` | String | Type of distribution request (ADD, DELETE, etc.) |\n| `DISTRIBUTION_PACKAGE_ID` | String | Unique package identifier |\n| `DISTRIBUTION_PATHS` | String[] | Content paths being distributed |\n| `DISTRIBUTION_DEEP_PATHS` | String[] | Deep paths (full subtree) |\n| `DISTRIBUTION_ENQUEUE_TIMESTAMP` | Long | When item was enqueued (milliseconds) |\n\n### Accessing Event Properties\n\n```java\nimport org.apache.sling.distribution.event.DistributionEventProperties;\n\n@Override\npublic void handleEvent(Event event) {\n    \u002F\u002F Component information\n    String componentName = (String) event.getProperty(\n        DistributionEventProperties.DISTRIBUTION_COMPONENT_NAME\n    );\n    String componentKind = (String) event.getProperty(\n        DistributionEventProperties.DISTRIBUTION_COMPONENT_KIND\n    );\n    \n    \u002F\u002F Distribution details\n    String type = (String) event.getProperty(\n        DistributionEventProperties.DISTRIBUTION_TYPE\n    );\n    String packageId = (String) event.getProperty(\n        DistributionEventProperties.DISTRIBUTION_PACKAGE_ID\n    );\n    \n    \u002F\u002F Content paths\n    String[] paths = (String[]) event.getProperty(\n        DistributionEventProperties.DISTRIBUTION_PATHS\n    );\n    String[] deepPaths = (String[]) event.getProperty(\n        DistributionEventProperties.DISTRIBUTION_DEEP_PATHS\n    );\n    \n    \u002F\u002F Timing\n    Long enqueueTime = (Long) event.getProperty(\n        DistributionEventProperties.DISTRIBUTION_ENQUEUE_TIMESTAMP\n    );\n}\n```\n\n## Common Use Cases\n\n### Use Case 1: Alert on Distribution Failures\n\n```java\nimport org.apache.sling.distribution.event.DistributionEventTopics;\n\n@Component(\n    service = EventHandler.class,\n    property = {\n        org.osgi.service.event.EventConstants.EVENT_TOPIC + \"=\" + \n            DistributionEventTopics.AGENT_PACKAGE_DROPPED\n    }\n)\npublic class DistributionFailureAlertHandler implements EventHandler {\n    \n    private static final Logger LOG = LoggerFactory.getLogger(\n        DistributionFailureAlertHandler.class\n    );\n    \n    @Reference\n    private AlertService alertService;  \u002F\u002F Custom alert service\n    \n    @Override\n    public void handleEvent(Event event) {\n        String packageId = (String) event.getProperty(\n            DistributionEventProperties.DISTRIBUTION_PACKAGE_ID\n        );\n        String[] paths = (String[]) event.getProperty(\n            DistributionEventProperties.DISTRIBUTION_PATHS\n        );\n        \n        LOG.error(\"Distribution package dropped: packageId={}, paths={}\", \n            packageId, String.join(\",\", paths));\n        \n        \u002F\u002F Send alert to operations team\n        alertService.sendAlert(\n            \"CRITICAL: Distribution Failed\",\n            String.format(\"Package %s was dropped. Paths: %s\", \n                packageId, String.join(\",\", paths))\n        );\n    }\n}\n```\n\n### Use Case 2: CDN Cache Warming After Distribution\n\n```java\n@Component(\n    service = EventHandler.class,\n    property = {\n        org.osgi.service.event.EventConstants.EVENT_TOPIC + \"=\" + \n            DistributionEventTopics.IMPORTER_PACKAGE_IMPORTED\n    }\n)\npublic class CdnCacheWarmingHandler implements EventHandler {\n    \n    private static final Logger LOG = LoggerFactory.getLogger(\n        CdnCacheWarmingHandler.class\n    );\n    \n    @Reference\n    private HttpClient httpClient;\n    \n    @Override\n    public void handleEvent(Event event) {\n        String[] paths = (String[]) event.getProperty(\n            DistributionEventProperties.DISTRIBUTION_PATHS\n        );\n        String distributionType = (String) event.getProperty(\n            DistributionEventProperties.DISTRIBUTION_TYPE\n        );\n        \n        \u002F\u002F Only warm cache on ADD (activation)\n        if (\"ADD\".equals(distributionType) && paths != null) {\n            for (String path : paths) {\n                warmCache(path);\n            }\n        }\n    }\n    \n    private void warmCache(String path) {\n        try {\n            \u002F\u002F Convert JCR path to public URL\n            String publicUrl = \"https:\u002F\u002Fwww.example.com\" + \n                path.replace(\"\u002Fcontent\u002Fmysite\", \"\") + \".html\";\n            \n            LOG.info(\"Warming CDN cache for: {}\", publicUrl);\n            \n            HttpGet request = new HttpGet(publicUrl);\n            httpClient.execute(request);\n            \n        } catch (Exception e) {\n            LOG.error(\"Cache warming failed for path: \" + path, e);\n        }\n    }\n}\n```\n\n### Use Case 3: Distribution Analytics Tracking\n\n```java\n@Component(\n    service = EventHandler.class,\n    property = {\n        org.osgi.service.event.EventConstants.EVENT_TOPIC + \"=\" + \n            DistributionEventTopics.AGENT_PACKAGE_CREATED,\n        org.osgi.service.event.EventConstants.EVENT_TOPIC + \"=\" + \n            DistributionEventTopics.AGENT_PACKAGE_DISTRIBUTED,\n        org.osgi.service.event.EventConstants.EVENT_TOPIC + \"=\" + \n            DistributionEventTopics.AGENT_PACKAGE_DROPPED\n    }\n)\npublic class DistributionAnalyticsHandler implements EventHandler {\n    \n    @Reference\n    private AnalyticsService analyticsService;\n    \n    @Override\n    public void handleEvent(Event event) {\n        String topic = event.getTopic();\n        String packageId = (String) event.getProperty(\n            DistributionEventProperties.DISTRIBUTION_PACKAGE_ID\n        );\n        String[] paths = (String[]) event.getProperty(\n            DistributionEventProperties.DISTRIBUTION_PATHS\n        );\n        Long timestamp = (Long) event.getProperty(\n            DistributionEventProperties.DISTRIBUTION_ENQUEUE_TIMESTAMP\n        );\n        \n        \u002F\u002F Track metrics\n        if (DistributionEventTopics.AGENT_PACKAGE_CREATED.equals(topic)) {\n            analyticsService.trackEvent(\"distribution.package.created\", \n                Map.of(\"packageId\", packageId, \"pathCount\", paths.length));\n        } \n        else if (DistributionEventTopics.AGENT_PACKAGE_DISTRIBUTED.equals(topic)) {\n            long duration = System.currentTimeMillis() - timestamp;\n            analyticsService.trackEvent(\"distribution.package.distributed\", \n                Map.of(\"packageId\", packageId, \"duration\", duration));\n        }\n        else if (DistributionEventTopics.AGENT_PACKAGE_DROPPED.equals(topic)) {\n            analyticsService.trackEvent(\"distribution.package.failed\", \n                Map.of(\"packageId\", packageId, \"paths\", String.join(\",\", paths)));\n        }\n    }\n}\n```\n\n### Use Case 4: Slack Notifications for Production Publishes\n\n```java\n@Component(\n    service = EventHandler.class,\n    property = {\n        org.osgi.service.event.EventConstants.EVENT_TOPIC + \"=\" + \n            DistributionEventTopics.IMPORTER_PACKAGE_IMPORTED\n    }\n)\npublic class ProductionPublishNotificationHandler implements EventHandler {\n    \n    @Reference\n    private SlackService slackService;\n    \n    @Reference\n    private SlingSettingsService slingSettings;\n    \n    @Override\n    public void handleEvent(Event event) {\n        \u002F\u002F Only notify for production environment\n        if (!slingSettings.getRunModes().contains(\"prod\")) {\n            return;\n        }\n        \n        String[] paths = (String[]) event.getProperty(\n            DistributionEventProperties.DISTRIBUTION_PATHS\n        );\n        String componentName = (String) event.getProperty(\n            DistributionEventProperties.DISTRIBUTION_COMPONENT_NAME\n        );\n        \n        \u002F\u002F Only notify for publish agent (not preview)\n        if (!\"publish\".equals(componentName)) {\n            return;\n        }\n        \n        String message = String.format(\n            \":rocket: Content published to production: %s\",\n            String.join(\", \", paths)\n        );\n        \n        slackService.postToChannel(\"#content-releases\", message);\n    }\n}\n```\n\n### Use Case 5: Audit Log for All Distribution Events\n\n```java\nimport javax.jcr.Node;\nimport org.apache.sling.api.resource.ResourceResolver;\nimport org.apache.sling.api.resource.ResourceResolverFactory;\n\n@Component(\n    service = EventHandler.class,\n    property = {\n        org.osgi.service.event.EventConstants.EVENT_TOPIC + \"=\" + \n            DistributionEventTopics.AGENT_PACKAGE_CREATED,\n        org.osgi.service.event.EventConstants.EVENT_TOPIC + \"=\" + \n            DistributionEventTopics.AGENT_PACKAGE_QUEUED,\n        org.osgi.service.event.EventConstants.EVENT_TOPIC + \"=\" + \n            DistributionEventTopics.AGENT_PACKAGE_DISTRIBUTED,\n        org.osgi.service.event.EventConstants.EVENT_TOPIC + \"=\" + \n            DistributionEventTopics.AGENT_PACKAGE_DROPPED,\n        org.osgi.service.event.EventConstants.EVENT_TOPIC + \"=\" + \n            DistributionEventTopics.IMPORTER_PACKAGE_IMPORTED\n    }\n)\npublic class DistributionAuditHandler implements EventHandler {\n    \n    @Reference\n    private ResourceResolverFactory resolverFactory;\n    \n    @Override\n    public void handleEvent(Event event) {\n        try (ResourceResolver resolver = getServiceResolver()) {\n            \n            String topic = event.getTopic();\n            String packageId = (String) event.getProperty(\n                DistributionEventProperties.DISTRIBUTION_PACKAGE_ID\n            );\n            String[] paths = (String[]) event.getProperty(\n                DistributionEventProperties.DISTRIBUTION_PATHS\n            );\n            Long timestamp = (Long) event.getProperty(\n                DistributionEventProperties.DISTRIBUTION_ENQUEUE_TIMESTAMP\n            );\n            \n            \u002F\u002F Create audit log entry under \u002Fvar\u002Faudit\u002Fdistribution\n            String auditPath = \"\u002Fvar\u002Faudit\u002Fdistribution\u002F\" + \n                System.currentTimeMillis();\n            \n            Node auditNode = resolver.getResource(\"\u002Fvar\u002Faudit\u002Fdistribution\")\n                .adaptTo(Node.class)\n                .addNode(String.valueOf(System.currentTimeMillis()), \"nt:unstructured\");\n            \n            auditNode.setProperty(\"topic\", topic);\n            auditNode.setProperty(\"packageId\", packageId);\n            auditNode.setProperty(\"paths\", paths);\n            auditNode.setProperty(\"timestamp\", timestamp);\n            auditNode.setProperty(\"auditTime\", System.currentTimeMillis());\n            \n            resolver.commit();\n            \n        } catch (Exception e) {\n            LOG.error(\"Failed to create audit log\", e);\n        }\n    }\n    \n    private ResourceResolver getServiceResolver() throws Exception {\n        Map\u003CString, Object> param = Map.of(\n            ResourceResolverFactory.SUBSERVICE, \"distributionAuditor\"\n        );\n        return resolverFactory.getServiceResourceResolver(param);\n    }\n}\n```\n\n## Distribution Request Types\n\nWhen monitoring events, the `DISTRIBUTION_TYPE` property indicates the type of operation:\n\n| Request Type | Description | When Used |\n|--------------|-------------|-----------|\n| `ADD` | Content is being added\u002Factivated | Normal publishing |\n| `DELETE` | Content is being deleted | Unpublishing, deletion |\n| `PULL` | Content is being pulled from target | Reverse replication |\n| `INVALIDATE` | Cache invalidation only | CDN purge |\n| `TEST` | Connection test | Health checks |\n\n### Example: Handle Different Distribution Types\n\n```java\n@Override\npublic void handleEvent(Event event) {\n    String distributionType = (String) event.getProperty(\n        DistributionEventProperties.DISTRIBUTION_TYPE\n    );\n    String[] paths = (String[]) event.getProperty(\n        DistributionEventProperties.DISTRIBUTION_PATHS\n    );\n    \n    switch (distributionType) {\n        case \"ADD\":\n            LOG.info(\"Content activated: {}\", String.join(\",\", paths));\n            break;\n        case \"DELETE\":\n            LOG.info(\"Content deleted: {}\", String.join(\",\", paths));\n            break;\n        case \"INVALIDATE\":\n            LOG.info(\"Cache invalidated: {}\", String.join(\",\", paths));\n            break;\n        case \"TEST\":\n            LOG.debug(\"Distribution test executed\");\n            break;\n        default:\n            LOG.warn(\"Unknown distribution type: {}\", distributionType);\n    }\n}\n```\n\n## Best Practices\n\n### 1. Filter Events Appropriately\n\nOnly listen to events you need:\n\n```java\n\u002F\u002F Good: Listen to specific events\nproperty = {\n    org.osgi.service.event.EventConstants.EVENT_TOPIC + \"=\" + \n        DistributionEventTopics.AGENT_PACKAGE_DROPPED\n}\n\n\u002F\u002F Avoid: Listening to all events if not needed\n```\n\n### 2. Handle Events Asynchronously\n\nEvent handlers should be fast. Offload heavy processing:\n\n```java\n@Reference\nprivate JobManager jobManager;\n\n@Override\npublic void handleEvent(Event event) {\n    \u002F\u002F Queue a job for async processing\n    Map\u003CString, Object> jobProperties = new HashMap\u003C>();\n    jobProperties.put(\"packageId\", event.getProperty(\n        DistributionEventProperties.DISTRIBUTION_PACKAGE_ID));\n    \n    jobManager.addJob(\"com\u002Fmyapp\u002Fdistribution\u002Fprocess\", jobProperties);\n}\n```\n\n### 3. Use Service Users\n\nEvent handlers should use service users, not admin sessions:\n\n```xml\n\u003C!-- Service user mapping -->\n{\n  \"user.mapping\": [\n    \"com.myapp.core:distributionEventHandler=myapp-distribution-service\"\n  ]\n}\n```\n\n### 4. Handle Null Properties\n\nNot all properties are available in all events:\n\n```java\nString[] paths = (String[]) event.getProperty(\n    DistributionEventProperties.DISTRIBUTION_PATHS\n);\n\nif (paths != null && paths.length > 0) {\n    \u002F\u002F Process paths\n}\n```\n\n### 5. Log Appropriately\n\nUse appropriate log levels:\n\n```java\n\u002F\u002F INFO for normal flow\nLOG.info(\"Package distributed: {}\", packageId);\n\n\u002F\u002F WARN for unexpected situations\nLOG.warn(\"Package queued longer than expected: {}\", packageId);\n\n\u002F\u002F ERROR for failures\nLOG.error(\"Package dropped: {}\", packageId);\n```\n\n## Monitoring Distribution Queue\n\nWhile you can't directly query distribution queues via the API in Cloud Service, you can monitor via:\n\n1. **Events**: Track `AGENT_PACKAGE_QUEUED` and `AGENT_PACKAGE_DISTRIBUTED` events\n2. **Felix Console**: View Sling jobs at `\u002Fsystem\u002Fconsole\u002Fslingjobs`\n3. **Logs**: Check distribution logs in Cloud Manager\n\n### Example: Queue Depth Monitoring\n\n```java\nimport java.util.concurrent.ConcurrentHashMap;\nimport java.util.Map;\n\n@Component(\n    service = {EventHandler.class, QueueMonitor.class},\n    property = {\n        org.osgi.service.event.EventConstants.EVENT_TOPIC + \"=\" + \n            DistributionEventTopics.AGENT_PACKAGE_QUEUED,\n        org.osgi.service.event.EventConstants.EVENT_TOPIC + \"=\" + \n            DistributionEventTopics.AGENT_PACKAGE_DISTRIBUTED,\n        org.osgi.service.event.EventConstants.EVENT_TOPIC + \"=\" + \n            DistributionEventTopics.AGENT_PACKAGE_DROPPED\n    }\n)\npublic class QueueMonitor implements EventHandler {\n    \n    private final Map\u003CString, Long> queuedPackages = new ConcurrentHashMap\u003C>();\n    \n    @Override\n    public void handleEvent(Event event) {\n        String topic = event.getTopic();\n        String packageId = (String) event.getProperty(\n            DistributionEventProperties.DISTRIBUTION_PACKAGE_ID\n        );\n        \n        if (DistributionEventTopics.AGENT_PACKAGE_QUEUED.equals(topic)) {\n            queuedPackages.put(packageId, System.currentTimeMillis());\n            LOG.info(\"Queue depth: {}\", queuedPackages.size());\n            \n            \u002F\u002F Alert if queue is too deep\n            if (queuedPackages.size() > 50) {\n                LOG.warn(\"Distribution queue depth exceeds threshold: {}\", \n                    queuedPackages.size());\n            }\n        } \n        else if (DistributionEventTopics.AGENT_PACKAGE_DISTRIBUTED.equals(topic) ||\n                 DistributionEventTopics.AGENT_PACKAGE_DROPPED.equals(topic)) {\n            Long queuedTime = queuedPackages.remove(packageId);\n            \n            if (queuedTime != null) {\n                long duration = System.currentTimeMillis() - queuedTime;\n                LOG.info(\"Package processed in {}ms. Queue depth: {}\", \n                    duration, queuedPackages.size());\n            }\n        }\n    }\n    \n    public int getQueueDepth() {\n        return queuedPackages.size();\n    }\n}\n```\n\n## Troubleshooting\n\n### Issue: Event Handler Not Firing\n\n**Causes**:\n1. Wrong event topic constant\n2. Component not activated\n3. Event topic not registered\n\n**Solution**:\n```java\n\u002F\u002F Verify event topic matches exactly\nproperty = {\n    org.osgi.service.event.EventConstants.EVENT_TOPIC + \"=\" + \n        DistributionEventTopics.AGENT_PACKAGE_CREATED  \u002F\u002F Exact constant\n}\n\n\u002F\u002F Check component is active in Felix console\n\u002F\u002F \u002Fsystem\u002Fconsole\u002Fcomponents\n```\n\n### Issue: Missing Event Properties\n\n**Cause**: Not all properties are available in all events\n\n**Solution**: Always null-check:\n```java\nString[] paths = (String[]) event.getProperty(\n    DistributionEventProperties.DISTRIBUTION_PATHS\n);\n\nif (paths == null) {\n    LOG.warn(\"No paths in distribution event\");\n    return;\n}\n```\n\n### Issue: Event Handler Slowing Down Distribution\n\n**Cause**: Synchronous processing in event handler\n\n**Solution**: Use async job processing:\n```java\n@Reference\nprivate JobManager jobManager;\n\n@Override\npublic void handleEvent(Event event) {\n    \u002F\u002F Don't do heavy work here\n    jobManager.addJob(\"com\u002Fmyapp\u002Fprocess\", eventData);\n}\n```\n\n## Relationship with Replication API\n\n**Key Understanding**:\n- **Replication API** (`com.day.cq.replication.Replicator`) - What you call to publish content\n- **Sling Distribution Events** (`org.apache.sling.distribution.event`) - What fires during the distribution lifecycle\n\n**Workflow**:\n```\nYour Code: replicator.replicate(...)\n    ↓\nSling Distribution: Creates package → [AGENT_PACKAGE_CREATED]\n    ↓\nSling Distribution: Queues package → [AGENT_PACKAGE_QUEUED]\n    ↓\nSling Distribution: Sends package → [AGENT_PACKAGE_DISTRIBUTED]\n    ↓\nTarget Tier: Imports package → [IMPORTER_PACKAGE_IMPORTED]\n```\n\n## References\n\n- **Sling Distribution Javadoc**: https:\u002F\u002Fdeveloper.adobe.com\u002Fexperience-manager\u002Freference-materials\u002Fcloud-service\u002Fjavadoc\u002Forg\u002Fapache\u002Fsling\u002Fdistribution\u002Fpackage-summary.html\n- **Sling Distribution Docs**: https:\u002F\u002Fsling.apache.org\u002Fdocumentation\u002Fbundles\u002Fcontent-distribution.html\n- **Replication API Skill**: [replication\u002FSKILL.md](..\u002Freplication\u002FSKILL.md)\n- **Adobe AEM Replication**: https:\u002F\u002Fexperienceleague.adobe.com\u002Fdocs\u002Fexperience-manager-cloud-service\u002Fcontent\u002Foperations\u002Freplication.html\n",{"name":5,"license":15,"description":7},"main","b30820b3248f6676d5389f0ccabd4e5250c9c536","skills\u002Fadobe-sling-distribution","https:\u002F\u002Fgithub.com\u002Fkalash33\u002Fkstack","https:\u002F\u002Fgithub.com\u002Fkalash33","kalashpoddar.me","Tech-savvy Full Stack Developer 🚀 | Cybersecurity enthusiast 🔒 | Passionate about innovation and securing the digital world 🌐 | Let's code securely! 💻🔐","2026-05-20 04:11:22",{"source":8,"skillName":5,"commands":33,"prompt":43,"zipAvailable":44},[34,37,40],{"tool":35,"command":36},"npx","npx skills add kalash33\u002Fkstack --skill sling-distribution",{"tool":38,"command":39},"bunx","bunx skills add kalash33\u002Fkstack --skill sling-distribution",{"tool":41,"command":42},"pnpm","pnpm dlx skills add kalash33\u002Fkstack --skill sling-distribution","安装技能，技能地址：https:\u002F\u002Fgithub.com\u002Fkalash33\u002Fkstack\u002Fblob\u002Fmain\u002Fskills\u002Fadobe-sling-distribution\u002FSKILL.md",true,[],[47,55,62,69,76,83],{"skillNo":48,"name":49,"nameZh":6,"description":50,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":51,"licenseFileUrl":6,"sourceHtmlUrl":52,"categories":53,"keywords":54,"publishedAt":19},"01M73CFERCR43JCAP606E41EFB","zustand-store-ts","Create Zustand stores with TypeScript, subscribeWithSelector middleware, and proper state\u002Faction separation. Use when building React state management, creating global stores, or implementing reacti...","MIT","https:\u002F\u002Fgithub.com\u002Fkalash33\u002Fkstack\u002Fblob\u002Fmain\u002Fskills\u002Fzustand-store-ts\u002FSKILL.md",[],[],{"skillNo":56,"name":57,"nameZh":6,"description":58,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":51,"licenseFileUrl":6,"sourceHtmlUrl":59,"categories":60,"keywords":61,"publishedAt":19},"01M73CFCMFVTAQEMTZ5HR10X8V","zoom-automation","Automate Zoom meeting creation, management, recordings, webinars, and participant tracking via Rube MCP (Composio). Always search tools first for current schemas.","https:\u002F\u002Fgithub.com\u002Fkalash33\u002Fkstack\u002Fblob\u002Fmain\u002Fskills\u002Fzoom-automation\u002FSKILL.md",[],[],{"skillNo":63,"name":64,"nameZh":6,"description":65,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":51,"licenseFileUrl":6,"sourceHtmlUrl":66,"categories":67,"keywords":68,"publishedAt":19},"01M73CFAA7EBWXJVXDQ1X555MB","zoho-crm-automation","Automate Zoho CRM tasks via Rube MCP (Composio): create\u002Fupdate records, search contacts, manage leads, and convert leads. Always search tools first for current schemas.","https:\u002F\u002Fgithub.com\u002Fkalash33\u002Fkstack\u002Fblob\u002Fmain\u002Fskills\u002Fzoho-crm-automation\u002FSKILL.md",[],[],{"skillNo":70,"name":71,"nameZh":6,"description":72,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":51,"licenseFileUrl":6,"sourceHtmlUrl":73,"categories":74,"keywords":75,"publishedAt":19},"01M73CF80XCM9K81567MJ8QZFW","zod-validation-expert","Expert in Zod — TypeScript-first schema validation. Covers parsing, custom errors, refinements, type inference, and integration with React Hook Form, Next.js, and tRPC.","https:\u002F\u002Fgithub.com\u002Fkalash33\u002Fkstack\u002Fblob\u002Fmain\u002Fskills\u002Fzod-validation-expert\u002FSKILL.md",[],[],{"skillNo":77,"name":78,"nameZh":6,"description":79,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":51,"licenseFileUrl":6,"sourceHtmlUrl":80,"categories":81,"keywords":82,"publishedAt":19},"01M73CF4YPMF3RA8ZJDXZSMD93","zeroize-audit","Detects missing zeroization of sensitive data in source code and identifies zeroization removed by compiler optimizations, with assembly-level analysis, and control-flow verification. Use for auditing C\u002FC++\u002FRust code handling secrets, keys, passwords, or other sensitive data.","https:\u002F\u002Fgithub.com\u002Fkalash33\u002Fkstack\u002Fblob\u002Fmain\u002Fskills\u002Fzeroize-audit\u002FSKILL.md",[],[],{"skillNo":84,"name":85,"nameZh":6,"description":86,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":51,"licenseFileUrl":6,"sourceHtmlUrl":87,"categories":88,"keywords":89,"publishedAt":19},"01M73CF2S25EN3XNAMKY47XHPS","zendesk-automation","Automate Zendesk tasks via Rube MCP (Composio): tickets, users, organizations, replies. Always search tools first for current schemas.","https:\u002F\u002Fgithub.com\u002Fkalash33\u002Fkstack\u002Fblob\u002Fmain\u002Fskills\u002Fzendesk-automation\u002FSKILL.md",[],[]]