Server to Phonegap push: SignalR vs Azure Notifica

2019-03-15 13:18发布

Well, I'm in a kind of a dilemma to go on with my Phonegap application development: for real time event notification, should I go with Azure Notification Hub or SignalR?

For my understanding, SignalR is good for real time web applications through the use of Web Sockets. Whereas notification hub makes it easy to send push notifications across multiple platforms. To make it easy to respond, let me explain the structure that I currently have and what my app is supposed to do.

The App: It's basically an app where users can create groups and invite other users. The user can also make a group "online" so other users can "enter" the group. While the group is online and the user have entered , they can send questions, exchange messages and so forth.

The need: When a user ask a question in a group, or enter/leave a group, the other users needs to see the new user in the app screen. I could do a polling on the server to check that and update the UI according, but this is something the modern days don't allow. My searches on the subject lead me to two things: SignalR and NotificationHub.

The current architecture: Client -> PhoneGap application with backbone.js. Backend -> Asp.NET Web API with Entity Framework and Azure Sql Server.

I've already put some thinking in the use of notification hubs and tags for that. For example, when a user enter an online group, it sends a request to the server to register a "grouplisten:{groupId}" tag. The server then registers the tag with the user's device and also fires a notification to all other devices with the tag "grouplisten:{groupId}", so the other users update the UI with the recently joined user. Also when the user leaves the group, it sends a request to the server to remove the "grouplisten:{groupId}" tag and also notifiy the devices with "grouplisten:{groupId}". But with this simple example, looks like this can become unmanageable.

1条回答
▲ chillily
2楼-- · 2019-03-15 13:48

Both technologies have their pros and cons on mobile platforms:

SignalR

Pros:

  • Well suited for real-time delivery where time or receiving notifications from the server is important.
  • Web clients are supported by all major browsers, IE8+, FireFox, Chrome, Safari and Android WebView, iOS Safari, IE mobile, so they are working well.
  • Solution could be written in JS, without need for the knowing

Cons:

  • Required dedicated server, but possible hosting with shared hosting probably, since not performance hungry.
  • In Cordova particularly requires manual connection management for better user experience, instead of relying on the re-connection mechanism which SignalR provides (This is required for iOS which could drop network connection for battery preserving, on Android not an issue so far).
  • It has a known issue with Safari on iOS (which needs to run with long polling configuration, you can find more on that issue here) which - on real world scenarios with frequent ajax requests - forces you to use a different IP address for the SignalR Server for a seamless experience on iOS.

Azure Notification Hub

Pros:

  • Use existing infrastructure of Google, Apple and MS to deliver notifications to the user and each of them not guarantee immediate delivery of the notifications. You have to read each platforms separately:
  • No need for the dedicated server

Cons:

  • No guarantee for the immediate deleivery.
  • Required working with each native platform's languages. (There excellent plugin for Cordova https://github.com/sgrebnov/cordova-plugin-azure-notificationhub, but it is does not allow receiving notifications when application paused on Android and don't have 64 bit build on iOS)
查看更多
登录 后发表回答