文章
问答
冒泡
四、camunda学习-camunda中task的几种实现
上篇我们讲了通过接口方式去调用任务执行,在介绍camunda的任务之前,我们先说说任务的实现,从modeler可以看到,实现方式,主要分为5种
  • Java Class
  • Expression
  • Delegate Exoression
  • External
  • Connector
0
1.Java Class
public class SendTaskDelegate implements JavaDelegate {
    @Override
    public void execute(DelegateExecution execution) throws Exception {
        System.out.println("java class test");
    }
}

 

0
2.Expression
@Component(value = "taskExpression")
public class TaskExpression {
    public String test(){
        System.out.println("expression test");
        return "express";
    }
}
 
0
 
3.Delegate Exoression
@Component(value = "taskDelegate")
public class SendTaskDelegate implements JavaDelegate {
    @Override
    public void execute(DelegateExecution execution) throws Exception {
        System.out.println("java class test");
    }
}
0
 
4.External
@PostMapping("external-tasks")
public void externalTask(){
    List<LockedExternalTask> lockedExternalTasks =  externalTaskService.fetchAndLock(10,"testExternalTaskId").topic("ExternalTopic",60L*1000).execute();
    lockedExternalTasks.forEach(t->{
        System.out.println("external task test");
        externalTaskService.complete(t.getId(),"testExternalTaskId");
    });
}
 
0
 
5.Connector
添加依赖
<dependency>
    <groupId>org.camunda.bpm</groupId>
    <artifactId>camunda-engine-plugin-connect</artifactId>
</dependency>
<dependency>
    <groupId>org.camunda.connect</groupId>
    <artifactId>camunda-connect-http-client</artifactId>
</dependency>
<dependency>
    <groupId>org.camunda.bpm</groupId>
    <artifactId>camunda-engine-plugin-spin</artifactId>
</dependency>
<dependency>
    <groupId>org.camunda.spin</groupId>
    <artifactId>camunda-spin-dataformat-json-jackson</artifactId>
</dependency>
从文档可以看出,官方支持的connector id 分别是 http-connector 和 soap-http-connector
 
写一个接口来被调用
@GetMapping("connector")
public String connector(){
    System.out.println("connector test");
    return "connector";
}
0
 
0
 
以上,就是service task的几种实现方式。
camunda

关于作者

落雁沙
非典型码农
获得点赞
文章被阅读