How to implement Socket.IO with ASP.Net, IISNode, Node.JS, and SQL Server for event-based push notifications?
Asked Answered
V

2

15

For a notification project, would like to push event notifications out. These are things like login, change in profile, etc., and to be displayed to the appropriate client. I would like to discuss some ideas on putting it together, and get some advice on the best approach.

I noticed here that changes made to a CouchDB can be detected with a _changes stream, picked up by Node, and a process kicks off. I would like to implement something like this (I'm using SQL Server, but an entry point at this level may not be the best solution).

Instead of following the CouchDB example (detecting database-based events, I think this just complicates things, since we're interested in client events), I was thinking that when an event occurs, such as a user login, then a message is sent to the Node server with some event details (RESTful request?). This message is then processed and broadcast to all connected clients; the appropriate client displays notification.

Proposed ecosystem:

  • .Net 4.0
  • IIS
  • IISNode
  • Socket.IO
  • Node.JS
  • SQL Server 2008

This will be built on top of an existing project using the .Net framework (IIS, etc.). Many of the clients' browsers do not support web sockets, so using Socket.IO is a good option (fallback support). However, from what I can see, Socket.IO only still only supports long polling through IISNode (which isn't really a problem).

An option would be to expose the Socket.IO/Node endpoint to all clients, so that client-based notifications can be sent through JS to the Node server, which broadcasts the message. (follows the basic chat-server /client/server examples).

Alternately, an IIS endpoint could be used, but could only support long polling (through Socket.IO). This would offer some additional .Net back-end processing, but may be over-complicating the architecture.

Is there SQL Server-based event notification available for Node?

What would be the best approach?

If I didn't get the terminology ecosystem configuration right, please clarify.

Thanks.

Verbatim answered 5/3, 2012 at 16:49 Comment(0)
P
15

I would recommend you check out SignalR first before considering adding iisnode/node.js to the mix of technologies of your pre-existing ASP.NET application.

Regarding websockets, regardless if you use ASP.NET or node.js (socket.io), you can only use HTTP long polling for low latency notifications, as websockets are not supported by HTTP.SYS/IIS until Windows 8. iisnode does not currently support websockets (even on Windows 8), but such support could be added later.

I did some research lately regarding MSSQL access from node.js. There are a few OSS projects out there, some of them use native, platform-specific extensions, some attempt implementing TDS protocol purely in JavaScript. I am not aware of any that would enable you to access the SQL Notifications functionality. However, the MSSQL team itself is investing in a first class MSSQL driver for node.js, so this is something to keep an eye on going forward (https://github.com/tjanczuk/iisnode/issues/139).

If you plan to use SQL Notifications to support low latency notifications, I would strongly recommend starting with performance benchmarks that simulate the desired level of traffic at the SQL server level. SQL Notifications were meant primarily as a mechanism to help maintain in memory cache consistent with the content of the database, so it may or may not meet the requirements of your notification scenario. At the very minimum these measurements would help you start with a better design.

Prizewinner answered 5/3, 2012 at 17:56 Comment(4)
Thanks Tomasz. You make a very good point about implementing SignalR. However, the issue is that that the project is fragmented between legacy ASP code and .Net code, so I think that for now, Javascript-based communication (not C#) would probably be the best choice. If I am getting the SignalR concept correctly, in the future when the project is completely migrated to .Net, then switch to SiglanR. Are there some good walk-throughs of Node.JS, IISNode, and Socket.IO? Also looked at a few SQL Server options, but overkill for this app.Verbatim
Correction: Implement a SignalR approach in .Net 4.0 as a WCF service that can be consumed by the classic ASP code. Solved.Verbatim
Tomasz - could you make this limitation clearer in the iisnode docs? I installed iisnode and nodejs on my Windows box with main goal of using the websocket support - so I looks like my choices are using nginx or apache on Windows, or moving to Linux.Upstate
user123067 - why not just use node.exe without a webserver?Xerosis
S
2

I would highly recommend using Pusher. That is what we use and it makes it easy to implement as it is a hosted solution. So plugging it and making it work is really easy. It doesn't cost much unless you are going to push a crazy amount of messages through it on a massive scale.

Skeg answered 30/8, 2012 at 2:50 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.