egg SingleMode

zvms9eto  于 5个月前  发布在  其他
关注(0)|答案(7)|浏览(48)

I asked this question before
#3262
#4183

It is too complicated for me!!

How can I run eggjs in single mode and create an anonymous context?
I want to Run eggjs as library
I create a complex RESTful web service by eggjs , it have many services and plugins
I want to create workers (some js scripts) for my messaging queue (rabbitmq) and I want to reuse services and plugins , so I need to access to ctx object

const runWorker = ()=>{
    // some code here

   //here I need eggjs service
  const configs = {
      baseDir : 'mainAppDir'
  };
  
  const egg= //Create a single mode eggjs instance
  const ctx = egg.createAnonymousContext();

}
sr4lhrrt

sr4lhrrt1#

@sm2017 try this:

const { Application, Agent } = require('egg');

const agent = new Agent(options);
await agent.ready();

const app = new Application(options);
await app.ready();

app.agent = agent;
agent.application = app;

that is the mini init work at egg-cluster or egg-mock

but you need to start HTTP server yourself and handler gracefull exit.

we will provide a createInstance to do this at egg 3.0 later this year.

nkoocmlb

nkoocmlb2#

@atian25 I must enable all plugins too
How you pass single mode in options?

Also I don't need Agent must I create an instance of agent?

xhv8bpkk

xhv8bpkk3#

@atian25 I run your code in a fresh installed simple mode eggjs

2020-05-17 10:36:22,279 WARN 3912 [egg:core:ready_timeout] 10 seconds later node_modules\egg-watcher\lib\init.js:15:14 was still unable to finish.
2admgd59

2admgd594#

const { Application } = require('egg');
const app = new Application(options);
await app.ready();

but some plugin required Agent, so maybe you could disable the plugin.

since this way is more like a hacky, so I can't promise everything will work fine.

6rqinv9w

6rqinv9w5#

@atian25 I run your code in a fresh installed simple mode eggjs

2020-05-17 10:36:22,279 WARN 3912 [egg:core:ready_timeout] 10 seconds later node_modules\egg-watcher\lib\init.js:15:14 was still unable to finish.

What about this error?

a14dhokn

a14dhokn6#

@atian25 reply please

83qze16e

83qze16e7#

@atian25 just to remove inactive tag

相关问题