spring-projects / spring-framework

Spring Framework
https://spring.io/projects/spring-framework
Apache License 2.0
56.51k stars 38.1k forks source link

RSocket Functional route & Kotlin DSL #23135

Open linux-china opened 5 years ago

linux-china commented 5 years ago

Now functional route is useful feature for Spring WebFlux and SpringMVC, and it's possible to add this feature for RSocket? Functional route is very convenient with functional style, especially for Kotlin, and all are functions and messages/events.

    @Bean
    public RouterFunction locateRoutes() {
        return RouterFunctions
                .route(RPC("findId"), payload -> Mono.just(DefaultPayload.create("hello")))
                .andRoute(FIRE("notifyLogin"), payload -> Mono.empty())
                .andRoute(STREAM("accounts"), payload -> Flux.empty());
    }

Two hard things: MessageMapping and payload data serialization. I like following style, and it's very useful sometimes.

    @MessageMapping("users.{user}.info")
    Mono<ChatUserInfo> getUserInfo(@DestinationVariable String user, Body body) {
        // ...
    }
sdeleuze commented 5 years ago

@rstoyanchev Is RSocketRequester the recommended functional alternative to MessageMapping? If yes, how @MessageMapping("users.{user}.info") and @DestinationVariable would translate? Is there some special configuration to use for enabling composite metadata?

sdeleuze commented 5 years ago

After discussing that with @rstoyanchev, we indeed miss a functional way to define RSocket routes. I think it is a too late for 5.2, but it would perfectly makes sense for 5.3 IMO. This should be implemented in Java with an additional Kotlin DSL like what with did on WebFlux.fn.