-
-
Notifications
You must be signed in to change notification settings - Fork 667
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: adding document for Adding messages page #2025
Closed
Closed
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
f64b838
add message page added
mhmohona ae2413c
small fix
mhmohona 9fec48d
updating according to review
mhmohona 70916b9
small fix
mhmohona 0daa262
update description
mhmohona 756da69
small fix
mhmohona a159843
small fix
mhmohona 5dcf126
small fix
mhmohona 1ca94ef
fix broken link
mhmohona 1c25232
updating as per review
mhmohona File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
--- | ||
title: 'AsyncAPI Document' | ||
weight: 50 | ||
--- |
136 changes: 136 additions & 0 deletions
136
pages/docs/concepts/asyncapi-document/adding-messages.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,136 @@ | ||
--- | ||
title: Adding Messages | ||
weight: 140 | ||
--- | ||
|
||
Adding [messages](../message) in an AsyncAPI document primarily involves defining channels, operations, and messages, which is crucial for documenting the exchange of data between your applications. In AsyncAPI, you define the interaction of your application with a message broker in terms of channels and operations. [Channels](../channel) are the medium through which messages are sent or received, while operations represent the actions of publishing or subscribing to these channels. | ||
|
||
Here is a diagram explaining messages: | ||
|
||
```mermaid | ||
graph TD; | ||
A[AsyncAPI Message] --> B[Headers] | ||
A --> C[Payload] | ||
|
||
style A fill:#47BCEE,stroke:#47BCEE; | ||
``` | ||
|
||
The above diagram shows the components of AsyncAPI messages: headers and payload. | ||
|
||
Here is an example of a simple message: | ||
|
||
```yml | ||
channels: | ||
user/signedup: | ||
address: 'application/json' | ||
messages: | ||
userSignUp: | ||
$ref: '#/components/messages/userSignUp' | ||
``` | ||
|
||
This document defines a `user/signedup` channel where a `userSignUp` message can be made. | ||
|
||
## Using multiple message types | ||
|
||
AsyncAPI supports defining multiple possible message types for a single channel. | ||
|
||
Here is a diagram showing the use of multiple message types: | ||
|
||
```mermaid | ||
graph TD; | ||
A[Operations] --> B[Messages] | ||
B --> C[Message Type 1] | ||
B --> D[Message Type 2] | ||
style B fill:#47BCEE,stroke:#47BCEE; | ||
``` | ||
|
||
This diagram shows how AsyncAPI uses multiple message types for a single channel. | ||
|
||
Here is an example document of how AsyncAPI supports the use of multiple message types for a single channel: | ||
|
||
```yml | ||
channels: | ||
userSignupWithReply: | ||
messages: | ||
signup: | ||
$ref: '#/components/messages/userSignedUp' | ||
reply: | ||
$ref: '#/components/messages/userSignedUpReply' | ||
``` | ||
|
||
The above document shows a channel `userSignupWithReply` under which two messages can be sent or received: `userSignedUp` or `userSignedUpReply`. | ||
|
||
## Specifying `contentType` in messages | ||
|
||
The `contentType` field specifies the format of the payload. If it's not provided, the default payload format is `application/json`. | ||
|
||
Here is a diagram showing how to specify `contentType` in messages: | ||
|
||
```mermaid | ||
graph TD; | ||
A[AsyncAPI Message] --> B[contentType] | ||
style A fill:#47BCEE,stroke:#47BCEE; | ||
``` | ||
|
||
The above diagram shows an AsyncAPI message that can specify a content type (`contentType`), which defaults to `application/json`. | ||
|
||
The following code shows how `contentType` is added to the Message: | ||
|
||
```yml | ||
messageId: userSignup | ||
name: UserSignup | ||
title: User signup | ||
summary: Action to sign a user up. | ||
description: A longer description | ||
contentType: application/json | ||
``` | ||
|
||
In this document, the `contentType` is specified as `application/json` for the `userSignup` message. | ||
|
||
## Reusing components | ||
|
||
The components object in the AsyncAPI specification contains reusable objects, but they will only impact the application if they are specifically referred to outside the components object. | ||
|
||
Here is a diagram explaining how to reuse components: | ||
|
||
```mermaid | ||
flowchart TB | ||
|
||
subgraph Components Object | ||
Component_1 | ||
Component_2 | ||
Component_3 | ||
end | ||
|
||
subgraph API | ||
API_implementation --> Component_1:Uses | ||
API_implementation --> Component_2:Uses | ||
API_implementation --> Component_3:Uses | ||
|
||
style API_implementation fill:#47BCEE,stroke:#47BCEE; | ||
end | ||
``` | ||
|
||
The above diagram shows how components in the API implementation are used by various components, emphasizing their impact when referred to outside the components object. | ||
|
||
Here is an example demonstrating how components are reused in AsyncAPI: | ||
|
||
```yml | ||
components: | ||
messages: | ||
user: | ||
contentType: 'application/json' | ||
schema: | ||
$ref: '#/components/schemas/User' | ||
|
||
schemas: | ||
User: | ||
type: object | ||
properties: | ||
id: | ||
type: string | ||
name: | ||
type: string | ||
``` | ||
|
||
The above document shows reuse of a component by defining a `User` schema. |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm confused by this diagram. What exactly did you try to convey here? 🤔
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I tried to explain the reusing components section here. Do you think I should change it? In what way it would be better in your opinion?