# Event register problem

**URL:** <https://forum.flowable.org/t/event-register-problem/7056>\
**Category:** Uncategorized\
**Created:** [November 10, 2020, 9:15pm UTC](https://forum.flowable.org/t/event-register-problem/7056 "2020-11-10T21:15:43Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![douglascrp](https://yyz1.discourse-cdn.com/flex035/user_avatar/forum.flowable.org/douglascrp/32/306_2.png) [@douglascrp](https://forum.flowable.org/u/douglascrp)\
**Post date:** [November 10, 2020, 9:15pm UTC](https://forum.flowable.org/t/event-register-problem/7056/1 "2020-11-10T21:15:43Z")

</div>

Hello.

I am trying to write some logic to do the assignment of multi-instance tasks when new members are included in some groups, but I am finding a hard time trying to register to receive such events.

If I register the listener using the code below, I receive lots of events, all from FlowableEngineEventType

```auto
runtimeService.addEventListener(new MembershipCreatedEventListener());

```

But using that, I receive nothing from IDM, like FlowableIdmEventType.MEMBERSHIP\_CREATE

What is the right way to register for the FlowableIdmEventType types?

I have also tried with this:

```auto
ProcessEngines.getDefaultProcessEngine().getProcessEngineConfiguration().getEventDispatcher().addEventListener(new MembershipCreatedEventListener());

```

But again, nothing changes.

My code is packaged into a jar file, and I am deploying it inside the flowable-task/WEB-INF/lib folder.

Thank you.

---

<div class="post-metadata">

**Author:** ![douglascrp](https://yyz1.discourse-cdn.com/flex035/user_avatar/forum.flowable.org/douglascrp/32/306_2.png) [@douglascrp](https://forum.flowable.org/u/douglascrp)\
**Post date:** [November 11, 2020, 1:51pm UTC](https://forum.flowable.org/t/event-register-problem/7056/2 "2020-11-11T13:51:37Z")

</div>

Good morning.

Just to register here, one more test that I have done, with no success.

I tried to register the listener with

```auto
IdmEngines.getDefaultIdmEngine().getIdmEngineConfiguration().getEventDispatcher().addEventListene
r(new MembershipCreatedEventListener());

```

Besides that, I have also tried to deploy the resulting jar both inside the flowable-task and inside flowable-idm, but again, I got nothing from the event dispatcher.

---

<div class="post-metadata">

**Author:** ![joram](https://yyz1.discourse-cdn.com/flex035/user_avatar/forum.flowable.org/joram/32/26_2.png) [@joram](https://forum.flowable.org/u/joram)\
**Post date:** [November 16, 2020, 8:28pm UTC](https://forum.flowable.org/t/event-register-problem/7056/3 "2020-11-16T20:28:04Z")

</div>

Hmm, the second post should work - do you have a way and set a breakpoint and see what happens in the MembershipEntityManagerImpl#createMembership method?

Worst case, you’d be able to listen to generic entity events and check for the membership entity. However, the logic above should work, see also the test here: [https://github.com/flowable/flowable-engine/blob/master/modules/flowable-engine/src/test/java/org/flowable/engine/test/api/event/GroupEventsTest.java#L110](https://github.com/flowable/flowable-engine/blob/master/modules/flowable-engine/src/test/java/org/flowable/engine/test/api/event/GroupEventsTest.java#L110)

---

<div class="post-metadata">

**Author:** ![douglascrp](https://yyz1.discourse-cdn.com/flex035/user_avatar/forum.flowable.org/douglascrp/32/306_2.png) [@douglascrp](https://forum.flowable.org/u/douglascrp)\
**Post date:** [November 18, 2020, 7:21pm UTC](https://forum.flowable.org/t/event-register-problem/7056/4 "2020-11-18T19:21:24Z")

</div>

Hello  
Thank you for your answer, and sorry for the late response.  
I was debugging flowable’s source code, and it seems the code creating the event is reached, but for some reason, the notification is not received by the listener.  
And today, doing some more tests, I found the following in the code:

> <https://github.com/flowable/flowable-engine/blob/master/modules/flowable-engine-common/src/main/java/org/flowable/common/engine/impl/AbstractEngineConfiguration.java#L1774>

Am I wrong when I think such code is ignoring the types defined by the FlowableIdmEventType class?

The mentioned code seems to be searching by the events by the string, and in the case of FlowableIdmEventType.MEMBERSHIP\_CREATED, it is not there.

I am going to keep testing everything and will be back with more information if I find something useful.

---

<div class="post-metadata">

**Author:** ![douglascrp](https://yyz1.discourse-cdn.com/flex035/user_avatar/forum.flowable.org/douglascrp/32/306_2.png) [@douglascrp](https://forum.flowable.org/u/douglascrp)\
**Post date:** [November 18, 2020, 8:05pm UTC](https://forum.flowable.org/t/event-register-problem/7056/5 "2020-11-18T20:05:59Z")

</div>

And another test.

When the membership is created or removed, the request to dispatch the events are executed, but when the code reaches [https://github.com/flowable/flowable-engine/blob/88d6bbf60b719a7b30a9eea153f78b2408e79d82/modules/flowable-engine-common/src/main/java/org/flowable/common/engine/impl/event/FlowableEventSupport.java#L87](https://github.com/flowable/flowable-engine/blob/88d6bbf60b719a7b30a9eea153f78b2408e79d82/modules/flowable-engine-common/src/main/java/org/flowable/common/engine/impl/event/FlowableEventSupport.java#L87)

both variables eventListeners and typedListeners are empty

> <https://github.com/flowable/flowable-engine/blob/88d6bbf60b719a7b30a9eea153f78b2408e79d82/modules/flowable-engine-common/src/main/java/org/flowable/common/engine/impl/event/FlowableEventSupport.java#L97>

  

> <https://github.com/flowable/flowable-engine/blob/88d6bbf60b719a7b30a9eea153f78b2408e79d82/modules/flowable-engine-common/src/main/java/org/flowable/common/engine/impl/event/FlowableEventSupport.java#L105>

and because of that, no real event is dispatched.

Any idea on how to proceed with this?

Do you think my previous question makes sense?

---

<div class="post-metadata">

**Author:** ![filiphr](https://yyz1.discourse-cdn.com/flex035/user_avatar/forum.flowable.org/filiphr/32/315_2.png) [@filiphr](https://forum.flowable.org/u/filiphr)\
**Post date:** [November 19, 2020, 7:22am UTC](https://forum.flowable.org/t/event-register-problem/7056/6 "2020-11-19T07:22:00Z")

</div>

Hey @douglascrp,

When are you doing `IdmEngines.getDefaultIdmEngine().getIdmEngineConfiguration().getEventDispatcher().addEventListene r(new MembershipCreatedEventListener());`?

If you are repacking your jar and adding it to the `flowable-task` I would suggest you to use Spring Boot auto configuration and register your events like that. Perhaps invoking `IdmEngines.getDefaultIdmEngine()` is too early and has not been created by Spring.

What you shared should work (the registering by getting the event dispatcher and adding the event).

Cheers,  
Filip

---

<div class="post-metadata">

**Author:** ![douglascrp](https://yyz1.discourse-cdn.com/flex035/user_avatar/forum.flowable.org/douglascrp/32/306_2.png) [@douglascrp](https://forum.flowable.org/u/douglascrp)\
**Post date:** [November 20, 2020, 5:38pm UTC](https://forum.flowable.org/t/event-register-problem/7056/7 "2020-11-20T17:38:18Z")

</div>

Hello.

This is the class with all the tests I have done so far (all commented, but I’ve tried all of the options, one at a time)

```auto
package br.com.dgcloud.flowable;

import java.util.List;

import org.flowable.common.engine.impl.event.FlowableEventSupport;
import org.flowable.engine.HistoryService;
import org.flowable.engine.ProcessEngine;
import org.flowable.engine.ProcessEngines;
import org.flowable.engine.RepositoryService;
import org.flowable.engine.RuntimeService;
import org.flowable.engine.TaskService;
import org.flowable.engine.history.HistoricActivityInstance;
import org.flowable.idm.api.event.FlowableIdmEventType;
import org.flowable.idm.engine.IdmEngines;
import org.flowable.spring.boot.EngineConfigurationConfigurer;
import org.flowable.task.api.history.HistoricTaskInstance;
import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.autoconfigure.AutoConfigureOrder;
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.Ordered;
import org.flowable.spring.SpringProcessEngineConfiguration;

import br.com.dgcloud.events.MembershipCreatedEventListener;

@Configuration
@AutoConfigureOrder(Ordered.LOWEST_PRECEDENCE)
@ConditionalOnBean(type = "org.flowable.engine.ProcessEngine")
public class CustomConfiguration {

   @Configuration
   @ComponentScan({ "br.com.dgcloud.flowable" })
   public static class ComponentScanConfiguration {
   	// This class is needed in order to conditionally perform the component scan
   	// (i.e. when the ProcessEngine bean is present)
   	// It is an optional class, in case you don't need component scanning then you
   	// don't need to do this
   }

   @Bean
   public EngineConfigurationConfigurer<SpringProcessEngineConfiguration> customProcessEngineConfigurationConfigurer() {
   	return engineConfiguration -> {
   		// You can use this to add extra configuration to the process engine
           //IdmEngines.getDefaultIdmEngine().getIdmEngineConfiguration().getEventDispatcher().addEventListener(new MembershipCreatedEventListener(), FlowableIdmEventType.MEMBERSHIP_CREATED);
           //IdmEngines.getDefaultIdmEngine().getIdmEngineConfiguration().getEventDispatcher().addEventListener(new MembershipCreatedEventListener());
   		
   		// getEventDispatcher() == null
   		//engineConfiguration.getEventDispatcher().addEventListener(new MembershipCreatedEventListener(), FlowableIdmEventType.MEMBERSHIP_CREATED);
   	};
   }

   @Bean
   public CommandLineRunner init(final RepositoryService repositoryService, final RuntimeService runtimeService,
   		final TaskService taskService) {
   	return new CommandLineRunner() {
   		@Override
   		public void run(String... strings) throws Exception {
   			//runtimeService.addEventListener(new MembershipCreatedEventListener());
   			//runtimeService.addEventListener(new MembershipCreatedEventListener(), FlowableIdmEventType.MEMBERSHIP_CREATED);

               //ProcessEngines.getDefaultProcessEngine().getProcessEngineConfiguration().getEventDispatcher().addEventListener(new MembershipCreatedEventListener());
               //IdmEngines.getDefaultIdmEngine().getIdmEngineConfiguration().getEventDispatcher().addEventListener(new MembershipCreatedEventListener());
               //IdmEngines.getDefaultIdmEngine().getIdmEngineConfiguration().getEventDispatcher().addEventListener(new MembershipCreatedEventListener(), FlowableIdmEventType.MEMBERSHIP_CREATED);
               
               //processEngineConfiguration.getEventDispatcher().addEventListener(membershipListener);

               //runtimeService.addEventListener(new MembershipCreatedEventListener(), FlowableEngineEventType.TASK_ASSIGNED);
               //runtimeService.addEventListener(new MembershipCreatedEventListener(), FlowableEngineEventType.TASK_COMPLETED);
   		}
   	};
   }
}

```

Nothing works… I receive notifications for everything, except for the IDM ones.

Is it too much to ask somebody to try to create a sample project with these events working?

Thank you all.

---

<div class="post-metadata">

**Author:** ![douglascrp](https://yyz1.discourse-cdn.com/flex035/user_avatar/forum.flowable.org/douglascrp/32/306_2.png) [@douglascrp](https://forum.flowable.org/u/douglascrp)\
**Post date:** [November 20, 2020, 8:27pm UTC](https://forum.flowable.org/t/event-register-problem/7056/8 "2020-11-20T20:27:06Z")

</div>

The latest attempt for the week.

```auto
package br.com.dgcloud.flowable;

import org.flowable.engine.ProcessEngines;
import org.flowable.engine.RepositoryService;
import org.flowable.engine.RuntimeService;
import org.flowable.engine.TaskService;
import org.flowable.idm.engine.IdmEngines;
import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.autoconfigure.AutoConfigureOrder;
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.Ordered;

import br.com.dgcloud.flowable.events.GroupFlowableEventListener;

@Configuration
// Makes sure that this configuration will be processed last by Spring Boot
@AutoConfigureOrder(Ordered.LOWEST_PRECEDENCE)
//The configuration will only be used when the ProcessEngine bean is present
//@ConditionalOnBean(type = {"org.flowable.engine.ProcessEngine", "org.flowable.idm.engine.IdmEngine"})
@ConditionalOnBean(type = {"org.flowable.idm.engine.IdmEngine"})
public class CustomConfiguration {

	@Bean
	public CommandLineRunner init(final RepositoryService repositoryService, final RuntimeService runtimeService,
			final TaskService taskService) {
		return new CommandLineRunner() {
			@Override
			public void run(String... strings) throws Exception {

				if (ProcessEngines.getDefaultProcessEngine().getProcessEngineConfiguration().getEventDispatcher() != null) {
					
					ProcessEngines.getDefaultProcessEngine().getProcessEngineConfiguration().getEventDispatcher().addEventListener(new GroupFlowableEventListener());
					
				} else {
					System.out.println("DG: Event Dispatcher Process nulo");
				}
				
				if (IdmEngines.getDefaultIdmEngine().getIdmEngineConfiguration().getEventDispatcher() != null) {
					
					IdmEngines.getDefaultIdmEngine().getIdmEngineConfiguration().getEventDispatcher().addEventListener(new GroupFlowableEventListener());
					
				} else {
					System.out.println("DG: Event Dispatcher IDM nulo");
				}
				
			}
		};
	}
}

```

With this code, the event listener class receives all kind of events, but nothing from IDM.  
I can see events for entities, tasks, flows, everything, except for the IDM related ones.

I have no idea what else to try.

---

<div class="post-metadata">

**Author:** ![douglascrp](https://yyz1.discourse-cdn.com/flex035/user_avatar/forum.flowable.org/douglascrp/32/306_2.png) [@douglascrp](https://forum.flowable.org/u/douglascrp)\
**Post date:** [November 23, 2020, 2:25pm UTC](https://forum.flowable.org/t/event-register-problem/7056/9 "2020-11-23T14:25:32Z")

</div>

Good morning all.

Rereading the docs, I found this:

> **[Configuration · Flowable Open Source Documentation](https://www.flowable.com/open-source/docs/bpmn/ch03-Configuration/)**
>
> \## Creating a ProcessEngine

> **Listeners are only notified for events dispatched from the engine they are registered with.** So if you have different engines - running against the same database - only events that originated in the engine the listener is registered to are dispatched to that listener. The events that occur in other engines are not dispatched to the listeners, regardless of whether they are running in the same JVM or not.

So maybe the problem is because I am deploying my custom code inside flowable-task, and the event is fired by flowable-idm.  
As I’m using the 6.5 version, I have the multi-apps setup, so maybe if I use the new version 6.6, with the single app, the problem can go away.

I think I 'm going to test it.

---

<div class="post-metadata">

**Author:** ![douglascrp](https://yyz1.discourse-cdn.com/flex035/user_avatar/forum.flowable.org/douglascrp/32/306_2.png) [@douglascrp](https://forum.flowable.org/u/douglascrp)\
**Post date:** [November 23, 2020, 7:53pm UTC](https://forum.flowable.org/t/event-register-problem/7056/10 "2020-11-23T19:53:12Z")

</div>

Yes, using the single app way with Flowable 6.6 did the trick.

Now the event is received by the event listener.

Once I finish the solution, I will post something here in order to let it as a reference for the future.

Thank you all for the help
