I'd like to synchronize the state to all the clients interested in particular entity changes. So I'd like to achieve something like:
- exposing CRUD API on entity (via
HTTP/RESTandwebsockets) - and routing the response (of the modifying calls) to
websocketstopic
So technically, I'd be interested in ideas to mix spring-data-rest with spring websockets implementation to achieve something like spring-data-websocket.
There are a two solutions coming to my mind, and in fact both would be:
- spring-data-rest to expose my entities via
REST/HTTP API websocketcontrollers (used for the modification calls on entities)
The websocket controllers would look like this:
@Controller public class EntityAWebSocketController { @MessageMapping("/EntityA/update") @SendTo("/topic/EntityA/update") public EntityA update(EntityA entityA) throws Exception { // persist,.... return entityA; } } Scenario 1: Websocket API called from REST/HTTP API
Rules:
- client request is always
REST/HTTP API - response is
REST/HTTP APIfor all the operations - moreover for modifying operations the
websocketmessage comes as well
Technically, could be achieved, by:
- calling the
websocketcontrollers from the spring-rest-data events (namely in theAfterCreateEvent,AfterSaveEvent,AfterLinkSaveEvent,AfterDeleteEvent)
Still the solution seems quite sick to me, as I'd need to go for:
- client A --
HTTPrequest--> Server (spring-data-rest controller) - Server (AfterXXXEvent in the spring-data-rest controller) --
websocketmessage--> Springwebsocketcontroller - Spring websocket controller --
websocketmessage via topic--> all Clients interested in the topic - Server (spring-data-rest controller) --
HTTPresponse--> client A
Scenario 2: Websocket API independent from REST API
Rules:
- client request is
REST/HTTP APIfor non-modifying operations only - response is
REST/HTTP APIfor non-modifying operations only - client sends
websocketmessage for all the modifying operations websocketmessage is sent to client for all the modifying operations only
Well, if no other ideas come up, I'd go for the later one, but still, it would be great if I could have somehow generated C(R)UD methods exposed via websockets as well, something like spring-data-websockets and handle only the routes in my implementation.
As I feel like I'd have to manually expose (via *WebSocketControllers) all the CUD methods for all my entities. And I might be too lazy for that.
Ideas?