Hook events from camunda UserTask

眉间皱痕 提交于 2021-01-29 21:05:46

问题


I want to hook events from UserTask as describing in this article: https://docs.camunda.org/manual/latest/user-guide/spring-boot-integration/the-spring-event-bridge/

My listener:

@Component
@Slf4j
public class MyListener {
    public MyListener() {
        log.debug("[MyListener] create");
    }

    @EventListener
    public void onTaskEvent(DelegateTask taskDelegate) {
        log.debug("[DelegateTask] id" + taskDelegate.getId());
    }

    @EventListener
    public void onTaskEvent(TaskEvent taskEvent) {
        log.debug("[TaskEvent] id" + taskEvent.getId());
    }
}

I added properties:

camunda.bpm.eventing.execution=true
camunda.bpm.eventing.history=true
camunda.bpm.eventing.task=true

dependency:

    <dependency>
        <groupId>org.camunda.bpm.springboot</groupId>
        <artifactId>camunda-bpm-spring-boot-starter</artifactId>
        <version>${camunda.spring.version}</version>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-jdbc</artifactId>
        <version>${springboot.version}</version>
    </dependency>
    ....
    and other

version: springboot = 2.2.5.RELEASE camunda = 7.13.0

when I start BPM process I don't view any log messages from onTaskEvent myListener, only "[MyListener] create." after start application. In cockpit I see started process and active task. If userTask already have one expression type taskListener in bpm, it is may be reason? what could be the problem? perhaps need some more data to understand it?

Thanks.


回答1:


  • Have you checked if the Spring class path scanning correctly picked up and registered your @Component? If the Listener implementation accidentally is not placed in the package hierarchy below the Spring Boot Application class, then it will not get registered automatically.

  • How are you testing? Spring components will only get picked up if you run a SpringBootTest. A plain Java test using the @Rule ProcessEngineRule is not sufficient.

  • If the component was detected correctly (and your new properties were published correctly) then you should be able to observe that the @EventListener methods get invoked (e.g. set a break point and check if debugger stops there).

You should see log output similar to this if the properties are set correctly:

INFO  o.c.b.s.b.s.e.EventPublisherPlugin - EVENTING-001: Initialized Camunda Spring Boot Eventing Engine Plugin. 
INFO  o.c.b.s.b.s.e.EventPublisherPlugin - EVENTING-003: Task events will be published as Spring Events. 
INFO  o.c.b.s.b.s.e.EventPublisherPlugin - EVENTING-005: Execution events will be published as Spring Events. 
INFO  o.c.b.s.b.s.e.EventPublisherPlugin - EVENTING-007: History events will be published as Spring events.
  • You may not see the listener output due to your logging configuration.

Anyway, here is a lightweight working example, which writes to STOUT and a log file. (Just run mvn test and find the log in the target folder or watch the console output as you step through the process)



来源:https://stackoverflow.com/questions/63933392/hook-events-from-camunda-usertask

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!