Permalink
Browse files

Make it a web service

  • Loading branch information...
robjoh committed Aug 17, 2014
1 parent 32e5624 commit ae2a14404ed51d0beb73a068685d512e6442b3ae
Showing with 27 additions and 8 deletions.
  1. +27 −8 server.js
View
@@ -1,17 +1,36 @@
"use strict"
var namespace = 'azure-service-bus-nodejs',
accessKey = '[Access key for this namespace]',
azure = require('azure');
accessKey = '[Access key for this namespace]',
azure = require('azure'),
http = require('http');
var client = azure.createServiceBusService(namespace, accessKey);
client.listTopics(function(error, result, response) {
if (error) {
console.log(error);
return;
}
var server = http.createServer(function(httpReq, httpResp) {
client.listTopics(function(error, result, response) {
if (error) {
httpResp.writeHead(500, {'Content-Type': 'application/json'});
httpResp.write(JSON.stringify(error, null, 3));
httpResp.end();
return;
}
console.log(JSON.stringify(result, null, 3));
var topics = result.map(function(topic) {
return {
name: topic.TopicName,
totalSubscriptions: topic.SubscriptionCount,
totalSize: topic.SizeInBytes
};
});
httpResp.writeHead(200, {'Content-Type': 'application/json'});
httpResp.write(JSON.stringify(topics, null, 3));
httpResp.end();
});
});
server.listen(8080);

0 comments on commit ae2a144

Please sign in to comment.