For Flogo a Flow is more inline with the concept of a function, that is, a Flow has both input and output parameters. The concept of decoupling a trigger from a flow is a key part of supporting multiple triggers and re-use/sharing of a flow. A Flow can now operate against the data that it has defined within its declartion, in otherwords, just like a function, the scope of data that a Flow can operate against must reside within either the Flow context (or as an environment variable).
When building a Flow, you must first define the input and output params, that is, what are the input parameters that a flow can operate against and what parameters will be returned once the Flow has finished executing. To do this, we have options, either use the WebUI or construct the JSON manually.
From the WebUI, open your new Flow, and click the “Flow Params” box, you’ll be presented with the Flow input/output editor.
You will be presented with a dialog containing two tabs, Input and Output. Use this dialog to define your input and output parameters.
If you’d prefer to define the Flows input and output params via the application JSON, you may do so
{
"id": "flow:my_function",
"data": {
"name": "MyFunction",
"metadata": {
"input": [
{
"name": "name",
"type": "string"
}
],
"output": [
{
"name": "greeting",
"type": "any"
}
]
}
}
}
Because a Flow operates against its own locally scoped data (params), you will need to map the trigger data into the Flow params, as well as the flow params to the triggers reply params(s). This may sound a bit odd at first, however is required to ensure that a trigger is entierly decoupled from a flow, as previously said, enabling flows to be re-used and support multiple paths of invocation via different triggers.
Before we jump in, to understand the concepts used here:
To map the trigger data using the WebUI, add a trigger to your Flow, and click on it.
Now select “Map flow params”.
Now you can map the output of the trigger to Flow input params, and Flow output params can be mapped to the reply params available for the trigger.
If you choose to map directly within the JSON, consider the following triggers definition
"triggers": [
{
"id": "aws_lambda_trigger",
"ref": "#lambda",
"name": "AWS Lambda Trigger",
"description": "AWS Lambda Trigger",
"handlers": [
{
"action": {
"ref": "#flow",
"settings": {
"flowURI": "res://flow:my_function"
},
"input": {
"name": "=$.event.name"
},
"output": {
"data": "=$.greeting",
"status": 200
}
}
}
]
}
]
Note the input
and output
objects within the handler definition.