AEM Workflow for published asset | Community
Skip to main content
Level 2
July 1, 2024
Question

AEM Workflow for published asset

  • July 1, 2024
  • 1 reply
  • 1326 views

Hi,

I am exploring options to use AEM workflow. I want to call an API inside workflow when ever some one publish an asset. Is it possible to write this kind of workflow in AEM Cloud? Your answer is highly appreciated.  
THanks.

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

1 reply

sarav_prakash
Community Advisor
Community Advisor
July 1, 2024

There are multiple ways to address this requirement

 

Technique 1: Sling Events - There is modern compared to ResourceChangeListeners. Here is a full example. You create an EventHandler and subscribe to `distribution.paths` event for "ADD" type. The event will be invoked everytime asset gets published. 

@Component(immediate = true, property = { "event.topics=org/apache/sling/distribution/importer/package/imported",
"event.filter=(|(distribution.type=ADD)(distribution.type=DELETE))" })
public class SlingDistributionEventHandler implements EventHandler {
public static final String DISTRIBUTION_PATHS = "distribution.paths";

@Override
public void handleEvent(Event event) {
if (event.getProperty(DISTRIBUTION_PATHS) != null) {
String[] pagePath = (String[]) event.getProperty(DISTRIBUTION_PATHS);

}
}

 

Technique 2: Workflow Launchers  - This is an old technique. Not recommended considering, in cloud environments, launchers gets invoked multiple times. And may result in accidently executing multiple times. 

 

Technique 3: Using App Builder IO - On Cloud world, we are working hard to break AEM monolith into microservices. Adobe provides App Builder to run actions OUTSIDE AEM. So when an asset gets processed, AEM dispatches an Event. You ll build an IO action to subscribe to AEM event and continue your remaining work. Beauty is, this microservice action runs completely OUTSIDE AEM. And runs with Cloud power, scaling up/down. You need not worry about volume, job heaviness, CPU etc, since this is outside AEM.

 

Highly recommended to explore AppBuilder route and create an action outside AEM. If not feasible,  stick to option1, sling events. 

AmarHaAuthor
Level 2
July 1, 2024

Thanks @sarav_prakash  for the reply. Our AEM runs on cloud, so I believe there is less chance to go through option1.

with option 2, can we call an API in workflow step?
Thanks for Option 3: I still need to explore App builder IO and I need to request access for it. 

sarav_prakash
Community Advisor
Community Advisor
July 1, 2024

No Amar, if option3 is nogo, go with option1. For cloud, sling jobs work well. If you read comment by jorg hoh, reads,

 

The replication mechanism itself is implemented differently in CS and SDK, but the event after having received an incoming replication should be identical.

 

Subscribing to replication event is good reliable way.