egg-call-context

1.0.0 • Public • Published

egg-call-context 跨进程上下文调用

为解决多进程模式下,无法在其他进程调用长连接上下文(限单服务应用)

  1. 基于 messenger 进程间通信,无任何依赖
  2. 消息由 agent 进程中转到对应的 woker 进程执行调用,响应结果直接返回到请求进程
  3. 执行进程意外退出自动销毁

场景

向客户端长连接请求发送消息,并获取消息处理结果

安装

npm install @chandre/egg-call-context
// config/plugin.js
exports.callContext = {
    enable: true,
    package: '@chandre/egg-call-context'
}

使用

// app/controller/home.js

class HomeController extends Controller {

    
    async connect() {
        const { ctx } = this;

        // 创建
        ctx.callContext.create('serviceName', {
            echo(a, b) {
                // 销毁
                ctx.callContext.destroy('serviceName');
                return a+b;
            }
        })

        

    }


    async echo() {
        const { ctx } = this;
        // 调用serviceName的echo方法,超时(15000ms)
        ctx.callContext.requrest('serviceName', 15000).echo(1,2).then(res => {
            console.log(res) // 3
        }).catch(err => {
            consoel.log(err.message);
        })
    }

}

Package Sidebar

Install

npm i egg-call-context

Weekly Downloads

1

Version

1.0.0

License

MIT

Unpacked Size

4.02 kB

Total Files

6

Last publish

Collaborators

  • chandre