14.01.2015 Views

Eric lippert - Amazon Web Services

Eric lippert - Amazon Web Services

Eric lippert - Amazon Web Services

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

var channelTable = tables.getTable(‘ChannelSub’);<br />

channelTable.read({<br />

success: function(channels) {<br />

channels.forEach(function(channel) {<br />

if((channel.acceptBroadcast && channel.myId != item.<br />

myId) ||<br />

(channel.myId==item.toId)){<br />

push.wns.sendToastText04(channel.channel, {<br />

text1: item.myId + ‘: ‘ + item.fakeTweetText +<br />

(item.toId === ‘’ ‘ BROADCAST’: ‘’)<br />

}, {<br />

success: function(pushResponse) {<br />

console.log(“Sent push:”, pushResponse);<br />

}<br />

});<br />

} });<br />

} }); }}<br />

Notification 2: KirkyBoy sees the ‘BROADCAST’ tag and is irked at<br />

‘DVader’ for broadcasting a message and retorts back to DVader<br />

directly.<br />

Here in the sendNotifications method, we are looping through all<br />

the subscribers and sending them a message if the Incoming<br />

request’s ‘toId’ matches (and it’s not the same as the sender) or if<br />

the channel subscribers are subscribed to receive broadcast<br />

messages.<br />

Demo<br />

With the scripts in place, we load this application up on two<br />

machine, a Desktop and a Surface RT. On Desktop we have a user<br />

called DVader and on the Surface we have a user called KirkyBoy.<br />

Both are subscribed to receive broadcast messages.<br />

Notification 1: DVader sends out a Broadcast message asking if<br />

KirkyBoy is around. KirkyBoy receives a toast notification for this<br />

as follows<br />

Nice eh!<br />

Wrapping it up<br />

With that little squabble between our fictitious characters, we<br />

have seen Azure Mobile Service Notifications in full swing. It is<br />

quite amazing how the complex task of co-ordination between<br />

AppServer and WNS as well as registration and security ID were all<br />

handled by Azure Mobile services.<br />

Going forth, be it social media apps or business apps,<br />

implementing Push notifications are really going to be a breeze<br />

and with the cost of one shared SQL Server DB instance, the<br />

amount of plumbing work saved, definitely offsets the expenditure<br />

of developing and maintaining a stable notification system from<br />

ground up<br />

The complete code sample can be downloaded from<br />

bit.ly/dncm6-zutw but you do need to put in our Azure<br />

Mobile Service Application ID.<br />

Sumit is a .NET consultant and has been<br />

working on Microsoft Technologies for the<br />

past 12 years. He edits, he codes and he<br />

manages content when at work. C# is his<br />

first love, but he is often seen flirting with<br />

Java and Objective C. You can Follow him on<br />

twitter @sumitkm and read his articles at bit.ly/KZ8Zxb<br />

80 | DNCmagazine www.dotnetcurry.com

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!