客户端像调用本地方法一样调用引擎中的接口。
https://docs.camunda.org/manual/7.17/reference/rest/
一:pom.xml
<dependency><groupId>org.camunda.community.rest</groupId><artifactId>camunda-platform-7-rest-client-spring-boot-starter</artifactId><version>7.17.2</version>
</dependency>
<dependency><groupId>com.fasterxml.jackson.datatype</groupId><artifactId>jackson-datatype-jdk8</artifactId><version>2.13.3</version>
</dependency>
<dependency><groupId>com.fasterxml.jackson.datatype</groupId><artifactId>jackson-datatype-jsr310</artifactId><version>2.13.3</version>
</dependency>
<dependency><groupId>com.fasterxml.jackson.module</groupId><artifactId>jackson-module-kotlin</artifactId><version>2.13.3</version>
</dependency><dependency><groupId>org.springframework.cloud</groupId><artifactId>spring-cloud-starter-openfeign</artifactId><version>3.1.3</version>
</dependency>
<dependency><groupId>io.github.openfeign</groupId><artifactId>feign-httpclient</artifactId><version>11.8</version>
</dependency>
二:application.yml
server:port: 8081spring:datasource:url: jdbc:mysql://localhost:3306/camunda?useUnicode=true&characterEncoding=utf8&serverTimezone=Asia/Shanghai&&nullCatalogMeansCurrent=trueusername: rootpassword: root123driver-class-name: com.mysql.cj.jdbc.Drivercamunda:bpm:client:base-url: http://localhost:8080/engine-restmax-tasks: 1worker-id: springboot-camunda-clientasync-response-timeout: 20000lock-duration: 10000basic-auth:username: adminpassword: 123456feign:client:config:processInstance.url: ${camunda.bpm.client.base-url}processDefinition.url: ${camunda.bpm.client.base-url}message.url: ${camunda.bpm.client.base-url}signal.url: ${camunda.bpm.client.base-url}execution.url: ${camunda.bpm.client.base-url}task.url: ${camunda.bpm.client.base-url}taskVariable.url: ${camunda.bpm.client.base-url}taskLocalVariable.url: ${camunda.bpm.client.base-url}taskIdentityLink.url: ${camunda.bpm.client.base-url}externalTask.url: ${camunda.bpm.client.base-url}incident.url: ${camunda.bpm.client.base-url}historicProcessInstance.url: ${camunda.bpm.client.base-url}deployment.url: ${camunda.bpm.client.base-url}
三:开启
@SpringBootApplication
@EnableCamundaRestClient
public class SprigbootCamundaClientApplication {public static void main(String[] args) {SpringApplication.run(SprigbootCamundaClientApplication.class, args);}
}
四:test
package com.example.client;import org.camunda.bpm.engine.HistoryService;
import org.camunda.bpm.engine.RepositoryService;
import org.camunda.bpm.engine.RuntimeService;
import org.camunda.bpm.engine.repository.Deployment;
import org.camunda.bpm.engine.repository.ProcessDefinition;
import org.camunda.bpm.engine.runtime.ProcessInstance;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;import java.util.List;@RestController
public class RestClientTestController {private RuntimeService runtimeService;private RepositoryService repositoryService;private HistoryService historyService;public RestClientTestController(@Qualifier("remote")RuntimeService runtimeService,@Qualifier("remote")RepositoryService repositoryService,@Qualifier("remote")HistoryService historyService) {this.runtimeService = runtimeService;this.repositoryService = repositoryService;this.historyService = historyService;}@GetMapping("/test")public List<Deployment> test() {List<Deployment> list = repositoryService.createDeploymentQuery().list();return list;}
}