Spring Boot RSocket communication with RPC(interface) style.
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();
}
}
Please refer rsocket-react-demo for RSocket and React integration.