AEM 6.3设置PageEvent处理器/监听器

问题描述 投票:0回答:1

林目前正在建立的页面创建和删除事件处理程序上AEM到随后致电我们的供应商API的一个。

我一直一个基础模块上我的工作中,我们已经有一个监听复制事件。

到目前为止,我能在复制重现我的模块上的行为,并触发代码。但是,我只需要在页面出版物和删除的API调用。

我一直试图找到如何复制和删除页面激活和区分。

到目前为止,似乎AEM处理CRX复制和页面出版物同一类型的事件“键入=激活”的。

如果我删除一个页面,它设置类型为“删除”,所以我可以用工作来调用API,但该页面发布即时通讯丢失,因为正如我所说,AEM看起来像它处理CRX复制和页面出版物一样类型。

经过一番研究,我发现PageEvent API,我试图建立一个页面事件监听器,但它是没有得到在出版物或页面缺失引发的,所以我不会相信,如果什么即时试图做的可能或也许我及部件是位于项目监听页面事件的错误部分。

由于事先

events listener replication aem
1个回答
0
投票

这下面的代码工作正常,检测页面删除事件:

@Component(
        service = {
                EventHandler.class,
                JobConsumer.class
        },
        immediate = true,
        configurationPolicy = ConfigurationPolicy.OPTIONAL,
        property = {
                "event.topics=" + PageEvent.EVENT_TOPIC,
                JobConsumer.PROPERTY_TOPICS + "=" + "aem/custom/event"
        }
)

public class CustomEventHandler implements EventHandler, JobConsumer {

    @Override
    public void handleEvent(Event event) {
        PageEvent pageEvent = PageEvent.fromEvent(event);
        Map<String, Object> properties = new HashMap<>();
        properties.put("pageEvent", pageEvent);
        jobManager.addJob("aem/custom/event", properties);
    }

    @Override
    public JobResult process(Job job) {
        PageEvent pageEvent = (PageEvent) job.getProperty("pageEvent");
        try {
            if (pageEvent != null && pageEvent.isLocal()) {
                Iterator<PageModification> modificationsIterator = pageEvent.getModifications();
                while (modificationsIterator.hasNext()) {
                    PageModification modification = modificationsIterator.next();

                    if (PageModification.ModificationType.DELETED.equals(modification.getType())) {
                        // Your logic
                    }
                }
            }
        } catch (Exception e) {
            logger.error("Error : ", e);
        }
        return JobResult.OK;
    }
}
© www.soinside.com 2019 - 2024. All rights reserved.