ASYNCAPI
https://www.asyncapi.com
Introduction
AsyncAPI provides a specification that allows you to define Message-Driven APIs in a machine-readable format. It’s protocol-agnostic, so you can use it for APIs that work over MQTT, AMQP, WebSockets, STOMP, etc. The spec is very similar to OpenAPI/Swagger so, if you’re familiar with them, AsyncAPI should be easy for you.
A basic example
The following example describes a very simple streetlights service. It describes a service you can connect at api.streetlights.smartylighting.com (port 1883 or 8883) and allows you to publish information about environmental lighting conditions.
|
asyncapi: '1.0.0'
info:
title: Streetlights API
version: '1.0'
description: |
The Smartylighting Streetlights API allows you
to remotely manage the city lights.
license:
name: Apache 2.0
url: 'https://www.apache.org/licenses/LICENSE-2.0'
baseTopic: smartylighting.streetlights.1.0
servers:
- url: api.streetlights.smartylighting.com:{port}
scheme: mqtt
description: Test broker
variables:
port:
description: Secure connection (TLS) is available through port 8883.
default: '1883'
enum:
- '1883'
- '8883'
topics:
event.{streetlightId}.lighting.measured:
publish:
$ref: '#/components/messages/lightMeasured'
components:
messages:
lightMeasured:
summary: Inform about environmental lighting conditions for a particular streetlight.
payload:
type: object
properties:
lumens:
type: integer
minimum: 0
description: Light intensity measured in lumens.
sentAt:
$ref: "#/components/schemas/sentAt"
schemas:
sentAt:
type: string
format: date-time
description: Date and time when the message was sent.
|
If you are familiar with the OpenAPI specification, I’m sure you already found lots of similarities. But, what’s this topics section in the file? And what’s this event.{streetlightId}.lighting.measured? Let’s dive into it!
Core concepts
The AsyncAPI specification assumes two core concepts:
1. Messages
Consumer(s) communicate with your API via messages. A message is a piece of information two or more programs exchange. Most of the times to notify the other end(s) that, either an event has occurred or you want to trigger a command.
Technically speaking the events and actions will always be sent in the same way. These are just messages, and their content can be anything. So when we talk about the difference between events and actions, this is only a semantic differentiation of message’s content. We do not enforce you to make any difference between them, although we encourage you to do it.
A message can contain headers and a payload. However, both are optional. The specification allows you to define any header, to remain as much protocol-agnostic as possible.
2. Topics
Message-driven protocols usually contain something called topic (MQTT), routing key (AMQP), destination (STOMP), etc. To some extent, they can compare to URLs in HTTP APIs. So, when you send a message to your API, it will be routed depending on the topic you published on. This feature allows you to create APIs that subscribe to specific topics and publish to other ones.
ASYNCAPI的更多相关文章
- AsyncAPI 几个方便的工具
AsyncAPI 类似openapi 也提供了一些周边工具 editor 类似openapi 的,但是目前官方已经不推荐使用了,推荐使用playground,以下是构建一个容器镜像 clone 代码 ...
- AsyncAPI 试用
AsyncAPI 提供了类似openapi的代码生成,以下demo,来自官方,只是目前官方的generator有些问题以下 同时说明运行中的一些问题 环境准备 主要是安装依赖组件 npm instal ...
- AsyncAPI and CloudEvents
一篇比较AsyncAPI与CloudEvents的文章,很不错,原文连接:https://www.asyncapi.com/blog/asyncapi-cloud-events/ I’ve been ...
- asyncapi 指南
asyncapi 是可以用来创建异步机器可读定义api的指南,我们可以用来创建事件驱动的架构. 说明 asyncapi 的定义类似openapi,目前指南版本为2.0,很值得学习下 参考资料 http ...
- js 模块化历程
作者:吕大豹 网址:http://www.cnblogs.com/lvdabao/p/js-modules-develop.html 这是一篇关于js模块化历程的长长的流水账,记录js模块化思想的诞生 ...
- Salesforce Bulk API 基于.Net平台下的实施
在最近的salesforce实施项目中应用到Bulk API来做数据接口.顺便把实际应用的例子写下来.希望对做salesforce接口的朋友有借鉴作用. 一 参考网络牛人写好的Demo. 下载地址:h ...
- Boost - 从Coroutine2 到Fiber
Boost - 从Coroutine2 到Fiber 协程引子 我开始一直搞不懂协程是什么,网上搜一搜,(尤其是Golang的goroutine)感觉从概念上听起来有点像线程池,尤其是类似Java的E ...
- 《CUDA并行程序设计:GPU编程指南》
<CUDA并行程序设计:GPU编程指南> 基本信息 原书名:CUDA Programming:A Developer’s Guide to Parallel Computing with ...
- 2-11 tensorflow常量变量定义
D:\Users\ZHONGZHENHUA\Anaconda3\envs\tensorflow\Lib\site-packages\tensorflow https://developer.nvidi ...
随机推荐
- Cmake实现样例
多目录工程的CmakeLists.txt编写(自动添加多目录下的文件) http://www.cnblogs.com/chengxuyuancc/p/5347646.html 实现类似于vs中工程的C ...
- Adversarial Training
原于2018年1月在实验室组会上做的分享,今天分享给大家,希望对大家科研有所帮助. 今天给大家分享一下对抗训练(Adversarial Training,AT). 为何要选择这个主题呢? 我们从上图的 ...
- 第二百二十节,jQuery EasyUI,Slider(滑动条)组件
jQuery EasyUI,Slider(滑动条)组件 学习要点: 1.加载方式 2.属性列表 3.事件列表 4.方法列表 本节课重点了解 EasyUI 中 Slider(滑动条)组件的使用方法,这个 ...
- 开发人员需知的Web缓存知识(转)
什么是Web缓存,为什么要使用它? 缓存的类型: 浏览器缓存: 代理服务器缓存: 网关缓存: Web缓存无害吗?为什么要鼓励缓存? Web缓存如何工作 如何控制缓存和不缓存: HTML Meta标签 ...
- 路由器port触发与转发---Port Forwarding & Port Triggering
What is Port Triggering? If you have not read my explanation of port forwarding do so now. You can f ...
- backbone Model调用save方法的时候提交方式
horizon使用的是backbone框架,但是我们的后台api都是只接收post请求,请求的路径为/api/,根据backbone的官档解释: backbone的model.save方法会判断当前的 ...
- js阻止表单提交
<!DOCTYPE html><html><head> <title>Simple Login Form</title> < ...
- Java并发框架——AQS之怎样使用AQS构建同步器
AQS的设计思想是通过继承的方式提供一个模板让大家能够非常easy依据不同场景实现一个富有个性化的同步器.同步器的核心是要管理一个共享状态,通过对状态的控制即能够实现不同的锁机制. AQS的设计必须考 ...
- c#——表达式树在LINQ动态查询
一般如果逻辑比较简单,只是存在有的情况多一个查询条件,有的情况不需要添加该查询条件 简单方式这样操作就可以了 public IQueryable<FileImport> DynamicCh ...
- 如何用MathType编辑这三个符号
MathType是一款专门的公式编辑器,用来编辑数学物理等公式,很多期刊杂志的排版都会用到它.用MathType编辑公式的时候,完全不用考虑学习和上手的过程,打开就可以编辑出你的公式,所以这个工具对于 ...