AsyncAPI 试用
AsyncAPI 提供了类似openapi的代码生成,以下demo,来自官方,只是目前官方的generator有些问题以下
同时说明运行中的一些问题
环境准备
主要是安装依赖组件
npm install -g asyncapi-generator mqtt
定义AsyncAPI
稍有改动,主要是channel(mqtt 的topic)
- yaml 文件
asyncapi: '2.0.0'
info:
title: Streetlights API
version: '1.0.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'
servers:
mosquitto:
url: test.mosquitto.org
protocol: mqtt
channels:
dalong/measured:
publish:
summary: Inform about environmental lighting conditions for a particular streetlight.
message:
payload:
type: object
properties:
id:
type: integer
minimum: 0
description: Id of the streetlight.
lumens:
type: integer
minimum: 0
description: Light intensity measured in lumens.
sentAt:
type: string
format: date-time
description: Date and time when the message was sent.
- 生成代码命令
ag asyncapi.yaml nodejs -p server=mosquitto
- 简单说明
如果直接使用url test.mosquitto.org 会有解析的问题,如下:
Something went wrong:
Template render error: (unknown path) [Line 29, Column 36]
TypeError [ERR_INVALID_URL]: Invalid URL: test.mosquitto.org
at Object._prettifyError (/usr/local/lib/node_modules/asyncapi-generator/node_modules/nunjucks/src/lib.js:36:11)
at /usr/local/lib/node_modules/asyncapi-generator/node_modules/nunjucks/src/environment.js:567:19
at Template.root [as rootRenderFunc] (eval at _compile (/usr/local/lib/node_modules/asyncapi-generator/node_modules/nunjucks/src/environmen
t.js:637:18), <anonymous>:83:3)
at Template.render (/usr/local/lib/node_modules/asyncapi-generator/node_modules/nunjucks/src/environment.js:556:10)
at Environment.renderString (/usr/local/lib/node_modules/asyncapi-generator/node_modules/nunjucks/src/environment.js:380:17)
at Promise (/usr/local/lib/node_modules/asyncapi-generator/lib/generator.js:507:21)
at new Promise (<anonymous>)
at Generator.renderString (/usr/local/lib/node_modules/asyncapi-generator/lib/generator.js:506:12)
at Generator.renderFile (/usr/local/lib/node_modules/asyncapi-generator/lib/generator.js:531:19)
at <anonymous>
解决方法:临时修改为一个url 格式的比如test.mosquitto.org:1883 生成代码之后再修改回来
- 生成效果
Done! ✨
Check out your shiny new generated files at /Users/dalong/mylearning/asyncapi-learning/first/streetlights.

- 修改几处生成的代码
配置文件:
config/common.yml:
如下:
default:
app:
name: Streetlights API
version: 1.0.0
broker:
mqtt:
url: mqtt://test.mosquitto.org
topics: ["dalong/measured"]
qos:
protocol: mqtt
retain:
subscribe: true
development:
test:
staging:
production:
路由以及handler修改:
路由: 
随便些一个名字,注意后边handler 需要和这个一样

启动&&测试
- 安装npm依赖
yarn
- 启动
yarn start
- 模拟消息发送
mqtt pub -t 'dalong/measured' -h 'test.mosquitto.org' -m '{"id": 1111, "lumens": 3, "sentAt": "2019-10-06T12:34:32.000Z"}'
- 效果

说明
以上是一个简单的试用,以及在使用中碰到的问题,AsyncAPI 是一个很不错的编写事件驱动应用的指南
参考资料
https://www.asyncapi.com/docs/tutorials/streetlights/
https://github.com/asyncapi/generator
http://test.mosquitto.org/
https://github.com/rongfengliang/asyncapi-streetlights-demo
AsyncAPI 试用的更多相关文章
- SharePoint Online 申请试用链接地址
SharePoint Online 申请试用链接地址: https://products.office.com/en-us/business/compare-office-365-for-busine ...
- 活动助手Beta用户试用报告
用户试用报告 1.面向参与者用户 1.1 日常参加各类学习(水综测)活动中,有没有遇到以下问题: (1) 信息来源混乱,不知道靠不靠谱 (2) 每次报名都要重新填写自己的学号手机号,有时候填错了就没综 ...
- 创建WP8试用应用
参考资料: 创建 Windows Phone 的试用应用 如何在 Windows Phone 应用中实现试用体验 Windows Phone 7 开发 31 日谈——第23日:提供试用版应用程序 对资 ...
- 达梦7的试用 与SQLSERVER的简单技术对比
达梦7的试用 与SQLSERVER的简单技术对比 达梦数据库公司推出了他们的数据库服务管理平台,可以在该平台使用达梦数据库而无须安装达梦7数据库 地址:http://online.dameng.com ...
- Beta版本——用户试用与调研报告
1 引言 1.1 系统概述 毕设导师智能分配系统是一个用来简化传统手工匹配繁琐操作的系统.本系统将学生报志愿.系负责人收集整理数据.相关人员进行手工分配.反馈选择结果等繁琐的操作转移到线上.把毕设 ...
- 【记录】尝试用android-logging-log4j去实现log输出内容到sd卡中的文件的功能
[背景] 折腾: [记录]给Android中添加log日志输出到文件 期间,已经试了: [记录]尝试用android中microlog4android实现log输出到文件的功能 但是不好用. 然后就是 ...
- 代码阅读分析工具Understand 2.0试用
Understand 2.0是一款源代码阅读分析软件,功能强大.试用过一段时间后,感觉相当不错,确实可以大大提高代码阅读效率.由于Understand功能十分强大,本文不可能详尽地介绍它的所有功能,所 ...
- 如何申请国际版Office365和Azure的试用账号
关键字:国际版.Office365.Azure.试用账号.1美元.信用卡 待续
- Android N preview 试用
一.下载更新包 下载地址:https://developer.android.com/intl/zh-cn/preview/download.html 注意下载适合你手机的安装包哦 二.把你手机的oe ...
随机推荐
- vue截取字符串
1.vue中截取前11位字符串 <li> <span>立案时间:</span> <p>{{jsyd.TIME.substring(0,10)}}< ...
- Python 3 + Selenium 3 简单入门学习示例 126邮箱登录
这是一个很多基础演示的书上的例子,但是一般按照这些书上的代码可能都不能成功登录.也许是网易修改了126的页面导致的吧,下面给出最新的能够work的版本 from selenium import web ...
- 封装:WPF基于MediaElement封装的视频播放器
原文:封装:WPF基于MediaElement封装的视频播放器 一.目的:应用MediaElement创建媒体播放器 二.效果图 三.目前支持功能 播放.暂停.停止.快进.快退.声音大小.添加播放列表 ...
- Javascript文件上传插件
jQuery File Uploader 这是最受欢迎的 jQuery 文件上传组件,支持批量上传,拖放上传,显示上传进度条以及校验功能. 支持预览图片.音频和视频,支持跨域上传和客户端图片缩放,支持 ...
- Map接口---Day20
Map接口概述: 现实生活中,我们常会看到这样的一种集合:IP地址与主机名,身份证号与个人,系统用户名与系统用户对象等, 这种一一对应的关系,就叫做映射.Java提供了专门的集合类用来存放这种对象关系 ...
- 米尔XC7Z010开发板资源
关于XC7Z010开发板 详细介绍http://www.myir-tech.com/product/myc_C7Z010_20.htm Xilinx基于28nm工艺流程的Zynq-7000 All P ...
- webpack面试题
1.webpack的核心概念 Entry:入口,Webpack进行打包的起始点(文件) Output:出口,webpack编译打包生成的bundle(打包文件) Loader:模块加载(转换)器,将非 ...
- 在微信小程序中使用redux
本文主要讲述,在微信小程序中如何使用redux DEMO 需要解决的问题 如何在小程序中引入redux状态管理库,及它相关的插件? 微信小程序没有清晰的异步api,便于thunkMiddleware处 ...
- 从 Vue 的视角学 React(一)—— 项目搭建
虽然 Vue 在国内一家独大,但在全球范围内,React 依然是最流行的前端框架 最近和一些朋友聊天,发现很多项目都选择了 React 技术栈,而且公司的新项目也决定使用 React 我一直以来都是走 ...
- 链表(Linked List)
链表(Linked List) 一.介绍 链表是有序的列表,它在内存中存储方式(物理存储)如下: 小结: (1)链表是以节点的方式来存储,是链式存储. (2)每个节点包含 data 域:存储数据:ne ...