Let's define an application that's capable of receiving a "hello {name}" message.
1asyncapi: 2.5.0
2info:
3 title: Hello world application
4 version: '0.1.0'
5channels:
6 hello:
7 publish:
8 message:
9 payload:
10 type: string
11 pattern: '^hello .+$'
Let's get into the details of this sample specification:
1asyncapi: 2.5.0
2info:
3 title: Hello world application
4 version: '0.1.0'
5channels:
6 hello:
7 publish:
8 message:
9 payload:
10 type: string
11 pattern: '^hello .+$'
The first line of the specification starts with the document type asyncapi
and the version (2.5.0). This line doesn't have to be the first one, but it's a recommended practice.
1asyncapi: 2.5.0
2info:
3 title: Hello world application
4 version: '0.1.0'
5channels:
6 hello:
7 publish:
8 message:
9 payload:
10 type: string
11 pattern: '^hello .+$'
The info
object contains the minimum required information about the application. It contains the title
, which is a memorable name for the API, and the version
. While it's not mandatory, it's strongly recommended to change the version whenever you make changes to the API.
1asyncapi: 2.5.0
2info:
3 title: Hello world application
4 version: '0.1.0'
5channels:
6 hello:
7 publish:
8 message:
9 payload:
10 type: string
11 pattern: '^hello .+$'
The channels
section of the specification houses all of the mediums where messages flow through. For example, some systems use topic
, event name
or routing key
. Different kinds of information flow through each channel similar to the analogy of TV channels.
In this example, you only have one channel called hello
. The sample application subscribes to this channel to receive hello {name}
messages.
1asyncapi: 2.5.0
2info:
3 title: Hello world application
4 version: '0.1.0'
5channels:
6 hello:
7 publish:
8 message:
9 payload:
10 type: string
11 pattern: '^hello .+$'
You can read the highlighted lines as:
This is the
payload
of themessage
that theHello world application
is subscribed to. You canpublish
themessage
to thehello
channel and theHello world application
will receive it.
1asyncapi: 2.5.0
2info:
3 title: Hello world application
4 version: '0.1.0'
5channels:
6 hello:
7 publish:
8 message:
9 payload:
10 type: string
11 pattern: '^hello .+$'
The payload
object defines how the message must be structured. In this example, the message must be a string and match the given regular expression in the format hello {name}
string.