premnisha
(Premnisha Balakumar)
October 17, 2019, 12:32pm
1
Hi All,
We are trying to setup Event Listener for Encounter class. Below is the sample Listener class we setup for testing
Activator code:
private EncounterEventListenerImpl getEncounterEventListener() {
log.info("In event listener impl");
return Context.getRegisteredComponent("listener.EncounterEventListener", EncounterEventListenerImpl.class);
}
/**
* @see #started()
*/
public void started() {
log.info("Started subscribe");
Event.subscribe(Encounter.class, null, getEncounterEventListener());
}
EventListener Implementation
package org.openmrs.module.icrc.listener;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.openmrs.event.Event;
import org.openmrs.event.EventListener;
import org.springframework.stereotype.Component;
@Component("listener.EncounterEventListener")
public class EncounterEventListenerImpl implements EventListener {
private Log log = LogFactory.getLog(this.getClass());;
@Override
public void onMessage(Message message) {
log.info("IN EVENT LISTENER");
}
}
We are unable to see the log message even if encounter is created in the database. Is there something we need to setup to send / publish
an event during encounter save.
Please let us know if we are missing something.
Some reference links we use:
https://github.com/openmrs/openmrs-module-event
https://wiki.openmrs.org/display/docs/Event+Module
https://github.com/IsantePlus/openmrs-module-xds-sender
Thanks in advance
mksd
(Dimitri R)
October 17, 2019, 2:45pm
3
One thing that I notice by looking at those two examples:
PatientViewedEventListener
in EMR API,
CaseReportEventListener
in DHIS2 Tracker,
is that they are not Spring beans, they’re just new
'd in their module’s activator. I don’t really understand why that would make a difference, but you could try it out too.
dkayiwa
(Daniel Kayiwa)
October 17, 2019, 8:45pm
4
Just incase it is something to do with your logging settings, do you see anything when you change this to? System.out.println("IN EVENT LISTENER");
sakthi
(Sakthidharan Jagadeesan)
October 18, 2019, 1:05pm
5
Hello, i too am working on this problem with @premnisha .
I changed the code in module’s activator to
Event.subscribe(Encounter.class, null, new EncounterEventListenerImpl());
It did not work. Still not seeing the “IN EVENT LISTENER” message in the docker logs.
Copying @rrameshbtech
sakthi
(Sakthidharan Jagadeesan)
October 18, 2019, 1:07pm
6
Hello, i too am working on this problem with @premnisha .
I changed the onMessage() method of EventListener to
@Override
public void onMessage(Message message) {
log.info("IN EVENT LISTENER");
System.out.println("In Event listener");
}
It did not work. Still not seeing either message in the docker logs.
Copying @rrameshbtech
mksd
(Dimitri R)
October 18, 2019, 1:39pm
7
@sakthi could you debug the built-in one PatientViewedEventListener
to see if it is working as expected? Do you ever get in there?
wyclif
(Wyclif Luyima)
October 18, 2019, 7:03pm
8
It could be because your second argument is null when registering your listener in the activator which might be getting interpreted as no actions to listen to
wyclif
(Wyclif Luyima)
October 18, 2019, 7:07pm
9
Actually null is fine, it means listen to all actions
wyclif
(Wyclif Luyima)
October 18, 2019, 7:11pm
10
You might want to confirm if activemq is getting initialized properly and that it is working.
sakthi
(Sakthidharan Jagadeesan)
October 21, 2019, 6:39am
11
We have followed the documentation of event module and we have not setup ActiveMQ explicitly. @wyclif Could you please guide us to a place where ActiveMQ setup needed for event module is documented
cc @mksd
premnisha
(Premnisha Balakumar)
October 21, 2019, 8:47am
12
mksd
(Dimitri R)
October 21, 2019, 1:41pm
13
@premnisha can you reproduce this in a Spring test so that others can have a look?
dkayiwa
(Daniel Kayiwa)
October 21, 2019, 10:16pm
14
Where is the source code for the icrc
module which has the above activator?
wyclif
(Wyclif Luyima)
October 22, 2019, 1:03am
15
@sakthi the event module creates an embedded activemq instance so you don’t have no create one.
Please write a unit test instead for your listener.
premnisha
(Premnisha Balakumar)
October 23, 2019, 5:26am
16
We were able to get it working during debugging. Adding the second param while creating the subscription got it working
Event.subscribe(Encounter.class, Event.Action.CREATED.name(), getEncounterListener());
Thanks everyone for the support !