On the server side, I use Spring 4. On the browser side, I use Ember.js.
My application has entity classes such as Person
and Product
. These entities are in use both on the server and browser, and are modeled identically. For example:
//this is on the server side
public interface Person {
String getId();
String getFirstName();
void setFirstName(String firstName);
String getLastName();
void setLastName(String lastName);
}
//this is on the browser side, modeled with Ember Data
App.Person = DS.Model.extend({
// id: DS.attr("string"), //property 'id' will be provided by Ember automatically
firstName: DS.attr("string"),
lastName: DS.attr("string")
});
I have the requirement to keep entities in sync between the server and the browser. So for example, when a Person
's firstName
property changes on the server side, this change shall be pushed to all interested browsers in real time.
I investigated Spring's WebSocket support, and after getting comfortable with Spring's "Hello WebSocket" example, I got convinced that using this technology is the right approach for my requirement.
As WebSocket/STOMP is quite low-level, I am in search for a solution that builds on top of this technology and provides observer pattern-like behavior between the browser (role of entities here would be observer) and the server (role of entities here would be subject/observable).
As I couldn't find an existing solution to this "keeping-entities-in-sync" challenge (neither a solution within Spring nor some third-party library), I want to build my own solution, yet the design already poses interesting questions, such as:
- What should the protocol look like? Once a change happened, should the server send a minimal frame, only including the entity type and its ID? (e.g. once any property of a
Person
with ID "3" changes, then send{"type": "Person", "id": "3"}
to all interested clients) - Are there real-life limitations on the number of entities that can be subscribed to? During a session, a single browser may come in contact with hundreds of
Product
s.
I am interested in hearing which solutions have proven to successfully keep a Spring-based server's entities in sync with a JavaScript client's proxy entities (not necessarily Ember.js).