Posts

Showing posts from December, 2012

Schedule your Azure Mobile Service Pinger - Part 2

This is a continuation of  my previous blog. As an update to the Scheduler script I have incorporated the script with the Email and  sms module. I have used Sendgrid to send the email and Smslane to send the sms.

The scenario is whenever the url or web service is down a sms and an email will be sent to the administrator.

Following is the script

function Pinger() {

    //Import the modules that you will require to perform this request

    var req = require('request');
    var util = require('util');
    var sql;
    var responseStatus;
    var time = new Date();
    var SendGrid = require('sendgrid').SendGrid;

    //Send request to the url which you want to monitor. Note this is a get request
    req.get({
    uri:"http://www.microsoft.com/",
    headers:{'content-type': 'application/x-www-form-urlencoded'},      
   },

   //Write the callback module for the same
   function (error, response, body) {
   if (!error && response.statusCode == …

Schedule your Azure Mobile Service Pinger

Image
This is a continuation of my previous blog Create your own monitor with AMS. In my previous blog I had mentioned how we can create an URL ping monitor using Node.JS nodes in AMS. However there was something missing!
For any URL or service monitoring it does not make any sense until and unless it is scheduled. The actual flow should be a background task which will be scheduled after a specific time interval and execute the business logic which will do the pinging request. This was a little bit difficult until few days ago, when the Azure Mobile service team released Scheduler service.
Scheduler scripts were used to
1.Support background processing
2.Prune unnecessary data
3.Send push notification after an interval
Etc.
To explore this more I started integrating the Ping script
Step1: Go to your azure management portal -> Click on your Mobile Service.

Step 2: Double click on the service and click on the scheduler tab

Step 3: On clicking “Create a scheduled job” you will be asked about the Jo…

Create your own freaky chat server in 10 minutes :)

Image
This blog is how Node.JS helps to make a chat server in just 10 min time span. When this code first worked out at my end I felt awesome as in my past experience creating a chat server was cumbersome. The algorithm for creating a chat server is simple
1.Create a socket array which will contain all the sockets
2.Each socket represent an user who wants to chat
3.Server should open a port for listening
4.Each socket chat message data to this port
5.Once the data is received it is broadcasted to all the existing socket in the socket array.
Server side script
//Require net module for create socket connection
var net = require('net');
//Initialize the Socket array which will hold the current logged in used socket
var sockets = [];
var s = net.Server( function(socket) {
//Whenever there is a data sent from any user, the data will be pushed to all the existing socket connections
sockets.push (socket);
socket.on('data', function(d){
for(var i=0;i<sockets.length; i++)
{
sockets[i].write(d);
}
}…

Unseeing possibilities through Node.JS

Image
What is Node.JS?
Node.JS is a server side event driven I/O to build fast, scalable network applications. To know more about Node.JS you can get more information at http://en.wikipedia.org/wiki/Nodejs . In this blog I am more focused to talk on the practical done by me.
Node.Js is all about:
1.Asynchronous I/O Framework
2.Core in C++ on top of V8
3.Rest of it in Javascript
4.Can handle thousands of concurrent connections with minimal overhead (CPU/Memory) on a single process
5.Works upon v8 which is a potent platform developed by Google in C language. Node.JS sits above V8 and uses the APIs of V8
Once you download the Visual SDK toolkit for Node.JS you can verify the same with node command. Following sample shows how to write a simple addition and multiplication function and call them

Similarly you tend to do some management related operations like monitoring the event Eventemitters by calling the process command.
Let’s start with some real world application, like pinging a URL and getting it…
Image
Create your own URL monitor with AMS
In this blog I will discuss about the important role of Node.JS module(request) in Azure Mobile Service. I will like to take an example and explain how easily a simple URL monitoring application which took a lot of effort earlier was coded in just few hours.
The new Azure Mobile service provides the developers some standard node.js modules that can help them to code for CRUD related transactions. Richard Astbury has written a wonderful blog mentioning those standard modules. In addition to these standard modules some new modules that have been added recently are as follows:
·SendGrid
·Azure
·Request
We will be talking about the request module which has been recently added as a supported module to Azure mobile service. Let me start with the problem statement that was the origin of such an app. Situation
·I have 5 web service hosted by my application. I want to verify their status right now. I want a one click solution for the same
·I want to monitor whether…