1

I am using CQRS with EventSourcing. I have to use SignalR for updating grid when particular event raised in all opened browsers. So, I have to push data to all clients once Particular event raised.

Currently when user manually refresh page the query is fired which is pulling the data, but I have to pull data without manual refresh using SignalR. I am new to SignalR, Can I get any sample code/reference for implementing the same?

2 Answers2

4

You could read this article about this topic.

There is also a public repository with some "basic experimentations" with CQRS+ES and SignalR.

Hope this helps

wilver
  • 2,106
  • 1
  • 19
  • 26
  • I have gone through solution you provided, but when we are changing the ChangeDescription its not reflecting all opened browser which is expected via signalr –  Nov 19 '15 at 12:26
  • you're right, but it was a bug in DTO mapping, nothing to do with signalR. [Now it's fixed](https://github.com/williamverdolini/CQRS-ES-Todos/commit/88af7a93cb8a471649f323282fbc46e0bca7115b). Thank you – wilver Nov 19 '15 at 12:54
  • sure. I've not managed that event (it's a sample app), but you can see in the console.log that the event is broadcasted to all connected clients. – wilver Nov 19 '15 at 14:42
  • It would be very grateful if you update the solutions or tell me steps So that all event is broadcasted and all values on all the browsers are updated accordingly. I have tried using this in my existing project but I am facing below exception "[HttpException]: The controller for path '/signalr/hubs' was not found or does not implement IController. " –  Nov 20 '15 at 16:49
  • it seems that you miss [owin package](http://stackoverflow.com/a/26751425/3316654). SignalR is realized as OWIN module, so you need it to startup SignalR correctly – wilver Nov 20 '15 at 17:08
  • Anyway. The solution is update and the events are broadcasted to all clients, but not all the angular.js events fired are managed: some are [logged in console](https://github.com/williamverdolini/CQRS-ES-Todos/blob/master/Web.UI/Scripts/app/application.js#L181), some [are managed](https://github.com/williamverdolini/CQRS-ES-Todos/blob/master/Web.UI/Scripts/app/application.js#L364) – wilver Nov 20 '15 at 17:21
  • in new solution I am getting below error "Type specified in JSON 'AddedNewToDoItemEvent|1' was not resolved. Path '[0].Body.$type', line 1, position 56." –  Nov 21 '15 at 07:04
  • This error is about event deserialization, described at the and of [this article](http://williamverdolini.github.io/2014/10/21/cqrses-neventstore-event-upconversion/). Be sure to have all libraries in your project (Newtonsoft.Json, in this case). Anyway, I tried to clone my own repo, set Web.UI as start project in VS (**this makes VS to download and build the solution correctly**), create the db and all works fine. – wilver Nov 21 '15 at 10:23
  • I have deleted db and then created new db, now its working fine, @wilver if possible could you please name the events which are getting broadcasted to all clients, I haved checked but could not find any data updated in both connected clients, Am I missing anything? I have kept 2 instances of browser opened and updated description of ToDo list and it is not getting updated in another opened browser. –  Nov 21 '15 at 11:23
  • As said before some of the signalR notifications were not managed in angular.js sample application (just logged). Anyway, now I've added [some simple notification listeners in the angular app](https://github.com/williamverdolini/CQRS-ES-Todos/commit/b3256ec9a42f97a648c25453440b6cf39a7cca53), in order to manage all the events. So update the solution to the last commit and you'll see that If you start the application and open different instances of browser, every change in one instance will be propagated to all the others – wilver Nov 21 '15 at 14:19
0

First, you must create a Hub class so clients can connect to.

Then, in your event handler you do:

var hubContext = GlobalHost.ConnectionManager.GetHubContext<YourHub>(); hubContext.Clients.All.callJavaScriptFunction(parameters);

This way, when the event handler gets executed, SignalR will call the client methods you want with the data you provide.

You must also create the proper connection from the client and define callJavaScriptFunction.

Note: If you are using dependency injection, you might see very unstable behavior from GlobalHost. Let me know if it is the case.

Hope this helps!

Best of luck!

radu-matei
  • 3,469
  • 1
  • 29
  • 47