有人能告诉我或者给出一个使用WebFlux、RScoket和Spring (或SpringBoot)现成的CRUD示例吗?
我研究了RSocket文档WebFlux,也编写了简单的示例,但我希望看到使用RSocket的基本方法使用真正的CRUD应用程序。
我会非常感激的。谢谢。
发布于 2020-03-01 15:25:09
我维护了一个具有RSocket四种基本交互模式的Spring/RSocket样例项目。
如果只需要简单CRUD操作的请求/应答情况,请检查请求和响应模式,并选择传输协议TCP或WebSocket。
要实现CRUD操作,只需为它们定义4种不同的路由,比如使用URI定义RESTful API,您必须有一个很好的命名计划,但是在RSocket中没有帮助您区分相同路由的HTTP方法。
例如,在服务器端,我们可以声明一个@Controller来处理这样的消息。
@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) {
}
}在客户端,如果是Spring应用程序,可以使用RSocket RSocketRequester与服务器端进行如下交互。
//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()当然,如果您只是构建由rsocket协议公开的服务,客户端可以是rsocket-js项目或其他语言和框架,如角、React或Android等。
https://stackoverflow.com/questions/60398299
复制相似问题