January 2, 2021
Estimated Post Reading Time ~

One Simple Trick for Quicker AEM Content Jobs

Many projects have that job. You know the one. It’s every Sys Admin’s nightmare, but it performs some critical tasks for the website. It also takes several hours to run and has the occasional tendency to do bad things like… take down a server. What if I told you there’s a way to make that job quicker and reliable and to reduce the amount of code you have to write? Unbelievable? Believe it!

The Solution: Automatically Build & Replicate a Content Package
Recently, I contributed a new service to the Adobe Consulting Services AEM Commons open-source library. The service is based on the code we implemented at a client which reduced the execution time of that job by approximately 50%. In this case, that job was importing content from an internal data source to create a large number of pages on the website. It then performed a tree activation on the content to get it from Author to the Publishers. This would take hours and had the occasional tendency to take down a server as it would get overloaded with the thousands of replication events.

Instead of relying on tree activation, we switched over to package replication. This cut the replication time from hours to minutes and eliminated the performance issues.

Based on this tremendous performance improvement, I developed a new, genericized service for AEM ACS Commons. The new feature in ACS AEM Commons, Automatic Package Replication allows you to automatically build and replicate a package on a schedule, as a part of a workflow, or through a Sling Event.

Using ACS AEM Commons Automatic Package Replicator
Incorporating the Automatic Package Replication service in that job is a pretty simple trick. Let’s assume you want to fire replication after your job completes. You’d just follow these steps:
1. Download and install AEM ACS Commons 3.9.0+ or 2.12.0+ (depending on your version of AEM)
2. Create a package definition for the content you want to replicate. I’d be a good idea to test this a couple times to make sure it’s got everything you need and nothing you don’t.
3. Navigate to the Automatic Package Replication configuration and create a new configuration
4. Set the Trigger to “Sling Event” and the Event Topic to a unique value for your job. If you have multiple different packages your job may replicate or multiple instances of the job, you can use the Event Filter to further limit when the package will be replicated.
5. Add the code into your job to fire off a Sling, for example:

@Reference
private EventAdmin eventAdmin;

[... more code ...]

final Event event = new Event("customer/app/job1-replicate", new HashMap<String, String>() {

private static final long serialVersionUID = 1L;

{
put("package", "my-package");
}
});
eventAdmin.postEvent(event);


This will trigger the Automatic Package Replicator configuration you defined to run which will build the package and replicate it to the publisher servers.
More Information

For more information on the Automatic Package Replication service, consult the documentation on the ACS AEM Commons website.


By aem4beginner

No comments:

Post a Comment

If you have any doubts or questions, please let us know.