Camunda Spring-Boot REST 客户端

Camunda Spring-Boot REST 客户端

github仓库地址: camunda-rest-client-spring-boot

1.增加依赖

<properties>
  <camunda-rest-client-spring-boot.version>0.0.3camunda-rest-client-spring-boot.version>
  <spring-cloud.version>Hoxton.SR2spring-cloud.version>
properties>

<dependencyManagement>
  <dependencies>
    <dependency>
      <groupId>org.springframework.cloudgroupId>
      <artifactId>spring-cloud-dependenciesartifactId>
      <version>${spring-cloud.version}version>
      <type>pomtype>
      <scope>importscope>
    dependency>
  dependencies>
dependencyManagement>
<dependencies>
    <dependency>
      <groupId>org.camunda.bpm.extension.restgroupId>
      <artifactId>camunda-rest-client-spring-boot-starterartifactId>
      <version>${camunda-rest-client-spring-boot.version}version>
    dependency>
    <dependency>
      <groupId>org.springframework.cloudgroupId>
      <artifactId>spring-cloud-starter-openfeignartifactId>
    dependency>
    <dependency>
      <groupId>io.github.openfeigngroupId>
      <artifactId>feign-httpclientartifactId>
    dependency>
dependencies>

2.配置

在客户端代码中增加配置,使用@EnableCamundaRestClient激活REST client

@Configuration
@EnableCamundaRestClient
public class MyClientConfiguration {

}

在工程中的application.yml文件中增加feign配置。

feign:
  client:
    config:
      remoteRuntimeService:
        url: "http://your-process-engine-host/rest/engine/default/"

3.使用

需要访问远程API时,注入远程API。

@Component
public class MyClient {

    private RuntimeService runtimeService;

    public MyClient(@Qualifier("remote") RuntimeService runtimeService) {
        this.runtimeService = runtimeService;
    }

    public void start() {
        this.runtimeService
            .startProcessInstanceByKey("my_process_key");
    }

    public void correlate() {
        this.runtimeService
            .createMessageCorrelation("message_received")
            .processInstanceBusinessKey("WAIT_FOR_MESSAGE")
            .correlateAllWithResult();
    }
}

你可能感兴趣的:(Camunda)