【问题标题】:WebFlux + RSocket + SpringWebFlux + RSocket + 弹簧
【发布时间】:2020-06-09 09:42:13
【问题描述】:

谁能告诉我或给出一个使用 WebFlux、RScoket 和 Spring(或 SpringBoot) 的现成 CRUD 示例?

我研究了 RSocket 文档,WebFlux,也写了我的简单示例,但我希望看到一个真正的 CRUD 应用程序使用基本使用 RSocket 的方法。

我将不胜感激。 谢谢。

【问题讨论】:

    标签: spring-webflux serversocket reactor rsocket rsocket-java


    【解决方案1】:

    我一直维护a Spring/RSocket sample project with 4 basic interaction modes of 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 Boot应用,可以像这样使用RSocketRSocketRequester与服务端交互。

    //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项目或其他语言和框架,如Angular、React或Android等。

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-08-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-12-22
      • 2019-05-03
      • 2011-09-19
      相关资源
      最近更新 更多