NMathur
NMathur

Reputation: 829

How to implement signalR to two projects connected through backend service

Developing a messaging application for web and mobile with real-time notification. Project flow is ..

I need to send messages from the server to a user that can be connected from more than one location (web and mobile app).

Web and API works separately and access Backend. Please share suggestions what flow should I use to implement singalR in my project

Upvotes: 2

Views: 2480

Answers (2)

xleon
xleon

Reputation: 6375

There is nothing really special in what you want to achieve. Your client app needs to be authenticated before sending SignalR messages. That way you can identify a user and protect your server resources. That´s the first part I would start looking into (there are tons of info about this matter if you google it).

Then you need to send a message from the server to a user and that user can have 2 client apps connected (web and mobile or even more, like other browser tabs). That can be achieved using SignalR groups. A SignalR group is just a group of connections (not users) with a given name. One common scenario is creating a group for each user, and that group will hold the connections of the user. This is a logical pseudo structure of how SignalR groups work (not actual code):

Group name: "johnUser"
Group connections: [
    00001, // mobile app connection
    00002, // brower tab connection
    00003, // broswer tab connection 2
    0000n // etc
] 

Those numbers are simulations of Connection ids. SignalR creates them for you. Then you just need to send a message to the group, and all connected clients will get it.

If you are just starting with SignalR I would not complicate things implenting a backpane unless you really need it and you know what you are doing. A single server can handle hundreds of concurrent connections and you can scale-out later if you want.

Regarding architecture, it´s not very clear what you mean by Web and API works separately. It´s better if you ask more specific questions after you actually try to code something.

Upvotes: 2

Big Daddy
Big Daddy

Reputation: 5234

This is a broad question, but I'll give enough to get you started in the right direction. Since you're going to be in load-balanced environment, you'll need to implement a backplane. This sits behind your web servers and aggregates the messaging. Here are some links that will guide you set up SignalR:

Also, you'll need these nuget packages (minimum):

  • Microsoft.AspNet.SignalR.Redis or SqlServer
  • Microsoft.AspNet.SignalR
  • Microsoft.Owin

Upvotes: 3

Related Questions