Expand my Community achievements bar.

AEM Workflow for published asset

Avatar

Level 1

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.

Topics

Topics help categorize Community content and increase your ability to discover relevant content.

5 Replies

Avatar

Level 4

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. 

Avatar

Level 1

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. 

Avatar

Level 4

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. 

Avatar

Level 1

HI Sarav,
Cant we not use Adobe I/O events instead of app builder IO? I created a project and used webhook for subscribing but I don't see event for publish asset instead I see for Publish CF Event. I did a test run and it triggered but when ever I publish actual asset it doesnt trigger?
Thanks,
Amar.

Avatar

Level 4

Hi @AmarHa , yes using the Adobe I/O events only, I suggested the technique3. Your subscriber to the webhook runs into App Builder. This integration seamless, compared to running webhook subscriber outside Adobe world. 

 

And sounds interesting when you point CF publish event gets listened. But not asset publish event. Personally I haven't tried and tested if asset publish works. But sounds worthy issue to raise adobe support ticket.