eggjs / egg

🥚 Born to build better enterprise frameworks and apps with Node.js & Koa
https://eggjs.org
MIT License
18.9k stars 1.82k forks source link

APP启动时可以启动一个socket server吗? #521

Closed ghost closed 7 years ago

ghost commented 7 years ago

我想在APP启动时开启自己写的socket服务,用来接收ISO-8583报文。用nodejs自带的net模块实现的。这样可以吗?

dead-horse commented 7 years ago
// app.js

const server = require('./server');

module.exports = app => {
  server.start();
  // 如果保证 server 启动之后再启动 egg 应用
  app.beforeStart(function*() {
    server.start();
  });
}
atian25 commented 7 years ago

要注意,agent 进程是唯一的,挂掉后不会重启,要确保错误处理。

相关 issue: https://github.com/eggjs/egg/issues/269

dead-horse commented 7 years ago

还是放 app 上吧

atian25 commented 7 years ago

@dead-horse 放 app 的话,你那段示例是会启动多个的了

dead-horse commented 7 years ago

启动多个也没问题,和 http server 一样

fengmk2 commented 7 years ago

@atian25 cluster 模块的精粹你还不够熟悉啊

atian25 commented 7 years ago

@fengmk2 回去补补课 T_T

ghost commented 7 years ago

Thanks

acodercat commented 7 years ago

楼主最后怎么解决的呢