Flowable Listener with Springboot

Hi everyone, I’m new on Flowable.
I’m integrating FLowable 7.0.1 into a Springboot 3.2.2 project

Is it possible to create a TaskListener where it reached for a specific type of Task?

For example in Camunda 7 I did something like this…

@Component
@CamundaSelector(type = ActivityTypes.TASK_SERVICE)
public class ServiceTaskListener implements ExecutionListener {

@Override
public void notify(DelegateExecution execution) throws Exception {
…some code…
}
}

and then I registered the ServiceTaskListener bean in the ProcessEngineConfiguration when starting Springboot.

This way any bpmn flow that had a service task… in any event was triggered!

Is there a similar way on Flowable with Springboot?
Thanks a lot!
Armando

Yes,

  1. Implement listener as usual. :slight_smile:
  2. add listener to any task you like in the model
    1.1 manually
    <endEvent id="theEnd" name="End event" activiti:async="true">
      <extensionElements>
        <activiti:executionListener event="start" class="org.flowable.examples.bpmn.executionlistener.ExampleExecutionListenerOne"></activiti:executionListener>
      </extensionElements>
    </endEvent>

1.2 automatically: Advanced · Flowable Open Source Documentation

Regards
Martin

1 Like

Hey @martin.grofcik and @Armando,

When using Spring components as listeners I would not advise in using the class approach for this, as it means that Flowable is going to create the instance and that won’t do any Spring injections.

The approach that you are looking for is what Martin linked with Advanced · Flowable Open Source Documentation.

You’ll need to create a custom ParseHandler and register that.

So something like:

public class CustomServiceTaskParseHandler extends AbstractActivityBpmnParseHandler<ServiceTask> {

    @Override
    protected Class<? extends BaseElement> getHandledType() {
        return ServiceTask.class;
    }

    @Override
    protected void executeParse(BpmnParse bpmnParse, ServiceTask serviceTask) {
        FlowableListener executionListener = new FlowableListener();
        executionListener.setImplementationType(ImplementationType.IMPLEMENTATION_TYPE_DELEGATEEXPRESSION);
        executionListener.setImplementation("${myServiceTaskListener}");
        serviceTask.getExecutionListeners()
                .add(executionListener);

    }
}

myServiceTaskListener is the name of the Spring Bean in the application context.

You can register the parse handler by setting the postBpmnParseHandlers list.

Cheers,
Filip

1 Like

thank you for the reply.
I had seen this example…but it’s not what I meant. Because here you are doing it manually. That is, you’re saying when you’re in this flow and there’s an endEvent state, it triggers this listener.
Instead I would like it to be triggered without saying it manually at a step of the flow, but dynamically at all the endEvent or all the UserTask or all the ServiceTask of any flow that exists in the ProcessEmgineConfiguration. I hope I explained myself :slight_smile:

thanks for the answer.

It seems like a good approach to me.

So for any element like in this case it is the ServiceTask, can I also trigger other elements like a UserTask?

public class CustomServiceTaskParseHandler extends AbstractActivityBpmnParseHandler {

thanks
Armando

Use
1.2 automatically: Advanced · Flowable Open Source Documentation

Regards
Martin

Yes you can do it for a user task as well. You can do it for any element.

public class CustomParseHandler implements BpmnParseHandler {

    @Override
    public Collection<Class<? extends BaseElement>> getHandledTypes() {
        return Set.of(ServiceTask.class, UserTask.class);
    }

    @Override
    public void parse(BpmnParse bpmnParse, BaseElement element) {
        Task task = (Task) element;
        FlowableListener executionListener = new FlowableListener();
        executionListener.setImplementationType(ImplementationType.IMPLEMENTATION_TYPE_DELEGATEEXPRESSION);
        executionListener.setImplementation("${myServiceTaskListener}");
        task.getExecutionListeners()
                .add(executionListener);
    }
}
1 Like