Best practice to trigger some code after publish | Community
Skip to main content
Level 4
June 7, 2017

Best practice to trigger some code after publish

  • June 7, 2017
  • 3 replies
  • 2341 views

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?

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.

3 replies

cquser1
Level 7
June 7, 2017

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

smacdonald2008
Level 10
June 7, 2017

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.

antoniom5495929
Level 7
January 29, 2019

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