使用Camunda进行基于REST和工作流引擎的便捷编排(无Java)

哈Ha!敬请关注BerndRücker的文章“使用Camunda作为基于REST的易于使用的业务流程和工作流引擎(无需接触Java)”的翻译。



2020年7月7日伯恩德·吕克(BerndRücker)翻译该文章





使用Camunda进行便捷的编排



, Java: C#, Node.JS/JavaScript Golang. , , -, Saga .



BPM- Camunda . — . , , «» Camunda Java-. , Java. ?



! , Camunda - Java , . :



  • ;
  • REST API;
  • , Java;
  • C # Node.JS;
  • Camunda (Docker Tomcat).




Camunda Java Java (JVM). Camunda REST API, , , REST Camunda:



使用Camunda进行便捷的编排



Camunda BPMN, XML-. Camunda Modeler.



Camunda Docker



Camunda — Docker. Camunda .



使用Camunda进行便捷的编排



:



  docker run -d -p 8080:8080 camunda/camunda-bpm-platform:latest


Linux, Java Tomcats. Dockerfiles (, ) Github.



Camunda Enterprise Edition, Dockerfile.



Camunda Docker : Tomcat, . - , Docker- Tomcat, , , .





, Saga , . BPMN :



使用Camunda进行便捷的编排



REST API . , trip.bpmn Camunda Docker, localhost: 8080:



  curl -w "\n" \
-H "Accept: application/json" \
-F "deployment-name=trip" \
-F "enable-duplicate-filtering=true" \
-F "deploy-changed-only=true" \
-F "trip.bpmn=@trip.bpmn" \
http://localhost:8080/engine-rest/deployment/creat


REST API , :



  curl \
-H "Content-Type: application/json" \
-X POST \
-d '{"variables":{"someData" : {"value" : "someValue", "type": "String"}},"businessKey" : "12345"}}' \
http://localhost:8080/engine-rest/<!-- -->process-definition/key/<!-- -->FlowingTripBookingSaga<!-- -->/start


: Camunda , ? Camunda (Push-Principle), , . worker REST, Camunda (Pull-Principle).



使用Camunda进行便捷的编排



, fetchAndLock ( worker ):



  curl \
-H "Content-Type: application/json" \
-X POST \
-d <!-- -->'{"workerId":"worker123","maxTasks":1,"usePriority":true,"topics":[{"topicName": "reserve-car"}, "lockDuration": 10000, "variables": ["someData"]}]}'<!-- --> \
http://localhost:8080/engine-rest/external-task/fetchAndLock


Camunda, worker ( , external task, ):



  curl \
-H "Content-Type: application/json" \
-X POST \
-d <!-- -->'{"workerId":"worker123", "variables": {}}'<!-- --> \
http://localhost:8080/engine-rest/<!-- -->external-task/EXTERNAL_TASK_ID/complete


— Java, ? !





REST API . JavaScript JQuery, C# — System.Net.Http Newtonsoft.Json. . - .



:



  • JavaScript: . Camunda;
  • Java: . Camunda;
  • C#: . , ;
  • PHP: — API , , .

JavaScript Java, Camunda. , REST API Camunda. , , , REST API Camunda. .



C#



, :



  var camunda = new CamundaEngineClient("http://localhost:8080/engine-rest/engine/default/", null, null);
  // Deploy the BPMN XML file from the resources
  camunda.RepositoryService.Deploy("trip-booking", new List<object> {
        FileParameter.FromManifestResource(Assembly.GetExecutingAssembly(), "FlowingTripBookingSaga.Models.FlowingTripBookingSaga.bpmn")
     });
  
  // Register workers
  registerWorker("reserve-car", externalTask => {
    // here you can do the real thing! Like a sysout :-)
    Console.WriteLine("Reserving car now...");
    camunda.ExternalTaskService.Complete(workerId, externalTask.Id);
  });
  registerWorker("cancel-car", externalTask => {
    Console.WriteLine("Cancelling car now...");
    camunda.ExternalTaskService.Complete(workerId, externalTask.Id);
  });
  registerWorker("book-hotel", externalTask => {
    Console.WriteLine("Reserving hotel now...");
    camunda.ExternalTaskService.Complete(workerId, externalTask.Id);
  });
  // Register more workers...
  
  StartPolling();
  
  string processInstanceId = camunda.BpmnWorkflowService.StartProcessInstance("FlowingTripBookingSaga", new Dictionary<string, object>()
    {
      {"someBookingData", "..." }
    });


: . .





Node.js



  var Workers = require('camunda-worker-node');
  var workers = Workers('http://localhost:8080/engine-rest', {
    workerId: 'some-worker-id'
  });
  
  workers.registerWorker('reserve-car', [ 'someData' ], function(context, callback) {
    var someNewData = context.variables.someData + " - added something";
    callback(null, {
      variables: {
        someNewData: someNewData
      }
    });
  });
  
  workers.shutdown();


github.com



Camunda



Docker «Camunda standalone WAR»



Docker Camunda Tomcat (, Docker Tomcat), Camunda WAR-.



使用Camunda进行便捷的编排



Java, Camunda Standalone war. Maven : Maven war Maven Overlay.



Camunda Tomcat



— Camunda Tomcat, . Java Runtime Environment (JRE), . .



使用Camunda进行便捷的编排



- , Tomcat, . , Tomcat , . Google , .



Camunda Tomcat



— Tomcat Camunda, . Tomcat, , , , Windows.



Camunda



, - Camunda. Camunda , , — : REST API . , .





您可能已经注意到,无论使用哪种语言,Camunda的入门都很容易。关键是所有通信都是通过REST API完成的。安装也非常容易,尤其是在使用Docker时。




All Articles