Unable to setup Encounter Event Listener using openmrs-module-event

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;

public class EncounterEventListenerImpl implements EventListener {
	private Log log = LogFactory.getLog(this.getClass());;
	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:

  1. https://github.com/openmrs/openmrs-module-event
  2. https://wiki.openmrs.org/display/docs/Event+Module
  3. https://github.com/IsantePlus/openmrs-module-xds-sender

Thanks in advance

Copying @mksd @wyclif

One thing that I notice by looking at those two examples:

  1. PatientViewedEventListener in EMR API,
  2. 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.

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");

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

Hello, i too am working on this problem with @premnisha. I changed the onMessage() method of EventListener to

	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

@sakthi could you debug the built-in one PatientViewedEventListener to see if it is working as expected? Do you ever get in there?

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

Actually null is fine, it means listen to all actions

You might want to confirm if activemq is getting initialized properly and that it is working.

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

Link to stack trace - https://pastebin.com/vtwPUpmk

@premnisha can you reproduce this in a Spring test so that others can have a look?

Where is the source code for the icrc module which has the above activator?

@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.

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 !