您现在的位置是:首页 > 文章详情

OOX - 0.2.0 发布, 使用 Node.JS 快速构建分布式服务

日期:2021-12-15点击:421

更新内容

  1. 使用AsyncLocalStorage 实现链路调用跟踪, 替换旧的属性名记录上下文@5eb5fe8
  2. 修复微服务模式下, 入口文件为 index.js 且未创建服务目录时, 栈溢出问题@ffa212d
  3. Socket.IO 更新至4.4.0

OOX 是什么

基于 Node.JS 实现的,更简单更快速的微服务解决方案,告别路由定义和各种配置文件,和调用本地函数一样调用远程服务,同时当不需要微服务运行时,也可以像传统应用一样单例运行。

服务端口不变同时支持 HTTP / Socket.IO,既能满足一般类 Web 的接口调用需求,又能满足长连接流式数据传输。

示例

 // demo/index.js const calculator = require ( './calculator' ) exports.calc = async exp => { const [ arg1, arg2 ] = exp.match ( /\d+/g ) const [ op ] = exp.match(/[\+\-\*\/]/g) const returns = await calculator [ op ] ( +arg1, +arg2 ) return `${arg1}${op}${arg2}=${returns}` } // demo/calculator.js module.exports = { '+': ( a, b ) => a + b, '-': ( a, b ) => a - b, '*': ( a, b ) => a * b, '/': ( a, b ) => a / b, }

单例运行

 oox index.js port=8001

微服务运行

 # 8001端口运行 index 服务 oox group=demo demo/index.js port=8001 # 随机端口运行 culator 服务, 并在主服务注册 oox group=demo demo/calculator.js registry=:8001

访问

 # httpie 为例 http :8001 action=calc params='3*5'
原文链接:https://www.oschina.net/news/173905/oox-0-2-0-released
关注公众号

低调大师中文资讯倾力打造互联网数据资讯、行业资源、电子商务、移动互联网、网络营销平台。

持续更新报道IT业界、互联网、市场资讯、驱动更新,是最及时权威的产业资讯及硬件资讯报道平台。

转载内容版权归作者及来源网站所有,本站原创内容转载请注明来源。

文章评论

共有0条评论来说两句吧...

文章二维码

扫描即可查看该文章

点击排行

推荐阅读

最新文章