Skip to content

40CoderPlus/rsocket-exchange-spring-boot

Repository files navigation

RSocket Exchange Auto Create Proxy Service

Add annotation @RSocketClient for @RScoketExchange.

Add annotation @EnableRSocketClients for init beans with annotation @RSocketClient.

Requirements

  • Spring Framework 6/Spring Boot 3
  • Java 17+

How to use

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);
}

Limit

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:

Releases

No releases published

Packages

No packages published

Languages