根据Apache Sling官方网站(https://sling.apache.org/documentation/bundles/apache-sling-eventing-and-job-handling.html#job-consumers),这是编写JobConsumer的方法。
import org.apache.felix.scr.annotations.Component;
import org.apache.felix.scr.annotations.Service;
import org.apache.sling.event.jobs.Job;
import org.apache.sling.event.jobs.consumer.JobConsumer;
@Component
@Service(value={JobConsumer.class})
@Property(name=JobConsumer.PROPERTY_TOPICS, value="my/special/jobtopic",)
public class MyJobConsumer implements JobConsumer {
public JobResult process(final Job job) {
// process the job and return the result
return JobResult.OK;
}
}
然而@Service和@Property都是被弃用的注解。我想知道创建JobConsumer的正确方法。有谁知道如何编写与上面相同的代码吗?
在AEM中不推荐使用scr注释,建议以后使用官方的OSGi声明性服务注释。Adobe有一个关于使用OSGi R7注释的研讨会。
新的写法是
import org.osgi.service.component.annotations.Component;
import org.apache.sling.event.jobs.Job;
import org.apache.sling.event.jobs.consumer.JobConsumer;
@Component(
immediate = true,
service = JobConsumer.class,
property = {
JobConsumer.PROPERTY_TOPICS +"=my/special/jobtopic"
}
)
public class MyJobConsumer implements JobConsumer {
public JobResult process(final Job job) {
// process the job and return the result
return JobResult.OK;
}
}
你可以参考下面的博客。我已经尽力在这里解释了。
https://www.linkedin.com/pulse/aem-how-write-sling-jobs-aem-veena-vikraman