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

docs: introduce AsyncAPI document #1868

Merged
merged 18 commits into from
Dec 12, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions pages/docs/concepts/asyncapi-document/_section.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
---
title: 'AsyncAPI Document'
weight: 50
---
61 changes: 61 additions & 0 deletions pages/docs/concepts/asyncapi-document/index.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
---
title: 'Introduction'
weight: 1
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

with subsections it works this way that the "starting weight" is the weight of the _section.md so change it to 50 or more and all the next documents should follow. This way you fix preview and make sure it shows in the UI

quetzalliwrites marked this conversation as resolved.
Show resolved Hide resolved
---

quetzalliwrites marked this conversation as resolved.
Show resolved Hide resolved
The AsyncAPI document is a YAML or JSON file that describes your implementation of the AsyncAPI specification. Providing a standardized way to document and describe asynchronous and event-driven systems, the AsyncAPI document generates documentation/code and defines the different components of your event-driven application, such as the events, channels, and message formats.
quetzalliwrites marked this conversation as resolved.
Show resolved Hide resolved
quetzalliwrites marked this conversation as resolved.
Show resolved Hide resolved
quetzalliwrites marked this conversation as resolved.
Show resolved Hide resolved

Primarily, it provides a method to produce comprehensive, consistent, and standardized AsyncAPI documentation. Additionally, it serves as a contract for communication between consumers and producers in an event-driven system. It specifies what should be included in the payload when a service produces a message and provides information to the consumer about the properties in the message.
quetzalliwrites marked this conversation as resolved.
Show resolved Hide resolved
quetzalliwrites marked this conversation as resolved.
Show resolved Hide resolved
quetzalliwrites marked this conversation as resolved.
Show resolved Hide resolved

```YAML
asyncapi: 3.0.0
info:
title: Cool Example
version: 0.1.0
channels:
user/signedup:
subscribe:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is actually an invalid document. Version 3 changed how channels, operations, and messages are described and linked.
It also changed the terms Publish/Subscribe to Receive/Send in that order, since documents changed from being Client-Centric to Application-Centric (meaning they describe the applications API and not the client's interaction within those APIs).

Ok, probably too much info there to digest 😓 .

Let's start with some of the changes in v3 that affect this example:

  • Publish/Subscribe thing. Here is a simple cheat sheet I made for the talk I presented at the EDA Summit 23 that helps to convert from v2 to v3.
  • Channels now have a new field called address that holds the address of the channel. Now the name of the channel can be whatever name. I recommend userSignedUp here.
  • Channels don't include the Operation anymore. Instead, Operations are defined in the root document and are "linked" to the channel.

Applying all the previous, your document will look like this:

asyncapi: 3.0.0
info:
  title: Cool Example
  version: 0.1.0
channels:
  userSignedUp:
    address: user/signedup
    messages:
      userSignedUp:
        description: An event describing that a user just signed up.
        payload:
          type: object
          additionalProperties: false
          properties:
            fullName:
              type: string
            email:
              type: string
              format: email
            age:
              type: integer
              minimum: 18
operations: 
  userSignedUp:
    action: send
    channel: 
      $ref: '#/channels/userSignedUp'

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Whoa, this was a lot of info but I really appreciate how fully you described everything. Thank you 🙏 !!!

One thing slightly confuses me... When you wrote changed the terms Publish/Subscribe to Receive/Send in that order, that made complete sense to me. With you so far. But then when I looked at your cheatsheet, my mind feels like it's trying to do gymnastics. Are you saying that in v3:

  • applications no longer subscribe, they send
  • applications no longer publish, they receive
    ?
    I have copied your updated code snippet and will integrate in my next commit. ✌🏽

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The reality is that the approach or point of view of the documented API changes. In v3, we now clearly state that:

The AsyncAPI Specification defines a set of files required to describe the API of an application.

Meaning the document describes the API of the application that offers the AsyncAPI document.
That means operations with the action send, means that the application will perform that operation by sending the messages. On the contrary, receive means the application expects to receive those messages.

message:
description: An event describing that a user just signed up.
payload:
type: object
additionalProperties: false
quetzalliwrites marked this conversation as resolved.
Show resolved Hide resolved
properties:
fullName:
type: string
email:
type: string
format: email
age:
type: integer
minimum: 18
```

## AsyncAPI document components
quetzalliwrites marked this conversation as resolved.
Show resolved Hide resolved

The AsyncAPI document follows a specific structure with certain headers or fields:
quetzalliwrites marked this conversation as resolved.
Show resolved Hide resolved

- **`asyncapi`**: This is a required field that specifies the AsyncAPI specification version that your document adheres to.

- **`info`**: This required field holds metadata about the API. The `info` section must include the following sub-fields:

- `title`: A descriptive title of the API.

- `version`: An API version identifier.

Optional fields within the `info` section could include `description`, `termsOfService`, `contact` (with subfields for `name`, `url`, `email`), and `license` (with `name` and `url` subfields).

- **`servers`**: An optional field specifying the server(s) where the API is available. Each server must have a `url` and may have `protocol`, `protocolVersion`, `description`, `variables`, `security`, and `bindings`.

- **`channels`**: This required field describes the paths available to the API and must include at least one channel. Each channel could include fields such as `description`, `subscribe`, `publish`, `parameters`, and `bindings`.

- **`components`**: An optional section for defining reusable components like `messages`, `schemas`, `securitySchemes`, and others.

- **`tags`**: An optional array of tags used by the specification with additional metadata. Each tag object can have `name` and `description`.

- **`externalDocs`**: An optional section to provide more information, such as a link to the API’s external documentation with a `description` and a `url`.
quetzalliwrites marked this conversation as resolved.
Show resolved Hide resolved


<Remember>
You might have additional fields depending on the implemented protocol (i.e., MQTT, AMQP, Kafka, etc.).
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would clarify this with an example

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you, noted. Added an example, you let me know if you like it.

quetzalliwrites marked this conversation as resolved.
Show resolved Hide resolved
</Remember>