EventHandler not catching events | Community
Skip to main content
JS_Bournival
Level 3
October 16, 2015
Solved

EventHandler not catching events

Hi,

I'm trying to post events and have them handled by a couple of services.  I'm using the EventAdmin class to post send the event.  The topic I use is just a string.

My handlers implement EventHandler and its handleEvent method.  I also define the Property annotation, with "event.topics" set to the same topic string used to post the events.  But nothing is ever received.

Do I need to create/configure queues somewhere? Does the topic name absolutely needs to be a FQCN?

Thanx.

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
JustinEd3Accepted solution
Employee
October 16, 2015

If you look at your code, you can see that you're explicitly declaring this component as a "BiosFactory" service, not an EventHandler.

5 replies

Sham_HC
Level 10
October 16, 2015

Look at sample implementation at /apps/geometrixx/src/impl/src/main/java/com/day/cq/wcm/apps/geometrixx/impl/PageEventListener.java

If you do not configure queue use the default one. You can configure it from felix console.

Translate
JS_Bournival
Level 3
October 16, 2015

I'm confused because I do not understand, I'm doing (at least I think I'm doing) exactly what's in the example.  3 key points:

1. posting the event in a servlet:

eventAdmin.sendEvent(new Event("com/mycomp/corpo/MOVE", properties));

2. implemented a handler:

@Component(immediate = true) @Service(value = BiosFactory.class) @Property(name = EventConstants.EVENT_TOPIC, value = { "com/mycomp/corpo/MOVE", "com/mycomp/corpo/DELETE" }) public class BiosFactoryImpl extends BaseServiceImpl implements BiosFactory, EventHandler { // ... @Override public void handleEvent(Event event) { logger.debug("Handling my event"); } }

3. Configured a queue in the OSGi admin console

[img]Adobe_CQ_Web_Console_-_Configuration-4.png[/img]

Translate
JS_Bournival
Level 3
October 16, 2015

... and I checked in the OSGi console 'Events' applet to see if my event have been posted, and it's there.  So I think it's something I'm doing wrong with the listener.

Translate
JustinEd3Accepted solution
Employee
October 16, 2015

If you look at your code, you can see that you're explicitly declaring this component as a "BiosFactory" service, not an EventHandler.

Translate
JS_Bournival
Level 3
October 16, 2015

yeah, got it.  so by leaving the annotation empty, it seem to recognize all the declared interfaces on the class.

Or use the multiple services annotation: 

@Component(immediate = true) @Services(value = { @Service(value = BiosFactory.class), @Service(value = EventHandler.class) }) @Property(name = EventConstants.EVENT_TOPIC, value = { "com/mycomp/corpo/MOVE", "com/mycomp/corpo/DELETE" }) public class BiosFactoryImpl extends BaseServiceImpl implements BiosFactory, EventHandler { // ... @Override public void handleEvent(Event event) { logger.debug("Handling my event"); } }

thank you.

Translate