Expand my Community achievements bar.

Dive into Adobe Summit 2024! Explore curated list of AEM sessions & labs, register, connect with experts, ask questions, engage, and share insights. Don't miss the excitement.

Best practice to trigger some code after publish

Avatar

Level 5

When a user publishes a product collection I need to trigger some code to push this data out of AEM into our Product Collection DynamoDB Table. I wanted to check what is the best practice for this would be (We are using AEM 6.2). From what I can tell I would want a sling event to capture the replication event (filtered based on path in the repository) and then I could either run my code to update DynamoDB or create a Sling Job(?) that from what I understand effectively places this on a queue that means I can then have my DynamoDB update code reading from this Job queue to give me more confidence that this code will be executed. My understanding is that it makes sense to run this on the author so I don't have n publishers all triggering the same thing but I want to ensure this code is run when the replication is successful I'm hopeful that the event is only triggered after success?

3 Replies

Avatar

Level 8

Hi,

One way I could think of is to have the logic to capture data into the db table, along with the logic [after the mentioned logic is processed]where you are replicating concerned stuff takes place. This way you need not have to explicitly listen to replication events and trigger capture of data into DB

Avatar

Level 10

What about a Publish Workflow where you could write a custom step that is invoked as part of the Publish Workflow. I know we do that internally.

Avatar

Level 7

Hi,

if you try to use a ReplicationListener i think that you are sure that the element is already published on the publish instance.

I put here a snippet that I use for my project:

package com.adobe.cq.listeners;

import com.day.cq.replication.*;

public class MyReplicationHandler implements ReplicationListener {

   public void onStart(Agent agent, ReplicationAction replicationAction) {

   //started
   }

   public void onMessage(ReplicationLog.Level level, String s) {

   //put in the queue
   }

   public void onEnd(Agent agent, ReplicationAction replicationAction, ReplicationResult replicationResult) {

   //replicated
   }

   public void onError(Agent agent, ReplicationAction replicationAction, Exception e) {

   //failed
   }

}

Let us know.

Thanks,

Antonio