I have maintained a Spring/RSocket sample project with 4 basic interaction modes of RSocket.
If you only require request/reply case for simple CRUD operations, check the request and response mode, and select a transport protocol, TCP or WebSocket.
To implement CRUD operations, just define 4 different routes for them, like define the RESTful APIs using URI, you have to have a good plan for the naming, but in RSocket there are no HTTP methods to help you to differentiate the same routes.
For example, in the server side, we can declare a @Controller
to handling messages like this.
@Controller
class ProfileController {
@MessageMapping("fetch.profile.{name}")
public Mono<Profile> greet(@DestinationVariable String name) {
}
@MessageMapping("create.profile")
public Mono<Message> greet(@Payload CreateProfileRequest p) {
}
@MessageMapping("update.profile.{name}")
public Mono<Message> greet(@DestinationVariable String name, @Payload UpdateProfileRequest p) {
}
@MessageMapping("delete.profile.{name}")
public Mono<Message> greet(@DestinationVariable String name) {
}
}
In the client side, if it is a Spring Boot application, you can use RSocket RSocketRequester
to interact with the server side like this.
//fetch a profile by name
requester.route("fetch.profile.hantsy").retrieveMono()
//create a new profile
requester.data(new CreateProfileRequest(...)).route("create.profile").retrieveMono()
//update the existing profile
requester.data(new UpdateProfileRequest(...)).route("update.profile.hantsy").retrieveMono()
//delete a profile
requester.route("delete.profile.hantsy").retrieveMono()
Of course, if you just build a service exposed by rsocket protocol, the client can be a rsocket-js project or other languages and frameworks, such as Angular, React or Android etc.
Update: I've added a crud sample in my rsocket sample codes, and I have published a post on Medium.