Introduction to AsyncAPI

A presentation at Nordic Kafka Meetup in May 2021 in by Lorna Jane Mitchell

Slide 1

Slide 1

Introduction to AsyncAPI for Kafka Lorna Mitchell, Aiven

Slide 2

Slide 2

Introducing: AsyncAPI Specification for describing event-driven and data streaming systems. • https://asyncapi.com • Open standard • Active community • Supports Kafka! And MQTT, AMQP, WS …. @lornajane

Slide 3

Slide 3

Why use AsyncAPI? Describe your event-driven systems in a useful and reusable way. • Clearly track changes in a text-based description • Generate documentation and code • Verify system operations against description • Enclose existing payload descriptions (CloudEvents, Avro) within AsyncAPI @lornajane

Slide 4

Slide 4

Bunch of JSON/YAML asyncapi: ‘2.0.0’ id: ‘urn:com.github.lornajane.example1’ info: contact: license: servers: local-kafka: channels: factorysensor: subscribe: message: payload: examples: components: securitySchemes: messages: @lornajane

Slide 5

Slide 5

Generated Docs @lornajane

Slide 6

Slide 6

AsyncAPI Descriptions

Slide 7

Slide 7

AsyncAPI Structure Top-level elements: • asyncapi and id • info • servers • channels • tags • components @lornajane

Slide 8

Slide 8

Info Section Valuable metadata is held in info. info: title: Thingum Industries Sensors description: Keeping the factory and all the machines running nicely version: 1.0.0 contact: name: Lorna email: lornajane@aiven.io url: https://github.com/aiven/thingum-industries license: name: Apache 2.0 url: http://www.apache.org/licenses/LICENSE-2.0.html @lornajane

Slide 9

Slide 9

Channels Section Main operations are described here channels: door-sensor: description: Door sensors (external and internal) subscribe: operationId: DoorSensor description: Open/closed state information from the doors. tags: - name: sensor bindings: kafka: clientId: type: string message: $ref: ‘#/components/messages/DoorData’ @lornajane

Slide 10

Slide 10

$ref Reusable Content Refer to content in the components section message: $ref: ‘#/components/messages/DoorData’ Useful for reuse and readability. We can also refer to other files: message: $ref: ‘doors-publish.yaml#/components/messages/DoorData’ @lornajane

Slide 11

Slide 11

Components Section A collection of reusable components components: messages: DoorData: name: door-sensor-data title: Door Sensor Reading description: Door sensor data payload: type: object properties: location: type: string state: enum: [“open”, “closed”] @lornajane

Slide 12

Slide 12

AsyncAPI Loves Standards AsyncAPI is compatible with other standards: • Avro or CloudEvent payload descriptions can be accessed with $ref • JSONSchema is supported • Based on and builds on OpenAPI @lornajane

Slide 13

Slide 13

AsyncAPI Tools

Slide 14

Slide 14

Generate Documentation Documentation with https://www.asyncapi.com/generator @lornajane

Slide 15

Slide 15

Generate Code Also using the generator: ag thingum/doors-publish.yaml \ @asyncapi/nodejs-template \ -o thingum/nodejs \ -p server=development @lornajane

Slide 16

Slide 16

Tools Landscape • VSCode extension: https://github.com/asyncapi/vs-asyncapi-preview • Validation/linting: https://stoplight.io/open-source/spectral/ • Generate test data: https://microcks.io/ • GitHub action: https://github.com/WaleedAshraf/asyncapi-github-action @lornajane

Slide 17

Slide 17

AsyncAPI and You Open standards, seamless integrations

Slide 18

Slide 18

Resources • AsyncAPI: https://asyncapi.com • Aiven: https://aiven.io - try the free trial • Examples: https://github.com/aiven/thingum-industries @lornajane