上篇我们讲了通过接口方式去调用任务执行,在介绍camunda的任务之前,我们先说说任务的实现,从modeler可以看到,实现方式,主要分为5种
- Java Class
- Expression
- Delegate Exoression
- External
- Connector
1.Java Class
public class SendTaskDelegate implements JavaDelegate {
@Override
public void execute(DelegateExecution execution) throws Exception {
System.out.println("java class test");
}
}
2.Expression
@Component(value = "taskExpression")
public class TaskExpression {
public String test(){
System.out.println("expression test");
return "express";
}
}
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");
}
}
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");
});
}
5.Connector
connetcor的用法,这个需要看下文档的 https://docs.camunda.org/manual/7.16/user-guide/process-engine/connectors/
添加依赖
<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
相关参数的设置 : 入参->https://docs.camunda.org/manual/7.16/reference/connect/http-connector/#using-the-generic-api
写一个接口来被调用
@GetMapping("connector")
public String connector(){
System.out.println("connector test");
return "connector";
}
以上,就是service task的几种实现方式。