-
Notifications
You must be signed in to change notification settings - Fork 11
/
app.js
47 lines (31 loc) · 1.25 KB
/
app.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
'use strict';
var log4js = require('log4js'),
childProcess = require("child_process"),
logger = log4js.getLogger();
var path = require("path");
var argv = process.argv.slice(2);
if(argv.indexOf('--debug') >= 0){
logger.setLevel('DEBUG');
}else {
logger.setLevel('INFO');
}
if(argv.indexOf('--project') >= 0){
GLOBAL.pjconfig = require(path.join( __dirname , 'project.debug.json'))
}else {
GLOBAL.pjconfig = require(path.join( __dirname ,'project.json'));
}
var mq = require(GLOBAL.pjconfig.mq.module)
, dispatcher = mq.socket('pub')
, acceptor = mq.socket('pull')
, dispatcherPort = GLOBAL.pjconfig.dispatcher.port
, dispatcherAddress = GLOBAL.pjconfig.dispatcher.address
, acceptorPort = GLOBAL.pjconfig.acceptor.port
, acceptorAddress = GLOBAL.pjconfig.acceptor.address;
acceptor[acceptor.bindSync ? 'bindSync' : 'bind']("tcp://" + acceptorAddress + ":" + acceptorPort);
dispatcher[acceptor.bindSync ? 'bindSync' : 'bind']("tcp://" + dispatcherAddress + ":" + dispatcherPort);
var openApiServer = childProcess.fork(__dirname + '/openApiService.js', argv)
acceptor.on("message" , function (data){
logger.debug(data.toString());
dispatcher.send(data);
})
logger.info("start badjs-mq success. ");