|
24 | 24 | + [Data Merging](#data-merging)
|
25 | 25 | * [Workflow Functions](#workflow-functions)
|
26 | 26 | + [Using Functions for RESTful Service Invocations](#using-functions-for-restful-service-invocations)
|
| 27 | + + [Using Functions for Async API Invocations](#using-functions-for-async-api-invocations) |
27 | 28 | + [Using Functions for RPC Service Invocations](#using-functions-for-rpc-service-invocations)
|
28 | 29 | + [Using Functions for GraphQL Service Invocations](#using-functions-for-graphql-service-invocations)
|
29 | 30 | - [Invoking a GraphQL `Query`](#invoking-a-graphql-query)
|
@@ -1089,6 +1090,95 @@ Note that the referenced function definition type in this case must be `rest` (d
|
1089 | 1090 |
|
1090 | 1091 | For more information about functions, reference the [Functions definitions](#Function-Definition) section.
|
1091 | 1092 |
|
| 1093 | +#### Using Functions for Async API Service Invocations |
| 1094 | + |
| 1095 | +[Functions](#Function-Definition) can be used to invoke PUBLISH and SUBSCRIBE operations on a message broker documented by the [Async API Specification](https://www.asyncapi.com/docs/specifications/v2.1.0). |
| 1096 | +[Async API operations](https://www.asyncapi.com/docs/specifications/v2.1.0#operationObject) are bound to a [channel](https://www.asyncapi.com/docs/specifications/v2.1.0#definitionsChannel) which describes the technology, security mechanisms, input and validation to be used for their execution. |
| 1097 | + |
| 1098 | +Let's take a look at a hypothetical Async API document (assumed its stored locally with the file name `streetlightsapi.yaml`) and define a single publish operation: |
| 1099 | + |
| 1100 | +```yaml |
| 1101 | +asyncapi: 2.1.0 |
| 1102 | +info: |
| 1103 | + title: Streetlights API |
| 1104 | + version: 1.0.0 |
| 1105 | + description: | |
| 1106 | + The Smartylighting Streetlights API allows you |
| 1107 | + to remotely manage the city lights. |
| 1108 | + license: |
| 1109 | + name: Apache 2.0 |
| 1110 | + url: https://www.apache.org/licenses/LICENSE-2.0 |
| 1111 | +servers: |
| 1112 | + mosquitto: |
| 1113 | + url: mqtt://test.mosquitto.org |
| 1114 | + protocol: mqtt |
| 1115 | +channels: |
| 1116 | + light/measured: |
| 1117 | + publish: |
| 1118 | + summary: Inform about environmental lighting conditions for a particular streetlight. |
| 1119 | + operationId: onLightMeasured |
| 1120 | + message: |
| 1121 | + name: LightMeasured |
| 1122 | + payload: |
| 1123 | + type: object |
| 1124 | + properties: |
| 1125 | + id: |
| 1126 | + type: integer |
| 1127 | + minimum: 0 |
| 1128 | + description: Id of the streetlight. |
| 1129 | + lumens: |
| 1130 | + type: integer |
| 1131 | + minimum: 0 |
| 1132 | + description: Light intensity measured in lumens. |
| 1133 | + sentAt: |
| 1134 | + type: string |
| 1135 | + format: date-time |
| 1136 | + description: Date and time when the message was sent. |
| 1137 | +``` |
| 1138 | + |
| 1139 | +To define a workflow action invocation, we can then use the following workflow [Function Definition](#Function-Definition) and set the `operation` to `onLightMeasured`: |
| 1140 | + |
| 1141 | +```json |
| 1142 | +{ |
| 1143 | + "functions": [ |
| 1144 | + { |
| 1145 | + "name": "publishLightMeasurements", |
| 1146 | + "operation": "file://streetlightsapi.yaml#onLightMeasured", |
| 1147 | + "type": "asyncapi" |
| 1148 | + }] |
| 1149 | +} |
| 1150 | +``` |
| 1151 | + |
| 1152 | +Note that the [Function Definition](#Function-Definition)'s `operation` property must have the following format: |
| 1153 | + |
| 1154 | +```text |
| 1155 | +<URI_to_asyncapi_file>#<OperationId> |
| 1156 | +``` |
| 1157 | + |
| 1158 | +Also note that the referenced function definition type in this case must have the value `asyncapi`. |
| 1159 | + |
| 1160 | +Our defined function definition can then we referenced in a workflow [action](#Action-Definition), for example: |
| 1161 | + |
| 1162 | +```json |
| 1163 | +{ |
| 1164 | + "name": "Publish Measurements", |
| 1165 | + "type": "operation", |
| 1166 | + "actions":[ |
| 1167 | + { |
| 1168 | + "name": "Publish Light Measurements", |
| 1169 | + "functionRef":{ |
| 1170 | + "refName": "publishLightMeasurements", |
| 1171 | + "arguments":{ |
| 1172 | + "id": "${ .currentLight.id }", |
| 1173 | + "lumens": "${ .currentLight.lumens }", |
| 1174 | + "sentAt": "${ now }" |
| 1175 | + } |
| 1176 | + } |
| 1177 | + } |
| 1178 | + ] |
| 1179 | +} |
| 1180 | +``` |
| 1181 | + |
1092 | 1182 | #### Using Functions for RPC Service Invocations
|
1093 | 1183 |
|
1094 | 1184 | Similar to defining invocations of operations on RESTful services, you can also use the workflow
|
@@ -1350,7 +1440,7 @@ should follow the Serverless Workflow [OData Json schema](https://github.com/ser
|
1350 | 1440 |
|
1351 | 1441 | #### Using Functions for Expression Evaluation
|
1352 | 1442 |
|
1353 |
| -In addition to defining RESTful, RPC, GraphQL and OData services and their operations, workflow [functions definitions](#Function-Definition) |
| 1443 | +In addition to defining RESTful, AsyncAPI, RPC, GraphQL and OData services and their operations, workflow [functions definitions](#Function-Definition) |
1354 | 1444 | can also be used to define expressions that should be evaluated during workflow execution.
|
1355 | 1445 |
|
1356 | 1446 | Defining expressions as part of function definitions has the benefit of being able to reference
|
@@ -3023,7 +3113,7 @@ section.
|
3023 | 3113 | | Parameter | Description | Type | Required |
|
3024 | 3114 | | --- | --- | --- | --- |
|
3025 | 3115 | | name | Unique function name | string | yes |
|
3026 |
| -| operation | If type is `rest`, <path_to_openapi_definition>#<operation_id>. If type is `rpc`, <path_to_grpc_proto_file>#<service_name>#<service_method>. If type is `graphql`, <url_to_graphql_endpoint>#<literal \"mutation\" or \"query\">#<query_or_mutation_name>. If type is `odata`, <URI_to_odata_service>#<Entity_Set_Name>. If type is `expression`, defines the workflow expression. | string | no | |
| 3116 | +| operation | If type is `rest`, <path_to_openapi_definition>#<operation_id>. If type is `asyncapi`, <path_to_asyncapi_definition>#<operation_id>. If type is `rpc`, <path_to_grpc_proto_file>#<service_name>#<service_method>. If type is `graphql`, <url_to_graphql_endpoint>#<literal \"mutation\" or \"query\">#<query_or_mutation_name>. If type is `odata`, <URI_to_odata_service>#<Entity_Set_Name>. If type is `expression`, defines the workflow expression. | string | no | |
3027 | 3117 | | type | Defines the function type. Is either `rest`, `rpc`, `odata` or `expression`. Default is `rest` | enum | no |
|
3028 | 3118 | | authRef | References an [auth definition](#Auth-Definition) name to be used to access to resource defined in the operation parameter | string | no |
|
3029 | 3119 | | [metadata](#Workflow-Metadata) | Metadata information. Can be used to define custom function information | object | no |
|
@@ -3068,6 +3158,8 @@ Depending on the function `type`, the `operation` property can be:
|
3068 | 3158 |
|
3069 | 3159 | * If `type` is `rest`, a combination of the function/service OpenAPI definition document URI and the particular service operation that needs to be invoked, separated by a '#'.
|
3070 | 3160 | For example `https://petstore.swagger.io/v2/swagger.json#getPetById`.
|
| 3161 | +* If `type` is `asyncapi`, a combination of the AsyncApi definition document URI and the particular service operation that needs to be invoked, separated by a '#'. |
| 3162 | + For example `file://streetlightsapi.yaml#onLightMeasured`. |
3071 | 3163 | * If `type` is `rpc`, a combination of the gRPC proto document URI and the particular service name and service method name that needs to be invoked, separated by a '#'.
|
3072 | 3164 | For example `file://myuserservice.proto#UserService#ListUsers`.
|
3073 | 3165 | * If `type` is `graphql`, a combination of the GraphQL schema definition URI and the particular service name and service method name that needs to be invoked, separated by a '#'.
|
|
0 commit comments