Tech
[程序员] [分享创造] mqttkit:给 MQTT 写应用,像写 Elysia / Hono 那样
给 MQTT 写应用,为什么不能像写 Elysia / Hono 一样?
mqttkit:在 Aedes / EMQX 之上加一层应用框架——有序中间件、类型化 topic 路由、MQTT 5 RPC 、自动生成 AsyncAPI 文档。
起因:MQTT 的应用层一直是一片散沙
只要在 Node 里写过认真一点的 MQTT 后端,下面这段代码你大概率写过:
client.on('message', (topic, payload) => {
if (topic.startsWith('devices/') && topic.endsWith('/events')) {
const uid = topic.split('/')[1]
// 临时手写鉴权
// 临时手写 JSON.parse + 校验
// 临时手写错误处理
// 临时手写埋点
// ...
} else if (topic.startsWith('server/')) {
// ...
}
})
这...
Read the full discussion on V2EX
This article was aggregated from V2EX. Click to join the conversation.
View on V2EX