Add annotation @RSocketClient
for @RScoketExchange
.
Add annotation @EnableRSocketClients
for init beans with annotation @RSocketClient
.
- Spring Framework 6/Spring Boot 3
- Java 17+
Annotation interface by @RSocketClient
@RSocketClient
public interface AnswerService {
@RSocketExchange("answer")
Mono<Answer> answer(@Payload Question question);
}
Use AnswerService
to communicate with RSocket Server
@AllArgsConstructor
@RestController
public class QuestionApi {
private AnswerService answerService;
@RequestMapping(path = "/question")
public Mono<Answer> question(@RequestParam(name = "current") int current) {
return answerService.answer(new Question(current));
}
}
More about @RSocketClient
Use you own RSocketServiceProxyFactory
@RSocketClient(proxyFactory = "myProxyFactory")
public interface AnswerService {
@RSocketExchange("answer")
Mono<Answer> answer(@Payload Question question);
}
Use you own RSocketRequester
@RSocketClient(rsocketRequester = "myRSocketRequester")
public interface AnswerService {
@RSocketExchange("answer")
Mono<Answer> answer(@Payload Question question);
}
Current can't auto register @RSocketClient
bean for Server push message to client.
But we can do like this:
AnswerService createServiceForClient(RSocketRequester rsocketRequester) {
return RSocketServiceProxyFactory.builder(rsocketRequester).build()
.createClient(AnswerService.class);
}
See more: