Permalink
Browse files

What about subscriptions

  • Loading branch information...
robjoh committed Aug 17, 2014
1 parent ae2a144 commit 6a41227305bc20e6ba836b889b3bb09eb91a14b9
Showing with 46 additions and 11 deletions.
  1. +46 −11 server.js
View
@@ -8,26 +8,61 @@ var namespace = 'azure-service-bus-nodejs',
var client = azure.createServiceBusService(namespace, accessKey);
var server = http.createServer(function(httpReq, httpResp) {
client.listTopics(function(error, result, response) {
if (httpReq.url === '/') {
getTopics(writeResult);
} else {
getSubscriptions(httpReq.url.slice(1), writeResult);
}
function getTopics(callback) {
client.listTopics(function(error, result, response) {
if (error) {
callback(error)
return;
}
var topics = result.map(function(topic) {
return {
name: topic.TopicName,
totalSubscriptions: topic.SubscriptionCount,
totalSize: topic.SizeInBytes
};
});
callback(null, topics);
});
}
function getSubscriptions(topic, callback) {
client.listSubscriptions(topic, function(error, result, response) {
if (error) {
callback(error);
return;
}
var subscriptions = result.map(function(subscription) {
return {
name: subscription.SubscriptionName,
totalMessages: subscription.MessageCount
};
});
callback(null, subscriptions);
});
}
function writeResult(error, result) {
if (error) {
httpResp.writeHead(500, {'Content-Type': 'application/json'});
httpResp.write(JSON.stringify(error, null, 3));
httpResp.end();
return;
}
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.write(JSON.stringify(result, null, 3));
httpResp.end();
});
}
});
server.listen(8080);

0 comments on commit 6a41227

Please sign in to comment.