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
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.
Hmm, the second post should work - do you have a way and set a breakpoint and see what happens in the MembershipEntityManagerImpl#createMembership method?
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:
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.
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).
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)
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?
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.
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.