Skip to content

Commit dab7039

Browse files
authored
Merge pull request serverlessworkflow#1053 from neuroglia-io/feat-asyncapi-refactor
Refactor the `AsyncAPI` call
2 parents 52cb747 + d1bd6ce commit dab7039

6 files changed

+361
-46
lines changed

dsl-reference.md

+184-16
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,10 @@
5656
+ [HTTP Request](#http-request)
5757
+ [URI Template](#uri-template)
5858
+ [Process Result](#process-result)
59+
+ [AsyncAPI Server](#asyncapi-server)
60+
+ [AsyncAPI Message](#asyncapi-message)
61+
+ [AsyncAPI Subscription](#asyncapi-subscription)
62+
5963

6064
## Abstract
6165

@@ -300,15 +304,16 @@ The [AsyncAPI Call](#asyncapi-call) enables workflows to interact with external
300304

301305
###### Properties
302306

303-
| Name | Type | Required | Description|
304-
|:--|:---:|:---:|:---|
305-
| document | [`externalResource`](#external-resource) | `yes` | The AsyncAPI document that defines the operation to call. |
306-
| operationRef | `string` | `yes` | A reference to the AsyncAPI operation to call. |
307-
| server | `string` | `no` | A reference to the server to call the specified AsyncAPI operation on.<br>If not set, default to the first server matching the operation's channel. |
308-
| message | `string` | `no` | The name of the message to use. <br>If not set, defaults to the first message defined by the operation. |
309-
| binding | `string` | `no` | The name of the binding to use. <br>If not set, defaults to the first binding defined by the operation |
310-
| payload | `any` | `no` | The operation's payload, as defined by the configured message |
311-
| authentication | `string`<br>[`authentication`](#authentication) | `no` | The authentication policy, or the name of the authentication policy, to use when calling the AsyncAPI operation. |
307+
| Name | Type | Required | Description |
308+
|:-------|:------:|:----------:|:--------------|
309+
| document | [`externalResource`](#external-resource) | `yes` | The AsyncAPI document that defines the [operation](https://www.asyncapi.com/docs/reference/specification/v3.0.0#operationObject) to call. |
310+
| channel | `string` | `yes` | The name of the channel on which to perform the operation. The operation to perform is defined by declaring either `message`, in which case the [channel](https://v2.asyncapi.com/docs/reference/specification/v2.6.0#channelItemObject)'s `publish` operation will be executed, or `subscription`, in which case the [channel](https://v2.asyncapi.com/docs/reference/specification/v2.6.0#channelItemObject)'s `subscribe` operation will be executed.<br>*Used only in case the referenced document uses AsyncAPI `v2.6.0`.* |
311+
| operation | `string` | `yes` | A reference to the AsyncAPI [operation](https://www.asyncapi.com/docs/reference/specification/v3.0.0#operationObject) to call.<br>*Used only in case the referenced document uses AsyncAPI `v3.0.0`.* |
312+
| server | [`asyncApiServer`](#asyncapi-server) | `no` | An object used to configure to the [server](https://www.asyncapi.com/docs/reference/specification/v3.0.0#serverObject) to call the specified AsyncAPI [operation](https://www.asyncapi.com/docs/reference/specification/v3.0.0#operationObject) on.<br>If not set, default to the first [server](https://www.asyncapi.com/docs/reference/specification/v3.0.0#serverObject) matching the operation's channel. |
313+
| protocol | `string` | `no` | The [protocol](https://www.asyncapi.com/docs/reference/specification/v3.0.0#definitionsProtocol) to use to select the target [server](https://www.asyncapi.com/docs/reference/specification/v3.0.0#serverObject). <br>Ignored if `server` has been set.<br>*Supported values are: `amqp`, `amqp1`, `anypointmq`, `googlepubsub`, `http`, `ibmmq`, `jms`, `kafka`, `mercure`, `mqtt`, `mqtt5`, `nats`, `pulsar`, `redis`, `sns`, `solace`, `sqs`, `stomp` and `ws`* |
314+
| message | [`asyncApiMessage`](#asyncapi-message) | `no` | An object used to configure the message to publish using the target operation.<br>*Required if `subscription` has not been set.* |
315+
| subscription | [`asyncApiSubscription`](#asyncapi-subscription) | `no` | An object used to configure the subscription to messages consumed using the target operation.<br>*Required if `message` has not been set.* |
316+
| authentication | `string`<br>[`authentication`](#authentication) | `no` | The authentication policy, or the name of the authentication policy, to use when calling the AsyncAPI operation. |
312317

313318
###### Examples
314319

@@ -319,17 +324,35 @@ document:
319324
name: asyncapi-example
320325
version: '0.1.0'
321326
do:
322-
- findPet:
327+
- publishGreetings:
328+
call: asyncapi
329+
with:
330+
document:
331+
endpoint: https://fake.com/docs/asyncapi.json
332+
operation: greet
333+
server:
334+
name: greetingsServer
335+
variables:
336+
environment: dev
337+
message:
338+
payload:
339+
greetings: Hello, World!
340+
headers:
341+
foo: bar
342+
bar: baz
343+
- subscribeToChatInbox:
323344
call: asyncapi
324345
with:
325346
document:
326347
endpoint: https://fake.com/docs/asyncapi.json
327-
operationRef: findPetsByStatus
328-
server: staging
329-
message: getPetByStatusQuery
330-
binding: http
331-
payload:
332-
petId: ${ .pet.id }
348+
operation: chat-inbox
349+
protocol: http
350+
subscription:
351+
filter: ${ . == $workflow.input.chat.roomId }
352+
consume:
353+
amount: 5
354+
for:
355+
seconds: 10
333356
```
334357

335358
##### gRPC Call
@@ -1940,4 +1963,149 @@ do:
19401963
version: '0.1.0'
19411964
input: {}
19421965
return: none
1966+
```
1967+
1968+
### AsyncAPI Server
1969+
1970+
Configures the target server of an AsyncAPI operation.
1971+
1972+
#### Properties
1973+
1974+
| Name | Type | Required | Description |
1975+
|:-------|:------:|:----------:|:--------------|
1976+
| name | `string` | `yes` | The name of the [server](https://www.asyncapi.com/docs/reference/specification/v3.0.0#serverObject) to call the specified AsyncAPI operation on. |
1977+
| variables | `object` | `no` | The target [server's variables](https://www.asyncapi.com/docs/reference/specification/v3.0.0#serverVariableObject), if any. |
1978+
1979+
#### Examples
1980+
1981+
```yaml
1982+
document:
1983+
dsl: '1.0.0-alpha5'
1984+
namespace: test
1985+
name: asyncapi-example
1986+
version: '0.1.0'
1987+
do:
1988+
- publishGreetings:
1989+
call: asyncapi
1990+
with:
1991+
document:
1992+
endpoint: https://fake.com/docs/asyncapi.json
1993+
operation: greet
1994+
server:
1995+
name: greetingsServer
1996+
variables:
1997+
environment: dev
1998+
message:
1999+
payload:
2000+
greetings: Hello, World!
2001+
headers:
2002+
foo: bar
2003+
bar: baz
2004+
```
2005+
2006+
### AsyncAPI Message
2007+
2008+
Configures an AsyncAPI message to publish.
2009+
2010+
#### Properties
2011+
2012+
| Name | Type | Required | Description |
2013+
|:-------|:------:|:----------:|:--------------|
2014+
| payload | `object` | `no` | The message's payload, if any. |
2015+
| headers | `object` | `no` | The message's headers, if any. |
2016+
2017+
#### Examples
2018+
2019+
```yaml
2020+
document:
2021+
dsl: '1.0.0-alpha5'
2022+
namespace: test
2023+
name: asyncapi-example
2024+
version: '0.1.0'
2025+
do:
2026+
- publishGreetings:
2027+
call: asyncapi
2028+
with:
2029+
document:
2030+
endpoint: https://fake.com/docs/asyncapi.json
2031+
operation: greet
2032+
protocol: http
2033+
message:
2034+
payload:
2035+
greetings: Hello, World!
2036+
headers:
2037+
foo: bar
2038+
bar: baz
2039+
```
2040+
2041+
### AsyncAPI Subscription
2042+
2043+
Configures a subscription to an AsyncAPI operation.
2044+
2045+
#### Properties
2046+
2047+
| Name | Type | Required | Description |
2048+
|:-------|:------:|:----------:|:--------------|
2049+
| filter | `string` | `no` | A [runtime expression](dsl.md#runtime-expressions), if any, used to filter consumed messages. |
2050+
| consume | [`subscriptionLifetime`](#asyncapi-subscription-lifetime) | `yes` | An object used to configure the subscription's lifetime. |
2051+
2052+
#### Examples
2053+
2054+
```yaml
2055+
document:
2056+
dsl: '1.0.0-alpha5'
2057+
namespace: test
2058+
name: asyncapi-example
2059+
version: '0.1.0'
2060+
do:
2061+
- subscribeToChatInboxForAmount:
2062+
call: asyncapi
2063+
with:
2064+
document:
2065+
endpoint: https://fake.com/docs/asyncapi.json
2066+
operation: chat-inbox
2067+
protocol: http
2068+
subscription:
2069+
filter: ${ . == $workflow.input.chat.roomId }
2070+
consume:
2071+
amount: 5
2072+
for:
2073+
seconds: 10
2074+
```
2075+
2076+
### AsyncAPI Subscription Lifetime
2077+
2078+
Configures the lifetime of an AsyncAPI subscription
2079+
2080+
#### Properties
2081+
2082+
| Name | Type | Required | Description |
2083+
|:-------|:------:|:----------:|:--------------|
2084+
| amount | `integer` | `no` | The amount of messages to consume.<br>*Required if `while` and `until` have not been set.* |
2085+
| for | [`duration`](#duration) | `no` | The [`duration`](#duration) that defines for how long to consume messages. |
2086+
| while | `string` | `no` | A [runtime expression](dsl.md#runtime-expressions), if any, used to determine whether or not to keep consuming messages.<br>*Required if `amount` and `until` have not been set.* |
2087+
| until | `string` | `no` | A [runtime expression](dsl.md#runtime-expressions), if any, used to determine until when to consume messages.<br>*Required if `amount` and `while` have not been set.* |
2088+
2089+
#### Examples
2090+
2091+
```yaml
2092+
document:
2093+
dsl: '1.0.0-alpha5'
2094+
namespace: test
2095+
name: asyncapi-example
2096+
version: '0.1.0'
2097+
do:
2098+
- subscribeToChatInboxUntil:
2099+
call: asyncapi
2100+
with:
2101+
document:
2102+
endpoint: https://fake.com/docs/asyncapi.json
2103+
operation: chat-inbox
2104+
protocol: http
2105+
subscription:
2106+
filter: ${ . == $workflow.input.chat.roomId }
2107+
consume:
2108+
until: '${ ($context.messages | length) == 5 }'
2109+
for:
2110+
seconds: 10
19432111
```

examples/call-asyncapi.yaml renamed to examples/call-asyncapi-publish.yaml

+6-6
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,12 @@ do:
99
with:
1010
document:
1111
endpoint: https://fake.com/docs/asyncapi.json
12-
operationRef: findPetsByStatus
13-
server: staging
14-
message: getPetByStatusQuery
15-
binding: http
16-
payload:
17-
petId: ${ .pet.id }
12+
operation: findPetsByStatus
13+
server:
14+
name: staging
15+
message:
16+
payload:
17+
petId: ${ .pet.id }
1818
authentication:
1919
bearer:
2020
token: ${ .token }
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
document:
2+
dsl: '1.0.0-alpha5'
3+
namespace: examples
4+
name: bearer-auth
5+
version: '0.1.0'
6+
do:
7+
- getNotifications:
8+
call: asyncapi
9+
with:
10+
document:
11+
endpoint: https://fake.com/docs/asyncapi.json
12+
operation: getNotifications
13+
protocol: ws
14+
subscription:
15+
filter: '${ .correlationId == $context.userId and .payload.from.firstName == $context.contact.firstName and .payload.from.lastName == $context.contact.lastName }'
16+
consume:
17+
amount: 5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
document:
2+
dsl: '1.0.0-alpha5'
3+
namespace: examples
4+
name: bearer-auth
5+
version: '0.1.0'
6+
do:
7+
- getNotifications:
8+
call: asyncapi
9+
with:
10+
document:
11+
endpoint: https://fake.com/docs/asyncapi.json
12+
channel: /notifications
13+
subscription:
14+
filter: '${ .correlationId == $context.userId and .payload.from.firstName == $context.contact.firstName and .payload.from.lastName == $context.contact.lastName }'
15+
consume:
16+
for:
17+
minutes: 30
18+
until: '${ ($context.consumedMessages | length) == 5 }'
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
document:
2+
dsl: '1.0.0-alpha5'
3+
namespace: examples
4+
name: bearer-auth
5+
version: '0.1.0'
6+
do:
7+
- getNotifications:
8+
call: asyncapi
9+
with:
10+
document:
11+
endpoint: https://fake.com/docs/asyncapi.json
12+
operation: getNotifications
13+
subscription:
14+
filter: '${ .correlationId == $context.userId and .payload.from.firstName == $context.contact.firstName and .payload.from.lastName == $context.contact.lastName }'
15+
consume:
16+
while: '${ ($context.consumedMessages | length) < 5 }'

0 commit comments

Comments
 (0)