spring-projects / spring-projects/spring-data-rest
mixing spring-data-rest with spring websocket implementation [DATAREST-232]
@odrotbohm is already working on this.
Since Dec 31, 2020.
- Dominant language
- Java
- Stars
- 958
- Forks
- 568
- PR merge metrics
- No merged PRs in 30d
Description
Peter Butkovic opened DATAREST-232 and commented
Let me put it in a StackOverflow way (to prevent reformulating my dilemmas to some perfectly designed solution proposal):
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.
It would be nice if spring-data-rest could support websocket annotations "somehow" :) out of the box. Marking my rest exposed methods via anotations (taking care of websocket message routing would be perfect).
Otherwise, there are a two solutions coming to my mind, in fact in both would be:
- spring-data-rest to expose my entities via
REST/HTTP API websocketcontrollers (used for the modification calls on entities)
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 it seems quite sick to me, as I'd be going 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 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 in my implementation only the routes.
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?
Affects: 2.0 M1 (Codd)
Reference URL: https://stackoverflow.com/questions/21278307/mixing-spring-data-rest-with-spring-websocket-implementation
8 votes, 9 watchers
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Assessment
This issue has not been assessed yet.