gpt4 book ai didi

spring-webflux - WebFlux + RSocket + Spring

转载 作者:行者123 更新时间:2023-12-03 16:22:07 26 4
gpt4 key购买 nike

有人可以告诉我或使用 提供现成的 CRUD 示例吗? WebFlux、RScoket 和 Spring(或 SpringBoot) ?

我研究了 RSocket 文档, WebFlux ,也写了我的简单例子,不过我想看一个真实的 CRUD 使用 的基本方法的应用程序RSocket .

我将不胜感激。
谢谢。

最佳答案

我一直维护a Spring/RSocket sample project with 4 basic interaction modes of RSocket .

如果您只需要简单 CRUD 操作的请求/回复案例,请查看 请求和响应 模式,然后选择传输协议(protocol) 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 Boot应用,可以使用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 协议(protocol)暴露的服务,客户端可以是 rsocket-js 项目或其他语言和框架,如 Angular、React 或 Android 等。

更新:我添加了一个 crud sample在我的 rsocket 示例代码中 ,我已经发表了 a post on Medium .

关于spring-webflux - WebFlux + RSocket + Spring ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60398299/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com