Notify different users depending on their category RRS feed

  • Question

  • User716235118 posted
    Hi everyone,

    I'm fairly new to signalR so I might have not understand all of those notions yet.

    Let me explain myself here. I'm trying to write a simple application (only one page, two with authentication) in mvc 4 that has to be evolutive,to monitor messages added to a database. So I have an SQL dependency on each message table. Each messages has an Id, a category and several other columns depending on the message type. That part is already ok for me the database notifies the application and then I have to notify clients using signalR.

    I have several users. When they connect to the application they are assigned to a category (for example : manager, partner, security ...)
    And they can all consult different types of messages (alerts, informations, notes ...) but only one at a time. So I have a lot of combination possibles, manager alerts message, manager information message, ..., partner alert message, partner information message...

    So when a client asks to monitor management alert message he must be notified only if a new management alert message appears in the application.

    So two users connects, one is a manager the other a security member. By default the page displays let's say all the alerts. The manager clicks on a button to display only informations so I make an Ajax call to a controller that handles informations messages,
    I retrieve all of the informations type messages and send them back to the client.
    The other user stays on the alerts page, and new messages start to appear...

    My question is, how to organise signalR to be able to differentiate which messages to send to whom ?

    I'm thinking about creating one hub per category (ManagerHub, PartnerHub, ...) since all hubs use the same connection and in each hub, a group for each message type (Alert, Information...). So when a user connects, I'm looking at his category and the type of
    message he decided to monitor then I add him to the proper group and hub so I can notify him using clients.group("GroupName") on the right hub.

    When he decides to change of message type to monitor, I remove him from the group and add him to a new group...

    That solution could work in theory I guess, but it's not evolutive at all. What if tomorrow I get 3 more message type to handle ? And if there's five more category ? I would have to create five more hubs and handle those three new types of messages in each
    hub... Plus since there is only one page, all hubs are going to be in the page...

    What do you guys think about it ? How can signalR adapts to this segregation of rights ?

    I don't know if I'm clear, this is a pretty long post so if you have any question don't hesitate and thank you for reading.

    Friday, July 10, 2015 8:20 AM


  • User61956409 posted

    Hi Obroken,

    Welcome to ASP.NET forum.

    Firstly, we usually use Groups to send messages to specified subsets of connected clients. You could group the clients by category, then you could call Add or Remove methods to add or remove users from a group dynamically. For more information about SignalR Groups, please refer to this link.

    Secondly, you could also broadcast messages to all connected clients, then you could filter messages from client side based on category.

    Best Regards,

    Fei Han

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Sunday, July 12, 2015 10:54 PM