linux-china / spring-boot-rsocket-demo

Spring Boot RSocket Demo with RPC style
41 stars 9 forks source link
react rsocket spring-boot websocket

Spring Boot RSocket Demo

Spring Boot RSocket communication with RPC(interface) style.

How it works?

public interface AccountService {

    Mono<Account> findById(Integer id);

    Flux<Account> findAll();

}
@Service
@Controller
@MessageMapping("org.mvnsearch.account.AccountService")
public class AccountServiceImpl implements AccountService {
    @Override
    @MessageMapping("findById")
    public Mono<Account> findById(Integer id) {
        return Mono.just(new Account(id, "nick:" + id));
    }

    @Override
    @MessageMapping("findAll")
    public Flux<Account> findAll() {
        return Flux.just(new Account(1, "Jackie"), new Account(2, "Tom"));
    }
}
@Configuration
public class RSocketConfiguration {

    @Bean
    public RSocketRequester rsocketRequester(RSocketStrategies strategies) {
        return RSocketRequester.builder()
                .dataMimeType(MimeTypeUtils.APPLICATION_JSON)
                .rsocketStrategies(strategies)
                .connectWebSocket(URI.create("ws://127.0.0.1:8088/rsocket")).block();
    }

    @Bean
    public AccountService accountService(RSocketRequester rsocketRequester) {
        return RSocketRemoteServiceBuilder.client(rsocketRequester, AccountService.class).build();
    }
}

Browser support

Please refer rsocket-react-demo for RSocket and React integration.

Development

Requirements

Maven Modules

RSocket acceptor & handler registry

References