Reactive JSON RPC 2.0 plugin for the Spring Boot.
This project aims to simplify web exchange via JSON RPC 2.0 protocol in reactive manner. Names of the components and their usage are very similar to JSON-RPC for Java (jsonrpc4j) project (thanks a lot to your work folks, your project is awesome!). The main difference between the projects is that this project is completely reactive, i.e. built on project reactor aka webflux for the Spring Boot.
- Add the following dependency to your pom.xml
<dependency>
<groupId>io.github.israiloff</groupId>
<artifactId>rpc4rj</artifactId>
<version>VERSION</version>
</dependency>
VERSION is the latest version of the RPC4RJ plugin.
- Mark the target service with @RJRpcService annotation.
@RJRpcService(PATH_TO_API)
interface FooService{
}
PATH_TO_API is your web path to API (e.g. if the value of the path is "/path/to/api" then the target url will be http://YOUR_HOST_ADDRESS/path/to/api).
- Mark the target methods with @RJRpcMethod and method's arguments with @RJRpcParam annotations.
@RJRpcService(PATH_TO_API)
interface FooService{
@RJRpcMethod(METHOD_NAME)
Mono<FooResult> singleResultMethod(@RJRpcParam(ARG_NAME) FooRequest request);
}
METHOD_NAME is the name of the target method (e.g. "dummyMethod").
ARG_NAME is the name of the method's argument (e.g. "dummyArg").
Note that return type can be wrapped with Flux<> type. If so, you will get results one by one wrapped into json RPC result wrapper.\
- Declare errors.
@RJRpcService(PATH_TO_API)
interface FooService {
@RJRpcMethod(METHOD_NAME)
@RJRpcErrors({
@RJRpcError(exception = FooException.class, code = EX_CODE, message = MSG, data = DATA)
})
Mono<FooResult> singleResultMethod(@RJRpcParam(ARG_NAME) FooRequest request);
}
FooException.class - target exception class, EX_CODE - error code to return, MSG - error message to return, DATA - data to return.
You must create a bean of your service by yourself (by annotating service with @Service or @Component annotations, or by declaring it in configuration class via @Bean annotation).
The second important thing is to register beans of this plugin by scanning elements via @ComponentScan("io.github.israiloff.rpc4rj") or via @SpringBootApplication(scanBasePackages = {"io.github.israiloff.rpc4rj"}).