In the previous lesson, you learned how to create the definition of a simple Hello World application. Let's take it from there.
In this tutorial, you'll learn how to add servers
to your AsyncAPI document. Adding and defining servers is useful because it specifies where and how to connect. The connection facilitates where to send and receive messages.
1asyncapi: 3.0.0
2info:
3 title: Hello world application
4 version: '0.1.0'
5servers:
6 production:
7 host: broker.mycompany.com
8 protocol: amqp
9 description: This is "My Company" broker.
10channels:
11 hello:
12 address: 'hello'
13 messages:
14 sayHelloMessage:
15 payload:
16 type: string
17 pattern: '^hello .+$'
18operations:
19 receiveHello:
20 action: 'receive'
21 channel:
22 $ref: '#/channels/hello'
You've now added a new section called servers
in your AsyncAPI document.
You might have noticed that our example mentions amqp
, a very common protocol that was popularized by RabbitMQ (among others). While our example uses amqp
, you can use any protocol. The most common protocols used are mqtt
(widely adopted by the Internet of Things and mobile apps), kafka
(popular for its streaming solution), ws
(WebSockets are frequently used in browsers), and http
(used in HTTP streaming APIs).
Remember
The servers
section defines where your application should connect to start sending and receiving messages.
- If you are using a broker-centric architecture such as Kafka or RabbitMQ, specify the broker URL.
- If you have the classic client-server model such as for REST APIs, then your
server
should be the URL of the server.
Conclusion
Now you know where the Hello world application
connects to, and you can start receiving hello {name}
messages.
In the next section, you'll learn how to add security requirements to your server.