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 ...
随机推荐
- bootstrap table--面相配置、hook、适配的表格框架
bootstrap table--面相配置.hook.适配的表格框架
- ASP.NETCore 3.0 Autofac替换及控制器属性注入及全局容器使用
1.Autofac基础使用 参考: https://www.cnblogs.com/li150dan/p/10071079.html 2.ASP.NETCore 3.0 Autofac 容器替换 需要 ...
- English--consonant_摩擦音
consonant_摩擦音_[f]和[v].[s]和[z].[∫]和[ʒ] 摩擦音:理论上可以无限延长气流. [f]:噘嘴,上牙咬住下唇,送气,通过气流摩擦发音,声带不震动.knife.food.le ...
- 【转载】使用宝塔Linux面板屏蔽某些IP访问你的服务器
在服务器的运维过程中,有时候发现一些异常IP或者扫描漏洞攻击者IP访问你的网站,此时如果想屏蔽该IP访问你的服务器,可以通过云服务器厂商提供的安全组进行设置.如果服务器安装有宝塔面板,也可以通过宝塔面 ...
- 工具sublime安装
默认安装后是英文版 view-show console 安装packagecontrol https://packagecontrol.io/installation ctrl+`打开控制台,输入代码 ...
- js new Date()不带时分秒时,时间变了 问题解决
//先把电脑系统时间的 时区 调到别的时间一下如 夏威夷 UTC-10:00//在浏览器的Console里运行如下代码,getMonth是从0开始的,所以要+1 var d=new Date(&quo ...
- Python 的稀疏矩阵
什么是稀疏矩阵 简单的说,如果一个矩阵中大部分元素为0,就被称为稀疏矩阵. 对于稀疏矩阵而言,实际存储的数据项很少.如果在计算机中采用传统的二维数组(Python中用二维列表)来存储稀疏矩阵,就会浪费 ...
- 一款APP的完整开发流程 (转载)
来源:https://www.sohu.com/a/239089829_100063940 近年来,在市场和政策的双轮驱动下,我国服务外包产业快速发展,服务智能化趋势显现.随着企业核心业务外包活动的日 ...
- linux防火墙和xshell的链接
centos7用的firewalld 1.firewalld的基本使用 启动: systemctl start firewalld 关闭: systemctl stop firewalld 查看状态: ...
- Linux命令passwd
passwd 简单说明:passwd命令的用法也很多,我们只选如下的几个参数加以说明:想了解更多,请参考man passwd或passwd --help :passwd [OPTION...] pas ...