Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/linux-china/spring-boot-rsocket-demo
Spring Boot RSocket Demo with RPC style
https://github.com/linux-china/spring-boot-rsocket-demo
react rsocket spring-boot websocket
Last synced: 9 days ago
JSON representation
Spring Boot RSocket Demo with RPC style
- Host: GitHub
- URL: https://github.com/linux-china/spring-boot-rsocket-demo
- Owner: linux-china
- Created: 2019-04-16T03:01:25.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2023-01-26T08:01:18.000Z (almost 2 years ago)
- Last Synced: 2023-03-10T21:34:25.314Z (over 1 year ago)
- Topics: react, rsocket, spring-boot, websocket
- Language: Java
- Homepage:
- Size: 2.4 MB
- Stars: 41
- Watchers: 4
- Forks: 9
- Open Issues: 33
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
Spring Boot RSocket Demo
========================Spring Boot RSocket communication with RPC(interface) style.
# How it works?
* Create a Reactive service interface alike following
```java
public interface AccountService {Mono findById(Integer id);
Flux findAll();
}
```* On responder side: implement Service Interface and annotate it with @Controller and @MessageMapping to make it exposed as RSocket service.
```java
@Service
@Controller
@MessageMapping("org.mvnsearch.account.AccountService")
public class AccountServiceImpl implements AccountService {
@Override
@MessageMapping("findById")
public Mono findById(Integer id) {
return Mono.just(new Account(id, "nick:" + id));
}@Override
@MessageMapping("findAll")
public Flux findAll() {
return Flux.just(new Account(1, "Jackie"), new Account(2, "Tom"));
}
}
```* On requester side: use RSocketRemoteServiceBuilder to build service call stub bean.
```java
@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](rsocket-react-demo) for RSocket and React integration.
# Development
### Requirements
* Jdk 1.8+
* Spring Boot 2.2.4### Maven Modules
* account-common: Reactive Service API
* rsocket-rpc-spring-boot-starter: Spring Boot Starter to make RSocket call as RPC style
* rsocket-responder: supply RSocket services
* rsocket-requester: consume RSocket services
* rsocket-react-demo: call rsocket service from browser### RSocket acceptor & handler registry
* acceptor: RSocketMessageHandler.createResponder()
* all @MessageMapping methods: rsocketMessageHandler.getHandlerMethods()# References
* Spring RSocket: https://docs.spring.io/spring/docs/5.2.3.RELEASE/spring-framework-reference/web-reactive.html#rsocket
* Spring Boot RSocket: https://docs.spring.io/spring-boot/docs/2.2.4.RELEASE/reference/html/spring-boot-features.html#boot-features-rsocket
* RSocket: http://rsocket.io/