Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: adapt anypointmq bindings to v3 #203

Merged
merged 10 commits into from
Nov 22, 2023
115 changes: 67 additions & 48 deletions anypointmq/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ This document defines how to describe Anypoint MQ-specific information in AsyncA
<a name="version"></a>
## Versions

The version of this bindings specification is `0.0.1`.
The version of this bindings specification is `0.1.0`.
This is also the `bindingVersion` for all binding objects defined by this specification.
In any given binding object, `latest` MAY alternatively be used to refer to the currently latest published version of this bindings specification.

Expand All @@ -28,7 +28,8 @@ The fields of the standard [Server Object](https://github.com/asyncapi/spec/blob
Server Object Field Name | Values for Anypoint MQ Protocol | Description
---|:---|:---
<a name="serverObjectProtocolFieldValueAnypointMQ"></a>`protocol` | `anypointmq` | **REQUIRED**. MUST be `anypointmq` for the scope of this specification.
<a name="serverObjectUrlFieldValueAnypointMQ"></a>`url` | e.g., `https://mq-us-east-1.anypoint.mulesoft.com/api` | **REQUIRED**. MUST be the endpoint URL of the Anypoint MQ Broker REST API _excluding_ the final major version indicator (e.g., `v1`). Valid examples are `https://mq-us-east-1.anypoint.mulesoft.com/api` and `https://mq-eu-central-1.eu1.anypoint.mulesoft.com/api` (and _not_ `https://.../api/v1`).
<a name="serverObjectUrlFieldValueAnypointMQ"></a>`host` | e.g., `https://mq-us-east-1.anypoint.mulesoft.com` | **REQUIRED**. MUST be the endpoint HOST part of the URL of the Anypoint MQ Broker REST API. Valid examples are `https://mq-us-east-1.anypoint.mulesoft.com` and `https://mq-eu-central-1.eu1.anypoint.mulesoft.com` (and _not_ `https://mq-us-east-1.anypoint.mulesoft.com/api`, or `https://.../api/v1`).
<a name="serverObjectUrlFieldValueAnypointMQ"></a>`pathname` | e.g., `/api` | **REQUIRED**. MUST be the endpoint path part of the URL of the Anypoint MQ Broker REST API _excluding_ the final major version indicator (e.g., `v1`). Valid examples are `/api` and (and _not_ `https://.../api/v1`).
<a name="serverObjectProtocolVersionFieldValueAnypointMQ"></a>`protocolVersion` | e.g., `v1` | **OPTIONAL**, defaults to `v1`. If present MUST be the major version indicator of the Anypoint MQ Broker REST API omitted from the `url`, e.g. `v1`.
<a name="serverObjectSecurityFieldValueAnypointMQ"></a>`security` | suitably configured OAuth 2.0 client credentials grant type | **REQUIRED**. Authentication against the MuleSoft-hosted Anypoint MQ message brokers uses the OAuth 2.0 client credentials grant type. At runtime, the client ID and client secret values of an Anypoint MQ client app must be supplied. Also, the OAuth 2.0 scopes are currently not client-configurable. The `security` field of the server object MUST correctly match these constraints.

Expand All @@ -54,27 +55,30 @@ Note that an Anypoint MQ exchange can only be sent to, not received from. To rec

### Examples

The following example shows a `channels` object with two channels, the second having a channel binding object for `anypointmq`:
The following example shows two channels where does not apply any bindings and the second one applying `anyointmq` bindings.

```yaml
channels:
user/signup:
userSignup:
address: 'user/signup'
description: |
This application receives command messages from this channel about users to sign up.
Minimal configuration, omitting a channel binding object.
publish:
messages:
#...
user/signedup:

userSignup:
address: 'user/signup'
description: |
This application sends events to this channel about users that have signed up.
Explicitly provides a channel binding object.
messages:
#...
bindings:
anypointmq:
destination: user-signup-exchg
destinationType: exchange
bindingVersion: '0.0.1'
subscribe:
#...
bindingVersion: '0.1.0'
```

<a name="operation"></a>
Expand All @@ -85,7 +89,7 @@ This object MUST NOT contain any properties. Its name is reserved for future use
<a name="message"></a>
## Message Binding Object

The Anypoint MQ [Message Binding Object](https://github.com/asyncapi/spec/blob/master/spec/asyncapi.md#message-bindings-object) is defined by a [JSON Schema](json_schemas/message.json), which defines these fields:
The Anypoint MQ [Message Binding Object](https://github.com/asyncapi/spec/blob/master/spec/asyncapi.md#message-bindings-object) defines these fields:

Field Name | Type | Description
---|:---:|---
Expand All @@ -101,13 +105,14 @@ The following example shows a `channels` object with two channels, each having o

```yaml
channels:
user/signup:
publish:
message:
#...
user/signedup:
subscribe:
message:
userSignup:
address: 'user/signup'
messages:
#...
userSignup:
address: 'user/signup'
messages:
userSignupMessage:
headers:
type: object
properties:
Expand All @@ -128,56 +133,51 @@ channels:
properties:
messageId:
type: string
bindingVersion: '0.0.1'
bindingVersion: '0.1.0'
```

## Complete Example

The following is a complete, simple AsyncAPI document illustrating the usage of all binding objects defined in this bindings specification, with all their fields.

```yaml
asyncapi: '2.0.0'
asyncapi: 3.0.0
info:
title: Example with Anypoint MQ
version: '0.0.1'

version: 0.0.1
servers:
development:
host: mq-us-east-1.anypoint.mulesoft.com
pathname: /api
protocol: anypointmq
protocolVersion: v1
url: https://mq-us-east-1.anypoint.mulesoft.com/api
description: |
Anypoint MQ broker for development, in the US East (N. Virginia) runtime plane
description: >
Anypoint MQ broker for development, in the US East (N. Virginia) runtime
plane

under management of the US control plane.
security:
- oauthDev: []
- $ref: '#/components/securitySchemes/oauthDev'
production:
host: mq-eu-central-1.eu1.anypoint.mulesoft.com
pathname: /api
protocol: anypointmq
protocolVersion: v1
url: https://mq-eu-central-1.eu1.anypoint.mulesoft.com/api
description: |
Anypoint MQ broker for production, in the EU Central (Frankfurt) runtime plane
description: >
Anypoint MQ broker for production, in the EU Central (Frankfurt) runtime
plane

under management of the EU control plane.
security:
- oauthProd: []
- $ref: '#/components/securitySchemes/oauthProd'
bindings:
anypointmq:
bindingVersion: '0.0.1'

bindingVersion: 0.1.0
channels:
user/signup:
description: |
This application receives command messages from this channel about users to sign up.
bindings:
anypointmq:
destination: user-signup-queue
destinationType: fifo-queue
bindingVersion: '0.0.1'
publish:
operationId: signUpUser
description: |
This application receives command messages via this operation about users to sign up.
message:
address: user/signup
messages:
signUpUser.message:
contentType: application/json
headers:
type: object
Expand All @@ -192,7 +192,9 @@ channels:
type: string
minLength: 3
correlationId:
description: Correlation ID is specified as a header and transmitted in the Anypoint MQ message properties section
description: >-
Correlation ID is specified as a header and transmitted in the
Anypoint MQ message properties section
location: $message.header#/correlationId
bindings:
anypointmq:
Expand All @@ -201,20 +203,37 @@ channels:
properties:
messageId:
type: string
bindingVersion: '0.0.1'

bindingVersion: 0.1.0
description: >
This application receives command messages from this channel about users
to sign up.
bindings:
anypointmq:
destination: user-signup-queue
destinationType: fifo-queue
bindingVersion: 0.1.0
operations:
signUpUser:
action: receive
channel:
$ref: '#/channels/user~1signup'
description: >
This application receives command messages via this operation about users
to sign up.
messages:
- $ref: '#/channels/user~1signup/messages/signUpUser.message'
components:
securitySchemes:
oauthDev:
type: oauth2
flows:
clientCredentials:
tokenUrl: https://mq-us-east-1.anypoint.mulesoft.com/api/v1/authorize
tokenUrl: 'https://mq-us-east-1.anypoint.mulesoft.com/api/v1/authorize'
scopes: {}
oauthProd:
type: oauth2
flows:
clientCredentials:
tokenUrl: https://mq-eu-central-1.eu1.anypoint.mulesoft.com/api/v1/authorize
tokenUrl: 'https://mq-eu-central-1.eu1.anypoint.mulesoft.com/api/v1/authorize'
scopes: {}
```