来自 camunda UserTask 的钩子事件 [英] Hook events from camunda UserTask

查看:119
本文介绍了来自 camunda UserTask 的钩子事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想从 UserTask 中挂钩事件,如本文所述:https://docs.camunda.org/manual/latest/user-guide/spring-boot-integration/the-spring-event-bridge/

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/

我的听众:

@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());
    }
}

我添加了属性:

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

依赖:

    <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

版本:springboot = 2.2.5.RELEASE卡蒙达 = 7.13.0

version: springboot = 2.2.5.RELEASE camunda = 7.13.0

当我启动 BPM 流程时,我不会查看来自 onTaskEvent myListener 的任何日志消息,只有[MyListener] 创建".开始申请后.在驾驶舱中,我看到启动的进程和活动的任务.如果 userTask 在 bpm 中已经有一个表达式类型 taskListener ,这可能是原因吗?可能是什么问题?也许需要更多的数据来理解它?

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?

谢谢.

推荐答案

  • 您是否检查过 Spring 类路径扫描是否正确拾取并注册了您的 @Component?如果 Listener 实现不小心没有放在 Spring Boot Application 类下面的包层次结构中,那么它不会自动注册.

    • 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.

      你是如何测试的?只有在您运行 SpringBootTest 时才会拾取 Spring 组件.使用 @Rule ProcessEngineRule 的纯 Java 测试是不够的.

      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.

      如果组件被正确检测(并且您的新属性已正确发布),那么您应该能够观察到@EventListener 方法被调用(例如设置断点并检查调试器是否在那里停止).

      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.
      

      • 由于您的日志记录配置,您可能看不到侦听器输出.
      • 无论如何,这是一个轻量级的工作示例,写入 STOUT 和日志文件.(只需运行 mvn test 并在目标文件夹中找到日志或在逐步执行该过程时观察控制台输出)

        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)

        这篇关于来自 camunda UserTask 的钩子事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆