How to add eventlistener in springboot

Hi, I want to add my eventlistener use flowable
Springboot. But I don’t how to do?

Hi,

I’m quite new to Flowable and I don’t know if it’s optimal way but here is how I did it.
Add

@Configuration
@AutoConfigureAfter(ProcessEngineAutoConfiguration.class)
public class ListenersConfiguration {

private static final Logger log = getLogger(ListenersConfiguration.class);

@Bean
@ConditionalOnClass(SpringProcessEngineConfiguration.class)
public EngineConfigurationConfigurer<SpringProcessEngineConfiguration> customizeSpringProcessEngineConfiguration() {
    return processEngineConfiguration -> {
        log.info("Overriding process engine configuration”);
        processEngineConfiguration.setEventListeners(Collections.singletonList(new MyEventListener()));
    };
}

}

where MyEventListener looks like:

public class MyEventListener implements FlowableEventListener {

@Override
public void onEvent(FlowableEvent event) {

    if(event.getType() == FlowableEngineEventType.PROCESS_COMPLETED) {
        System.out.println("Process completed ");
    } else if (event.getType() == FlowableEngineEventType.JOB_EXECUTION_FAILURE) {
        System.out.println("A job has failed…”);
    } else {
        System.out.println("Event received: " + event.getType());
    }
}

@Override
public boolean isFailOnException() {
    // The logic in the onEvent method of this listener is not critical, exceptions
    // can be ignored if logging fails…
    return false;
}

@Override
public boolean isFireOnTransactionLifecycleEvent() {
    return false;
}

@Override
public String getOnTransaction() {
    return null;
}
}
1 Like