Above code in AEM 6.5. How to convert it in AEM as a cloud service ?
a. Use Sling Event Listeners
b. Use Sling Scheduler jobs
c. Use Polling importer
d. Use Sling model exporter
Solved! Go to Solution.
Topics help categorize Community content and increase your ability to discover relevant content.
Views
Replies
Total Likes
@JakeCham With AEM as a Cloud Service, now the application will be running on cluster nodes which means instances can go down and new ones can come up any time. The code must be resilient especially as an instance might be stopped at any point in time. Refer below article for implementation details.
https://sudeshaempodcast.wordpress.com/2021/07/04/aemaacs-slingjobs/
@JakeCham With AEM as a Cloud Service, now the application will be running on cluster nodes which means instances can go down and new ones can come up any time. The code must be resilient especially as an instance might be stopped at any point in time. Refer below article for implementation details.
https://sudeshaempodcast.wordpress.com/2021/07/04/aemaacs-slingjobs/
Views
Replies
Total Likes
Hi @JakeCham you can use Sling Scheduler jobs. it will work
1.Create a Job Interface
import org.apache.sling.event.jobs.Job;
import org.apache.sling.event.jobs.consumer.JobConsumer;
public interface MyScheduledJob extends JobConsumer {
}
2.Implement the Job Consumer
import org.apache.sling.event.jobs.Job;
import org.apache.sling.event.jobs.consumer.JobConsumer;
public class MyScheduledJobImpl implements JobConsumer {
@Override
public JobResult process(Job job) {
}
3.Register the Job Consumer
import org.osgi.service.component.annotations.Component;
@Component(service = JobConsumer.class,
property = {
JobConsumer.PROPERTY_TOPICS + "=" + "my/scheduled/job"
})
public class MyScheduledJobImpl implements JobConsumer {
}
4.Configure Scheduler
import org.osgi.service.component.annotations.Activate;
import org.osgi.service.component.annotations.Component;
import org.osgi.service.metatype.annotations.Designate;
import org.osgi.service.metatype.annotations.AttributeDefinition;
import org.osgi.service.metatype.annotations.ObjectClassDefinition;
@Designate(ocd = MyScheduledJob.Configuration.class)
@Component(service = Runnable.class)
public class MyScheduledJob implements Runnable {
@ObjectClassDefinition(name = "My Scheduled Job Configuration", description = "Configure the interval for the scheduled job.")
public @interface Configuration {
@AttributeDefinition(name = "Scheduler Expression", description = "Cron expression for scheduling the job.")
String scheduler_expression() default "0 0/5 * 1/1 * ? *"; // Run every 5 minutes as an example
}
@Activate
protected void activate(Configuration config) {
...Use the configuration to set up the scheduler
}
@Override
public void run() {
Implement the logic that needs to be executed periodically
This method will be called when the job is triggered by the scheduler
}
}
In this example, the job consumer(MyscheduledJobImpl)processes the job when it is triggered by the scheduler. The scheduler configuration is typically done using a cron expression to determine the frequency of job execution.
Thanks.
Views
Replies
Total Likes
Views
Likes
Replies
Views
Likes
Replies