Basic Examples

Simple workflow examples to help new users understand the basic functionality of xFlow, focusing on simple approval and data processing tasks.

Customer Banking Transactions

{
  "id": "bankingtransactions",
  "name": "Customer Banking Transactions Workflow",
  "version": "1.0",
  "specVersion": "0.8",
  "timeouts": {
    "workflowExecTimeout": {
      "duration": "PT1M"
    },
    "actionExecTimeout": "PT10S"
  },
  "autoRetries": true,
  "start": "ProcessTransactions",
  "states": [
    {
      "name": "ProcessTransactions",
      "type": "foreach",
      "inputCollection": "${ .customer.transactions }",
      "iterationParam": "${ .tx }",
      "mode": "parallel",
      "actions": [
        {
          "name": "Processing Action",
          "functionRef": "InvokeBankingService"
        }
      ],
      "end": true
    }
  ],
  "functions": [
    {
      "name": "InvokeBankingService",
      "type": "rest"
    },
    {
      "name": "QueryCustomerName",
      "type": "expression",
      "operation": "${ .customer.name }"
    },
    {
      "name": "QueryCustomerAge",
      "type": "expression",
      "operation": "${ .customer.age }"
    }
  ]
}

```

Customer Application

{
  "id": "customerapplication",
  "name": "Customer Application Workflow",
  "version": "1.0",
  "timeouts": {
    "workflowExecTimeout": {
      "duration": "PT1M"
    },
    "actionExecTimeout": "PT10S"
  },
  "retries": [
    {
      "name": "WorkflowRetries",
      "delay": "PT3S",
      "maxAttempts": 10
    }
  ],
  "states": [
    {
      "name": "NewCustomerApplication",
      "type": "event",
      "onEvents": [
        {
          "eventRefs": ["NewApplicationEvent"],
          "actionMode": "parallel",
          "actions": [
            {
              "name": "Invoke Check Customer Info Function",
              "functionRef": "CheckCustomerInfo"
            },
            {
              "name": "Invoke Update Application Info Function",
              "functionRef": "UpdateApplicationInfo"
            }
          ]
        }
      ],
      "transition": "MakeApplicationDecision"
    },
    {
      "name": "MakeApplicationDecision",
      "type": "switch",
      "dataConditions": [
        {
          "condition": "${ .customer.age >= 20 }",
          "transition": "ApproveApplication"
        },
        {
          "condition": "${ .customer.age < 20 }",
          "transition": "RejectApplication"
        }
      ],
      "defaultCondition": {
        "transition": "RejectApplication"
      }
    },
    {
      "name": "ApproveApplication",
      "type": "operation",
      "actions": [
        {
          "name": "Invoke Approve Application Function",
          "functionRef": "ApproveApplication",
          "sleep": {
            "before": "PT1S"
          }
        }
      ],
      "end": true
    },
    {
      "name": "RejectApplication",
      "type": "operation",
      "actions": [
        {
          "name": "Invoke Reject Application Function",
          "functionRef": "RejectApplication",
          "sleep": {
            "before": "PT1S"
          }
        }
      ],
      "end": true
    }
  ],
  "functions": [
    {
      "name": "CheckCustomerInfo",
      "type": "rest"
    },
    {
      "name": "UpdateApplicationInfo",
      "type": "rest"
    },
    {
      "name": "ApproveApplication",
      "type": "rest"
    },
    {
      "name": "RejectApplication",
      "type": "rest"
    },
    {
      "name": "QueryCustomerName",
      "type": "expression",
      "operation": "${ .customer.name }"
    },
    {
      "name": "QueryCustomerAge",
      "type": "expression",
      "operation": "${ .customer.age }"
    }
  ],
  "events": [
    {
      "name": "NewApplicationEvent",
      "type": "com.fasterxml.jackson.databind.JsonNode",
      "source": "applicationsSource"
    }
  ]
}

```

Applicant Processing

{
  "id": "applicantworkflow",
  "name": "Applicant Processing Workflow",
  "version": "1.0",
  "specVersion": "0.8",
  "timeouts": {
    "workflowExecTimeout": {
      "duration": "PT2M"
    },
    "actionExecTimeout": "PT10S"
  },
  "autoRetries": true,
  "states": [
    {
      "name": "ApproveApplicant",
      "type": "operation",
      "actions": [
        {
          "name": "approvalAction",
          "functionRef": {
            "refName": "approvalFunction",
            "arguments": {
              "customer": "${ .customer }"
            }
          }
        }
      ],
      "transition": "WaitForDecision"
    },
    {
      "name": "WaitForDecision",
      "type": "event",
      "onEvents": [
        {
          "eventRefs": ["CustomerDecision"]
        }
      ],
      "end": true
    }
  ],
  "functions": [
    {
      "name": "approvalFunction",
      "type": "custom",
      "operation": "approvalworkflow#ToApproveCustomer"
    }
  ],
  "events": [
    {
      "name": "CustomerDecision",
      "type": "com.fasterxml.jackson.databind.JsonNode",
      "source": "applicationsSource"
    }
  ]
}

```

Last updated