-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
33 lines (28 loc) · 1020 Bytes
/
server.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
//super simple rpc server example
var amqp = require('amqp'), util = require('util');
var mongoURL = "mongodb://cmpeUser:[email protected]:10187/amazonDB";
var loginService = require('./services/login');
var mysql = require("./helper/mysql");
var mongo = require("./helper/mongodb");
var cnn = amqp.createConnection({host:'127.0.0.1'});
function publishQueue(conn,m,response){
conn.publish(m.replyTo, response, {
contentType:'application/json',
contentEncoding:'utf-8',
correlationId:m.correlationId
});
}
cnn.on('ready', function(){
console.log("listening on login_queue");
cnn.queue('login_queue', function(q){
q.subscribe(function(message, headers, deliveryInfo, m){
util.log(util.format( deliveryInfo.routingKey, message));
util.log("Message: "+JSON.stringify(message));
util.log("DeliveryInfo: "+JSON.stringify(deliveryInfo));
loginService.handle_request(message, function(err,res){
//return index sent
publishQueue(cnn,m,res);
});
});
});
});