Best way to register own listener

Hi guys,
I’m looking for some information how to register an own listener in Spring Boot Starter. It has to be trigger each time the process starts. Thanks! :slight_smile:

I guess this is what I need: https://github.com/camunda/camunda-bpm-reactor

The only problem I have that “@EnableCamundaReactor” can’t be found.

checkout https://github.com/camunda/camunda-bpm-reactor/tree/1.2

the Enable-annotation is new in 1.5 which is not released yet. In 1.2, it is enough to have the camunda-reactor-starter on the classpath. This will change with 1.5 though. And: no, sorry, I do not know when it will be released yet.

Thank you very much :slight_smile:
2 additional questions:

  • Is it necessary to register an event in EventBus()? I saw the example where the event is being registered in constructor
  • Is it necessary to create any plugin for that?

Thanks!

Hi

the reactor extension has a plugin: https://github.com/camunda/camunda-bpm-reactor/blob/1.2/extension/core/src/main/java/org/camunda/bpm/extension/reactor/plugin/ReactorProcessEnginePlugin.java

this is automatically activated due to camunda-spring-boots plugin detection. So nothing to do here.

And you do not register en event, the events are fix, you register consumers for those events. So in your start event listener, you will need something like eventbus.register(this). Doing this in the constructor is one option, but having an

@Autowired 
void register(CamundaEventBus eventBus) { eventBus.register(this); } 

works too.

That’s what the https://github.com/camunda/camunda-bpm-reactor/blob/1.2/extension/spring/src/main/java/org/camunda/bpm/extension/reactor/spring/listener/ReactorTaskListener.java does, so if you could also just extend that.

Note: The eventBus is stable but discontinued, it works with projectreactor-2 and was dropped with projectreactor-3 … I am currently exploring how to adopt the behaviour using plain spring-eventlisteners, but the filtering options (listen on all task-create, listen only for end of startevent in particular process,…) are far less advanced. For now, I would suggest the setup you use: camunda-spring-boot-starter 2.1.2, camunda-reactor 1.2 and the camunda-reactor-starter to have all the beans (bus, plugin) autoconfiguered.

Thank you once again.

And still I think I’m doing something wrong.

My listener:

@Component
@CamundaSelector(type = "startEvent", event = ExecutionListener.EVENTNAME_END)
public class StartProcessListener implements ExecutionListener {

  Logger logger = LoggerFactory.getLogger(StartProcessListener.class);

  @Autowired
  void register(CamundaEventBus eventBus) {
    eventBus.register(this);
  }

  @Override
  public void notify(DelegateExecution delegateExecution) throws Exception {
    logger.warn("invoking...");
    String activityName = delegateExecution.getCurrentActivityName();
    int a = 0;
  }
}

pom.xml contains camunda-bpm-spring-boot-starter (2.1.2), camunda-bpm-reactor-core(1.2) and camunda-bpm-reactor-spring-starter (1.2).

I’m starting 100 process instances but there is nothing in logs.

Everything works. The problem was I’ve been starting the process too early.

1 Like

Any progress on this?

Well, its quite simple actually, you just have to register a parseListener that publishes the events viaApplicationEventPublisher and subscribe with a conditional @EventListener … I will have a look for an example …

Hi,

It would be great if you can post an example for parseListener and EventListener.

Thanks