0

I'd like to clear up a couple of points around SignalR. I have an application that reads trades (eg. stock codes that have associated stock prices streaming). The group for this SignalR hub is pitched at the stock code. It has a publisher that is started on startup (to read the streaming data) of the SignalR hub then a client(s) subscribes to certain stock codes. The workflow for this type of hub is fairly well documented.

I have a second hub that searches unrelated (to the above) data that is read from a table. The hub publisher for this hub is not started at hub startup. I have the publisher starting when the subscribe takes place. The subscribe receives the search criteria, creates a group (whose name is basically the search criteria). This type of hub is not overly clear to me. Specifically when and where I should unsubscribe when I enter different search criteria. At the moment I subscribe then receive a message back based on the search. When I enter different search criteria where should I unsubscribe - (a) sourced from the client, or (b) should I simply pass the old criteria with the 'next' search criteria and call the unsubscibe on the server (i.e. unsubscibe one and subscribe to another), or (c) do I need to explicitly unsubscribe ?

Any help would be greatly appreciated

TerrorBight
  • 334
  • 4
  • 23
  • What is not clear to me is, when you subscribe to a search term, do you expect your client to receive multiple answers at different times based on new results made available for the same criteria? I assume so but from your question I'm not sure, because then why would a different search criteria need to clear the previous one? They look to me unrelated searches. – Wasp Aug 11 '15 at 11:43
  • What I'm trying do is UserA subscribes to a hub (passing a value 123) which creates a group called ACCOUNT123 (123 being the account number s/he is searching on). UserB subscribes to the same hub (passing a value 456) which creates a group ACCOUNT456 (456 being the account number s/he is searching on). When there are updates to what ever the search returns for each criteria the results should only get passed back to the relevant user (i.e. if the account name for account number 123 changes the update will get sent to UserA only, as s/he is subscribed to the ACCOUNT123 group) – TerrorBight Aug 11 '15 at 14:57

1 Answers1

0

SignalR is not really designed for pub/sub, there are libraries built ontop of SignalR that solves this, for example my own https://github.com/AndersMalmgren/SignalR.EventAggregatorProxy/wiki

This abstracts away signalr and now you can fire away strongly typed messages as you deem fit in your domain (Backend). The clients can listen to these messages and my library will glue it all together.

My library does not uses SignalR groups instead it has its own library for routing messages to specific clients. https://github.com/AndersMalmgren/SignalR.EventAggregatorProxy/wiki/Implement-constraint-handlers

Blog post

http://andersmalmgren.com/2014/05/27/client-server-event-aggregation-with-signalr/

Anders
  • 17,306
  • 10
  • 76
  • 144
  • 2
    I'm a little surprised you say that. My understanding is SignalR is quite suited to pub/sub (which is just one of its offerings) especially for something a bit complex where calls made by server to client (and vice verca) may add value to the process - the 'everything is a stream' concept seems to be implemented quite nicely with SignalR and RX (http://www.codeproject.com/Articles/851437/SignalR-plus-RX-Streaming-Data-Demo-App-of) – TerrorBight Aug 11 '15 at 14:49
  • Xsockets is more suited for that out of the box, signalr is more of a RPC framework. – Anders Aug 11 '15 at 15:07
  • Thanks Anders - Took your advice regarding not using SignalR for this type of requirement - I could use sockets but for the time being I've used WCF with callback (mostly because I've used it before). Seems to work OK but I'll have a look at XSockets in time as it could be a more robust solution – TerrorBight Sep 12 '15 at 02:15