-
Notifications
You must be signed in to change notification settings - Fork 611
AsyncAPI with CloudEvents #1349
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
Merged
Merged
Changes from 4 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
a0c1d2c
AsyncAPI with CloudEvents
Lazzaretti 0a1b57a
add changes from code review
Lazzaretti 2e5a250
fix: title naming
Lazzaretti 26ace1f
Add short samples on how to add CloudEvents support to AsyncAPI
Lazzaretti 2c47896
Change links for asyncapi-traits to location after merging
Lazzaretti 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 hidden or 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,2 @@ | ||
| # AsyncAPI With CloudEvents - Version 1.0.3-wip | ||
| מסמך זה טרם תורגם. בבקשה תשתמשו [בגרסה האנגלית של המסמך](../../../working-drafts/asyncapi.md) לבינתיים. |
This file contains hidden or 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,6 @@ | ||
| # AsyncAPI With CloudEvents - Version 1.0.3-wip | ||
|
|
||
| 本文档尚未被翻译,请先阅读英文[原版文档](../../../working-drafts/asyncapi.md) 。 | ||
|
|
||
| 如果您迫切地需要此文档的中文翻译,请[提交一个issue](https://github.com/cloudevents/spec/issues) , | ||
| 我们会尽快安排专人进行翻译。 |
39 changes: 39 additions & 0 deletions
39
cloudevents/working-drafts/asyncapi-examples/light-switch-events-binary-kafka.yaml
This file contains hidden or 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,39 @@ | ||
| # yaml-language-server: $schema=https://asyncapi.com/schema-store/3.0.0-without-$id.json | ||
| asyncapi: 3.0.0 | ||
| info: | ||
| title: Light Switch Events With CloudEvents as Headers (Binary Mode) | ||
| version: 1.0.0 | ||
| description: Informes about light swich changes. | ||
| operations: | ||
| onOfficeLightSwitchChanged: | ||
| title: Office light switch was triggered | ||
| channel: | ||
| $ref: '#/channels/officeLightSwitchChanged' | ||
| action: receive | ||
|
|
||
| channels: | ||
| officeLightSwitchChanged: | ||
| address: 'lightswitch.office.changed' | ||
| title: Office light switch changes | ||
| messages: | ||
| lightSwitchChanged: | ||
| $ref: '#/components/messages/lightSwitchChanged' | ||
|
|
||
| components: | ||
| messages: | ||
| lightSwitchChanged: | ||
| description: Light switch was triggered event with CloudEvents headers | ||
| traits: | ||
| - $ref: 'https://raw.githubusercontent.com/Lazzaretti/asyncapi-with-cloudevents-traits/main/traits/cloudevents-headers-kafka-binary.yaml' | ||
| payload: | ||
| type: object | ||
| properties: | ||
| lightSwitchId: | ||
| type: integer | ||
| examples: | ||
| - 1 | ||
| position: | ||
| type: string | ||
| enum: | ||
| - ON | ||
| - OFF |
42 changes: 42 additions & 0 deletions
42
cloudevents/working-drafts/asyncapi-examples/light-switch-events-structured-json.yaml
This file contains hidden or 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,42 @@ | ||
| # yaml-language-server: $schema=https://asyncapi.com/schema-store/3.0.0-without-$id.json | ||
| asyncapi: 3.0.0 | ||
| info: | ||
| title: Light Switch Events With CloudEvents as Headers (Binary Mode) | ||
| version: 1.0.0 | ||
| description: Informes about light swich changes. | ||
| operations: | ||
| onOfficeLightSwitchChanged: | ||
| title: Office light switch was triggered | ||
| channel: | ||
| $ref: '#/channels/officeLightSwitchChanged' | ||
| action: receive | ||
|
|
||
| channels: | ||
| officeLightSwitchChanged: | ||
| address: 'lightswitch.office.changed' | ||
| title: Office light switch changes | ||
| messages: | ||
| lightSwitchChanged: | ||
| $ref: '#/components/messages/lightSwitchChanged' | ||
|
|
||
| components: | ||
| messages: | ||
| lightSwitchChanged: | ||
| description: Light switch was triggered event with CloudEvents headers | ||
| payload: | ||
| type: object | ||
| allOf: | ||
| - $ref: 'https://raw.githubusercontent.com/cloudevents/spec/v1.0.2/cloudevents/formats/cloudevents.json' | ||
| properties: | ||
| data: | ||
| type: object | ||
| properties: | ||
| lightSwitchId: | ||
| type: integer | ||
| examples: | ||
| - 1 | ||
| position: | ||
| type: string | ||
| enum: | ||
| - ON | ||
| - OFF |
56 changes: 56 additions & 0 deletions
56
cloudevents/working-drafts/asyncapi-traits/cloudevents-headers-kafka-binary.yaml
This file contains hidden or 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,56 @@ | ||
| name: cloudevents-headers-kafka-binary | ||
| summary: Message headers for CloudEvents in binary content mode with Kafka (see https://github.com/cloudevents/spec/blob/v1.0.2/cloudevents/bindings/kafka-protocol-binding.md) | ||
| headers: | ||
| type: object | ||
| required: | ||
| - ce_id | ||
| - ce_source | ||
| - ce_specversion | ||
| - ce_type | ||
| properties: | ||
| ce_id: | ||
| type: string | ||
| minLength: 1 | ||
| description: Identifies the event. | ||
| examples: | ||
| - "1234-1234-1234" | ||
| ce_source: | ||
| type: string | ||
| format: uri-reference | ||
| minLength: 1 | ||
| description: Identifies the context in which an event happened. | ||
| examples: | ||
| - "https://example.com/storage/tenant/container" | ||
| ce_specversion: | ||
| type: string | ||
| description: The version of the CloudEvents specification which the event uses. | ||
| enum: | ||
| - "1.0" | ||
| ce_type: | ||
| type: string | ||
| minLength: 1 | ||
| description: Describes the type of event related to the originating occurrence. | ||
| examples: | ||
| - "com.example.someevent" | ||
| content-type: | ||
| type: string | ||
| description: Kafka default field to describing the content type of the data. Must be mapped directly to the CloudEvents datacontenttype attribute. | ||
| examples: | ||
| - "application/avro" | ||
| - "application/json;charset=utf-8" | ||
| ce_dataschema: | ||
| type: string | ||
| description: Identifies the schema that data adheres to. | ||
| examples: | ||
| - "http://registry.com/schema/v1/much.json" | ||
| ce_subject: | ||
| type: string | ||
| description: Describes the subject of the event in the context of the event producer (identified by source) | ||
| examples: | ||
| - mynewfile.jpg | ||
| ce_time: | ||
| type: string | ||
| format: date-time | ||
| description: Timestamp of when the occurrence happened. Must adhere to RFC 3339. | ||
| examples: | ||
| - "2018-04-05T17:31:00Z" |
This file contains hidden or 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,67 @@ | ||
| # AsyncAPI With CloudEvents - Version 1.0.3-wip | ||
|
|
||
| ## Purpose | ||
|
|
||
| Asynchronous APIs, e.g., events, can be specified in AsyncAPI, similar to how | ||
| RESTful APIs can be specified in [OpenAPI](https://swagger.io/specification/). | ||
| When defining new events in an API-first approach it can be hard to add | ||
| CloudEvents headers or fields according to spec. This makes following the | ||
| standard harder. This document will clarify how CloudEvents headers can be | ||
| specified in AsyncAPI. | ||
|
|
||
| ## Usage | ||
|
|
||
| Depending on the protocol and the mode (binary/structured), the inclusion of the | ||
| CloudEvents fields varies. | ||
|
|
||
| ## Structured Mode | ||
|
|
||
| In structured mode, the entire event, attributes, and data are encoded in the | ||
| message body. When using structured mode, the usage only varies depending on the | ||
| serialization format: | ||
|
|
||
| | Format | Example | Include | | ||
| | ------ | ----------------------------------------------------------------------- | ---------------------------------------- | | ||
| | JSON | [Short Example](#json-example) [Full Example](./asyncapi-examples/light-switch-events-structured-json.yaml) | [Reference](../formats/cloudevents.json) | | ||
|
|
||
| ### JSON Example | ||
|
|
||
| To add CloudEvents in structured mode, the following `allOf` reference needs to | ||
| be added: | ||
|
|
||
| ```yaml | ||
| components: | ||
| messages: | ||
| messageKey: | ||
| payload: | ||
| type: object | ||
| allOf: | ||
| - $ref: 'https://raw.githubusercontent.com/cloudevents/spec/v1.0.2/cloudevents/formats/cloudevents.json' | ||
| ``` | ||
|
|
||
| See also: [Full Example](./asyncapi-examples/light-switch-events-structured-json.yaml) | ||
|
|
||
| ## Binary Mode | ||
|
|
||
| In binary mode, protocol-specific bindings are mapping fields to protocol | ||
| content-type metadata property or headers; therefore, the AsyncAPI format needs | ||
| to depend on the protocol: | ||
|
|
||
| | Protocol Binding | Example | Trait | | ||
| | ---------------------------------------------- | -------------------------------------------------------------------- | ---------------------------------------------------------------- | | ||
| | [Kafka](../bindings/kafka-protocol-binding.md) | [Short Example](#avro-example) [Full Example](./asyncapi-examples/light-switch-events-binary-kafka.yaml) | [Trait](./asyncapi-traits/cloudevents-headers-kafka-binary.yaml) | | ||
|
|
||
| ### Avro Example | ||
|
|
||
| To add CloudEvents in binary mode, the following `traits` reference needs to | ||
| be added: | ||
|
|
||
| ```yaml | ||
| components: | ||
| messages: | ||
| messageKey: | ||
| traits: | ||
| - $ref: 'https://raw.githubusercontent.com/Lazzaretti/asyncapi-with-cloudevents-traits/main/traits/cloudevents-headers-kafka-binary.yaml' | ||
| ``` | ||
|
|
||
| See also: [Full Example](./asyncapi-examples/light-switch-events-binary-kafka.yaml) | ||
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.
Uh oh!
There was an error while loading. Please reload this page.