本文主要介绍Conductor的实战案例,Conductor server启动问题请参考https://blog.csdn.net/wh09091/article/details/84549371
1.通过命令行将Netflix Conductor Sever端启动之后访问localhost:8080
2.启动Conductor ui(启动后访问http://localhost:3000)
3.创建流程实例
3.1Create the workflow definition
定义工作流,向/metadata/workflow发送请求
{
"name": "Test process",
"description": "a simple demo for workflow",
"version": 1,
"tasks": [
{
"name": "string",
"taskReferenceName": "node1",
"inputParameters": {
"content": "${workflow.input.content}",
"zhushi": "${workflow.input.zhushi}"
},
"type": "SIMPLE",
"startDelay": 0
}
],
"outputParameters": {
"str": "${node1.output.content}",
"msg": "${node1.output.zhushi}"
},
"restartable": true,
"schemaVersion": 1
}
这时访问Conductor ui页面点击Workflow Defs能看到刚定义的workflow
3.2创建task definition
在3.1中创建好workflow definition后直接启动该流程会报错
{
"code": "INVALID_INPUT",
"message": "Cannot find the task definitions for the following tasks used in workflow: [string]",
"retryable": false,
"instance": "LAPTOP-9TKRBDMO"
}
Conductor定义workflow时需要定义其中的每一个task,这里没有定义name为string的task所以报错。so 接下来定义task
向/metadata/taskdefs发送post请求
以下是请求的body信息:
[
{
"name": "string",
"retryCount": 3,
"timeoutSeconds": 1200,
"inputKeys": [
"content",
"zhushi"
],
"outputKeys": [
"str",
"msg"
],
"timeoutPolicy": "TIME_OUT_WF",
"retryLogic": "FIXED",
"retryDelaySeconds": 600,
"responseTimeoutSeconds": 3600
}
]
可以同时定义多个task,用逗号“,“间隔开就行。
3.3启动流程
向/workflow/{name}发送post请求启动流程
流程启动成功,这时可以从Conductor ui页面上看到该流程。
点击workflow ID查看流程详情,task的状态为SCHEDULE,点击任务可以查看任务详情,如下图:
3.4轮询任务(相当于activiti中的签收任务)
向GET /tasks/poll/{tasktype}发送请求,参数tasktype为task的name,本例中tasktype为string
请求发送成功后Conductor ui查看流程状态,此时task的状态变为IN_PROGRESS
3.5完成任务--修改任务状态
向/tasks发送post请求,body信息包含taskId、workflowInstanceId、outputData、status等,这些数据都可以在Conductor ui中流程详情中查看。如下为本例中的body参数:
{
"taskId":"62e3e08a-62fb-4ff5-90bf-26d4f980432e",
"workflowInstanceId": "328f11f4-3504-4a32-96c1-86eb9afbef7e",
"outputData": {
"str":"1111",
"msg":"true"
},
"status": "COMPLETED"
}
至此workflow执行完成,Conductor ui页面可以在Completed中查看到已完成的workflow。