SignalR combined with Breeze
Asked Answered
F

2

9

I have a project that i right now have set up with BreezeJS. Not knowing what goes on inside BreezeJS to the full scope, but just accepted that it works, i have my items shown on screen basically from this simple command.

export function getProjects(projectsObservable, errorObservable)
{
return breeze.EntityQuery.from("Projects")
       .using(manager).execute()...then/fail.
}

I now want to make it responsiveness to users that edit the same items with signalR. This means i at this point have callbacks being fired on javascript end saying that object with guid = xxxxxxx has changed(guid is the key).

How can i tap into Breeze updating the item without it query the server again, nor sees it as an update that needs to be send back to the server. Remmeber that i just got the update from signal r.

Should i have taken another path in the first place, is there a reason to create a WebApi if i could just could have returned the data from the signalR hub at the beginning? Would it be easy to set this up with Breeze instead of the WebApi ?

Fellah answered 16/4, 2013 at 11:3 Comment(0)
E
14

We at IdeaBlade are looking forward to providing good guidance on Breeze apps working with SignalR.

My current thinking is that SignalR is appropriate for notifying the client of changes to data of interest but I would not deliver the changed data to the client with SignalR. I let the client decide whether (or not ... or when) to get the changed data from the server.

My reasoning is based on the view that SignalR should be a fast, lightweight mechanism for notification, not a fire hose spraying vast quantities of data at subscribing clients who may or may not be ready (or willing) to cope with a huge volume of change data forced upon them.

Perhaps you can elaborate on why you think differently. I'm certainly open to an alternative perspective.

Expand answered 17/4, 2013 at 6:28 Comment(3)
Firstly, it would be simplicity and fast developement. Just hook it up from signalr to push data. But you are absolutly right, that it might be better to let the client decide when to get the actual data. I will think a little more about it and if i change my mind that my first idea is better than yours then i will let you know :)Coldiron
I have to say with the rise of CQRS this view is not the sole correct view. If I'm issueing get commands to my server which eventually sends me events/or full read models then signalr is a great async event and object delivery mechanism.Garik
Actually this would be a great feature for the same reason breeze changesets is - minimizing the number of roudrips to the server. If you only use signalr for notifications (which isnt free either) you'd still need to fetch all the changed objects your client interested in via the web api/odata and in nontrivial cases it would require either several requests or a dedicated method to fetch the changes in one go which in turn cannot be flexible/generic. my point is - it would be nice to have a way to (optionally) propagate changesets not only to the server, but to subscribed clients as well.Loppy
R
4

I totally agree with Ward Bell

If you wonder how to do it: for example in an angular Application , you could subscribe to breeze entity tracking mechanism like this

enter image description here

Then you could setup a SignlarR Hub someplace else to transmit those changes to all clients

However possible thanks to the power of breeze.js, I would not recommend it, because as Ward pointed out : “that will be a fire hose spraying vast quantities of data at subscribing clients” . Just think for a moment, and consider your application will have hmmm let’s say 30 concurrent users doing transactions , imagine all the Network traffic that will be creating. That will be bad software architecture.

The only reason you may consider doing this is if you need to update a dashboard that feeds from live data, but still you need to be extra concision,mindful, aware, cognizant of the data traffic and server utilization .

    function setupEventForHasChangesChanged() {
        EntityManager.hasChangesChanged.subscribe(function (eventArgs) {
            $rootScope.$emit('dataservice.hasChangesChanged', eventArgs);
        });
    }

    function setupEventForEntitiesChanged() {
        EntityManager.entityChanged.subscribe(function (changeArgs) {
            if (changeArgs.entityAction === breeze.EntityAction.PropertyChange) {
                $rootScope.$emit('dataservice.entitiesChanged', changeArgs);
            }
        });
    }
Robertoroberts answered 4/8, 2014 at 16:47 Comment(1)
Do not post screenshots of code. Post the code as text.Morphophoneme

© 2022 - 2024 — McMap. All rights reserved.