-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhttp.js
61 lines (56 loc) · 1.84 KB
/
http.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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
var connect = require("connect");
var connectRoute = require('connect-route');
var http =require("http");
var bodyParser = require('body-parser');
var cluster =require('cluster');
var csvClient = require('./model/csv');
var tools = require('./model/tool');
var app = connect()
.use(bodyParser())
.use(connect.query())
.use(connectRoute(function (route) {
route.get("/",function(req,res){
res.end("welcome")
});
route.get("/log/:topic",function(req,res){
var args = {};
if (req.method == "POST") {
args = req.body;
} else {
args = qs.parse(req._parsedUrl.query);
}
if (tools.isEmptyObject(args) || !args.accessToken) {
//next(new Error("参数无效"));
}
var token = args.accessToken,topic =req.params.topic
csvClient.regroupData(token, args, topic ).then(function (data) {
// kafkaClient.sendMessages(req.params.topic, args.accessToken, data).fail(function (err) {
// console.error(err.message)
// });
// kafka2.send(topic,token,data).then(function(data){
// console.log(data);
// },function(err){
// console.error(err.message);
// });
console.log(data);
}, function (err) {
console.error(err.message);
});
res.end();
});
}));
if(cluster.isMaster){
var cpus = require('os').cpus().length;
for(var i=0;i<cpus;i++){
cluster.fork();
}
cluster.on('exit', function(worker, code, signal) {
console.log('worker ' + worker.process.pid + ' died');
cluster.fork();
});
}else {
http.createServer(app).listen(8080);
}
//http.createServer(app).listen(8080,function(){
// console.log("ok")
//});