【问题标题】:How to create JobConsumer in Sling?如何在 Sling 中创建 JobConsumer?
【发布时间】:2021-06-07 21:59:20
【问题描述】:

根据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 的正确方法。 有谁知道如何编写与上述等效的代码?

【问题讨论】:

    标签: java aem apache-felix sling


    【解决方案1】:

    scr 注释在 AEM 中已弃用,建议继续使用官方 OSGi 声明式服务注释。使用 OSGi R7 注释有一个seminar by Adobe

    新的写法是

    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;
        }
    }
    

    【讨论】:

      猜你喜欢
      • 2016-10-06
      • 2017-06-02
      • 2018-03-20
      • 2015-12-12
      • 2023-04-01
      • 1970-01-01
      • 2017-06-13
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多