-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
64 lines (36 loc) · 1.06 KB
/
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
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
62
63
64
var amqp = require('amqplib/callback_api');
var NewsDefenition = require('./defenitions/NewsDefenition');
amqp.connect('amqp://localhost', function(err, conn) {
conn.createChannel(function(err, ch) {
var q = 'rpc_queue';
ch.assertQueue(q, {durable: false});
ch.prefetch(1);
console.log(' [x] Awaiting RPC requests');
ch.consume(q, function reply(msg) {
var n = msg.content.toString();
console.log(n);
try{
req = JSON.parse(n);
console.log(req);
news = new NewsDefenition();
console.log(req.argument);
news.addInTable('{"title": "Title", "content": "Some content", "imgURL":"imgURL"}');
res="text";
console.log(news.getFromTable(req.argument));
}catch(err){
console.log(err);
res='error';
}
ch.sendToQueue(msg.properties.replyTo,
new Buffer(res),
{correlationId: msg.properties.correlationId});
ch.ack(msg);
});
});
});
function fibonacci(n) {
if (n === 0 || n === 1)
return n;
else
return fibonacci(n - 1) + fibonacci(n - 2);
}