Skip to content

Commit 099955c

Browse files
committed
Refactor the AsyncAPI call
Closes #1045 Signed-off-by: Charles d'Avernas <charles.davernas@neuroglia.io>
1 parent 52cb747 commit 099955c

6 files changed

+361
-45
lines changed

dsl-reference.md

Lines changed: 185 additions & 16 deletions
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:
323328
call: asyncapi
324329
with:
325330
document:
326331
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 }
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:
344+
call: asyncapi
345+
with:
346+
document:
347+
endpoint: https://fake.com/docs/asyncapi.json
348+
operation: chat-inbox
349+
protocol: http
350+
subscription:
351+
correlation: ${ . == $workflow.input.chat.roomId }
352+
consume:
353+
amount: 5
354+
for:
355+
seconds: 10
333356
```
334357

335358
##### gRPC Call
@@ -1940,4 +1963,150 @@ 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+
| correlation | `string` | `no` | A [runtime expression](dsl.md#runtime-expressions), if any, used to filter consumed messages based on their [correlation id.](https://www.asyncapi.com/docs/reference/specification/v3.0.0#correlationIdObject). |
2050+
| consume | [`subscriptionLifetime`](#asyncapi-subscription-lifetime) | `yes` | An object used to configure the subscription's lifetime. |
2051+
2052+
2053+
#### Examples
2054+
2055+
```yaml
2056+
document:
2057+
dsl: '1.0.0-alpha5'
2058+
namespace: test
2059+
name: asyncapi-example
2060+
version: '0.1.0'
2061+
do:
2062+
- subscribeToChatInbox:
2063+
call: asyncapi
2064+
with:
2065+
document:
2066+
endpoint: https://fake.com/docs/asyncapi.json
2067+
operation: chat-inbox
2068+
protocol: http
2069+
subscription:
2070+
correlation: ${ . == $workflow.input.chat.roomId }
2071+
consume:
2072+
amount: 5
2073+
for:
2074+
seconds: 10
2075+
```
2076+
2077+
### AsyncAPI Subscription Lifetime
2078+
2079+
Configures the lifetime of an AsyncAPI subscription
2080+
2081+
#### Properties
2082+
2083+
| Name | Type | Required | Description |
2084+
|:-------|:------:|:----------:|:--------------|
2085+
| amount | `integer` | `no` | The amount of messages to consume.<br>*Required if `while` and `until` have not been set.* |
2086+
| for | [`duration`](#duration) | `no` | The [`duration`](#duration) that defines for how long to consume messages. |
2087+
| 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.* |
2088+
| 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.* |
2089+
2090+
#### Examples
2091+
2092+
```yaml
2093+
document:
2094+
dsl: '1.0.0-alpha5'
2095+
namespace: test
2096+
name: asyncapi-example
2097+
version: '0.1.0'
2098+
do:
2099+
- subscribeToChatInbox:
2100+
call: asyncapi
2101+
with:
2102+
document:
2103+
endpoint: https://fake.com/docs/asyncapi.json
2104+
operation: chat-inbox
2105+
protocol: http
2106+
subscription:
2107+
correlation: ${ . == $workflow.input.chat.roomId }
2108+
consume:
2109+
until: ($context.messages | length) == 5
2110+
for:
2111+
seconds: 10
19432112
```

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

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,11 @@ do:
99
with:
1010
document:
1111
endpoint: https://fake.com/docs/asyncapi.json
12-
operationRef: findPetsByStatus
12+
operation: findPetsByStatus
1313
server: staging
14-
message: getPetByStatusQuery
15-
binding: http
16-
payload:
17-
petId: ${ .pet.id }
14+
message:
15+
payload:
16+
petId: ${ .pet.id }
1817
authentication:
1918
bearer:
2019
token: ${ .token }
Lines changed: 17 additions & 0 deletions
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+
protoçol: 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
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
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+
channel: /notifications
14+
subscription:
15+
filter: '${ .correlationId == $context.userId and .payload.from.firstName == $context.contact.firstName and .payload.from.lastName == $context.contact.lastName }'
16+
consume:
17+
for:
18+
minutes: 30
19+
until: '${ ($context.consumedMessages | length) == 5 }'
Lines changed: 16 additions & 0 deletions
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)