Your achievements

Level 1

0% to

Level 2

Tip /
Sign in

Sign in to Community

to gain points, level up, and earn exciting badges like the new
BedrockMission!

Learn More

View all

Sign in to view all badges

Replication listener for DAM assets

Avatar

Avatar
Validate 1
Level 1
mohammadm377380
Level 1

Like

1 like

Total Posts

17 posts

Correct Reply

1 solution
Top badges earned
Validate 1
Boost 1
Affirm 1
View profile

Avatar
Validate 1
Level 1
mohammadm377380
Level 1

Like

1 like

Total Posts

17 posts

Correct Reply

1 solution
Top badges earned
Validate 1
Boost 1
Affirm 1
View profile
mohammadm377380
Level 1

01-03-2018

Hi,

I'm working on this replication listener to capture events on my publish instance whenever DAM assets are published in our author instance.

This replication listener is used to filter paths and if matches our desired filters, it will also trigger replication to other publisher.

Basically, our setup is:

When activating a cq:page:
AUTHORING (author) ==> STAGING (publish).

Then activate from STAGING (publish) ==> LIVE (publish)

When activating/deactivating a dam:Asset

AUTHOR ==> STAGING

AUTHOR ==> LIVE

Sample code below:

@Component(

        label = "Replication Event Listener",

        description = "Listen to replication events and relay it to publisher if necessary.",

        metatype = false

)

@Properties({

    // Scope the paths as tightly as possible based on your use-case.

    @Property(

            label = "Topic",

            description = "Event topic for replication",

            name = EventConstants.EVENT_TOPIC,

            value = ReplicationAction.EVENT_TOPIC

    )

})

@Service

public class ReplicationEventListener implements EventHandler {

     private Logger log = LoggerFactory.getLogger(this.getClass());

     @Override

    public void handleEvent(Event event) {

        String n[] = event.getPropertyNames();

        log.info("");

        log.info("Event occurred: {}", event.getProperty(WorkflowEvent.EVENT_TYPE));

        log.info("Event properties: ");

        for (String s : n) {

            log.info(s + " = " + event.getProperty(s));

        }

        action = ReplicationAction.fromEvent(event);

        if (action != null) {

            log.info("Replication action {} occured on {} ", action.getType().getName(), action.getPath());

        }

        log.info("");

    }

}

Accepted Solutions (1)

Accepted Solutions (1)

Avatar

Avatar
Validate 1
Level 1
mohammadm377380
Level 1

Like

1 like

Total Posts

17 posts

Correct Reply

1 solution
Top badges earned
Validate 1
Boost 1
Affirm 1
View profile

Avatar
Validate 1
Level 1
mohammadm377380
Level 1

Like

1 like

Total Posts

17 posts

Correct Reply

1 solution
Top badges earned
Validate 1
Boost 1
Affirm 1
View profile
mohammadm377380
Level 1

01-03-2018

Yes, It is writing logs.

I think I got it solved already. I have figured out that it is not triggering any replication action but only:

org/apache/sling/api/resource/Resource/ADDED

org/apache/sling/api/resource/Resource/CHANGED

org/apache/sling/api/resource/Resource/REMOVED

Here's my

@Properties({

    @Property(

        label = "Filter",

        description = "Event filter for replication",

        name = EventConstants.EVENT_FILTER,

        value = "(path=/content/dam/*)"

    ),

    @Property(

        label = "Topic",

        description = "Event topic for replication",

        name = EventConstants.EVENT_TOPIC,

        value = {

            SlingConstants.TOPIC_RESOURCE_ADDED,

            SlingConstants.TOPIC_RESOURCE_CHANGED,

            SlingConstants.TOPIC_RESOURCE_REMOVED

        }

    )

})

@Service

public class DamEventListener implements EventHandler {

     private Logger log = LoggerFactory.getLogger(this.getClass());

     @Override

     public void handleEvent(Event event) {

          String path = (String) event.getProperty(SlingConstances.PROPERTY_PATH);

          String topic = event.getTopic();

          log.info("PATH: {}", path);

          log.info("TOPIC: {}", topic);

     }

}

Answers (4)

Answers (4)

Avatar

Avatar
Validate 1
Level 1
mohammadm377380
Level 1

Like

1 like

Total Posts

17 posts

Correct Reply

1 solution
Top badges earned
Validate 1
Boost 1
Affirm 1
View profile

Avatar
Validate 1
Level 1
mohammadm377380
Level 1

Like

1 like

Total Posts

17 posts

Correct Reply

1 solution
Top badges earned
Validate 1
Boost 1
Affirm 1
View profile
mohammadm377380
Level 1

01-03-2018

Yeah, I actually used that logic when listening to the replication of our pages.

Avatar

Avatar
Validate 25
Level 10
smacdonald2008
Level 10

Likes

1,408 likes

Total Posts

12,671 posts

Correct Reply

2,278 solutions
Top badges earned
Validate 25
Validate 10
Validate 1
Give back 900
Give back 600
View profile

Avatar
Validate 25
Level 10
smacdonald2008
Level 10

Likes

1,408 likes

Total Posts

12,671 posts

Correct Reply

2,278 solutions
Top badges earned
Validate 25
Validate 10
Validate 1
Give back 900
Give back 600
View profile
smacdonald2008
Level 10

01-03-2018

We have an older AEM article that shows logic for a replication event handler too -- Adobe CQ Help | Creating Replication Event Handlers for Adobe Experience Manager

Avatar

Avatar
Validate 25
Level 10
smacdonald2008
Level 10

Likes

1,408 likes

Total Posts

12,671 posts

Correct Reply

2,278 solutions
Top badges earned
Validate 25
Validate 10
Validate 1
Give back 900
Give back 600
View profile

Avatar
Validate 25
Level 10
smacdonald2008
Level 10

Likes

1,408 likes

Total Posts

12,671 posts

Correct Reply

2,278 solutions
Top badges earned
Validate 25
Validate 10
Validate 1
Give back 900
Give back 600
View profile
smacdonald2008
Level 10

01-03-2018

Id your log messages being written to the log file?

Avatar

Avatar
Establish
Community Manager
kautuk_sahni
Community Manager

Likes

1,164 likes

Total Posts

6,273 posts

Correct Reply

1,144 solutions
Top badges earned
Establish
Coach
Originator
Contributor 2
Contributor
View profile

Avatar
Establish
Community Manager
kautuk_sahni
Community Manager

Likes

1,164 likes

Total Posts

6,273 posts

Correct Reply

1,144 solutions
Top badges earned
Establish
Coach
Originator
Contributor 2
Contributor
View profile
kautuk_sahni
Community Manager

01-03-2018

Moving this to the Assets topic!!