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/REST
andwebsockets
) - and routing the response (of the modifying calls) to
websockets
topic
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
websocket
controllers (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 API
for all the operations - moreover for modifying operations the
websocket
message comes as well
Technically, could be achieved, by:
- calling the
websocket
controllers 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 --
HTTP
request--> Server (spring-data-rest controller) - Server (AfterXXXEvent in the spring-data-rest controller) --
websocket
message--> Springwebsocket
controller - Spring websocket controller --
websocket
message via topic--> all Clients interested in the topic - Server (spring-data-rest controller) --
HTTP
response--> client A
Scenario 2: Websocket API
independent from REST API
Rules:
- client request is
REST/HTTP API
for non-modifying operations only - response is
REST/HTTP API
for non-modifying operations only - client sends
websocket
message for all the modifying operations websocket
message 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 *WebSocketController
s) all the CUD
methods for all my entities. And I might be too lazy for that.
Ideas?