var http = require('http');
var connect = require('connect');
var url = require('url');

var config = require('./config.js').consumer;
var dataSrv = require('./DataSrv');


var app = connect();

app.use('/', function (req, res) {

        var path = url.parse(req.url);
        var queue_id = path.pathname.slice(1);
        console.log(queue_id);

        dataSrv.pop_notification({id: queue_id}, config.max_messages, function (err, notif_list) {
            if (err) {
                res.writeHead(500, {'content-type':'text/plain'});
                res.write(String(err));
                res.end();
            }
            else {
                message_list = notif_list.map(function(notif){return notif.payload;});
                message_list.reverse();
                res.writeHead(200, {'content-type':'application/json'});
                res.write(JSON.stringify(message_list));
                res.end();
            }
        });
    }
);

app.listen(config.port);

@@ -83,16 +83,45 @@
 'url');%0D
+%0Avar util = require('util');%0D
 %0A%0D%0Avar c
@@ -203,30 +203,817 @@
 );%0D%0A
-%0D%0A%0D%0Avar app = connect(
+var dataSrvBl = require('./DataSrvBlocking');%0D%0A%0D%0A%0D%0Avar app = connect();%0D%0A%0D%0Aapp.use('/block', function (req, res) %7B%0D%0A%0D%0A        var path = url.parse(req.url);%0D%0A        console.log(path);%0D%0A        var queue_id = path.pathname.slice(1);%0D%0A        console.log(queue_id);%0D%0A%0D%0A        dataSrvBl.blocking_pop(queue_id, /*blocking time, config*/ 2, function (err, notif) %7B%0D%0A            if (err) %7B%0D%0A                res.writeHead(500, %7B'content-type':'text/plain'%7D);%0D%0A                res.write(String(err));%0D%0A                res.end();%0D%0A            %7D%0D%0A            else %7B%0D%0A                message = notif && notif%5B1%5D?notif%5B1%5D:null;%0D%0A                res.writeHead(200, %7B'content-type':'application/json'%7D);%0D%0A                res.write(JSON.stringify(message));%0D%0A                res.end();%0D%0A            %7D%0D%0A        %7D);%0D%0A    %7D%0D%0A
 );%0D%0A

add blocking pop