Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/youkol/jsonrpc4j-spring-boot-starter
spring boot starter for jsonrpc4j
https://github.com/youkol/jsonrpc4j-spring-boot-starter
json-rpc jsonrpc-client jsonrpc-server jsonrpc4j jsonrpc4j-spring-boot-starter
Last synced: 10 days ago
JSON representation
spring boot starter for jsonrpc4j
- Host: GitHub
- URL: https://github.com/youkol/jsonrpc4j-spring-boot-starter
- Owner: youkol
- License: apache-2.0
- Created: 2024-02-28T00:59:50.000Z (10 months ago)
- Default Branch: main
- Last Pushed: 2024-03-15T16:25:18.000Z (10 months ago)
- Last Synced: 2024-12-18T06:21:41.495Z (14 days ago)
- Topics: json-rpc, jsonrpc-client, jsonrpc-server, jsonrpc4j, jsonrpc4j-spring-boot-starter
- Language: Java
- Homepage:
- Size: 105 KB
- Stars: 3
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# jsonrpc4j-spring-boot-starter
Spring boot starter for jsonrpc4j.
## jsonrpc4j
* jsonrpc4j Github:
## 1. Usage
### 1.1. Maven
```xml
com.youkol.support
jsonrpc4j-spring-boot-starter
${jsonrpc4j-spring-boot.version}```
### 1.2. Spring Boot application.properties/yaml
```yaml
# Default value for jsonrpc4j-spring-boot-starter
youkol:
jsonrpc4j:
enabled: true
server:
enabled: true
backwards-compatible: true
rethrow-exceptions: false
allow-extra-params: false
allow-less-params: false
should-log-invocation-errors: true
parallel-enabled: false
parallel-batch-processing-timeout: 30s
content-type: "application/json-rpc"
welcome:
enabled: true
servlet:
enabled: true
path: "/jsonrpc"
load-on-startup: -1
client:
base-url:
enabled: false
scan-package:
content-type:
```### 1.3. Use Servlet Mode (`JsonRpcMultiServer`)
#### 1.3.1. Java Code
> @JsonRpcMultiServiceName: If you want to use multiple services, you can use this annotation for special the service name.
>
> `JsonRpcBaseService` is the base class for all services. You must extends it on your interface, it will be auto injected by `JsonRpcMultiServer.addService````java
@JsonRpcMultiServiceName("User")
public interface UserService extends JsonRpcBaseService {
User createUser(@JsonRpcParam(value="userName") String userName,
@JsonRpcParam(value="firstName") String firstName,
@JsonRpcParam(value="password") String password);
User createUser(@JsonRpcParam(value="userName") String userName,
@JsonRpcParam(value="password") String password);
User findUserByUserName(@JsonRpcParam(value="userName") String userName);
int getUserCount();
}@Service
public class UserServiceImpl implements UserService {public User createUser(String userName, String firstName, String password) {
User user = new User();
user.setUserName(userName);
user.setFirstName(firstName);
user.setPassword(password);
database.saveUser(user);
return user;
}public User createUser(String userName, String password) {
return this.createUser(userName, null, password);
}public User findUserByUserName(String userName) {
return database.findUserByUserName(userName);
}public int getUserCount() {
return database.getUserCount();
}}
```#### 1.3.2. JSON request for RPC call
```json
POST http://localhost:8080/jsonrpc
body:
{
"jsonrpc":"2.0",
"method": "User.createUser",
"params": {
"userName": "",
"firstName": "",
"password": ""
},
"id": "1"
}
```### 1.4. Use jsonrpc4j annotation (`AutoJsonRpcServiceImplExporter`)
* @JsonRpcService
* @AutoJsonRpcServiceImpl
* @JsonRpcParam
* @JsonRpcMethod#### 1.4.1. Java Code for Annotations
```java
@JsonRpcService("/jsonrpc/user")
public interface UserService {
// @JsonRpcMethod is optional, if you need custom method names, you can use it.
// @JsonRpcMethod("User.create")
User createUser(@JsonRpcParam(value="userName") String userName,
@JsonRpcParam(value="firstName") String firstName,
@JsonRpcParam(value="password") String password);
// @JsonRpcMethod("User.create")
User createUser(@JsonRpcParam(value="userName") String userName,
@JsonRpcParam(value="password") String password);
// @JsonRpcMethod("User.findUserByUserName")
User findUserByUserName(@JsonRpcParam(value="userName") String userName);
// @JsonRpcMethod("User.getUserCount")
int getUserCount();
}@Service
@AutoJsonRpcServiceImpl
public class UserServiceImpl implements UserService {public User createUser(String userName, String firstName, String password) {
User user = new User();
user.setUserName(userName);
user.setFirstName(firstName);
user.setPassword(password);
database.saveUser(user);
return user;
}public User createUser(String userName, String password) {
return this.createUser(userName, null, password);
}public User findUserByUserName(String userName) {
return database.findUserByUserName(userName);
}public int getUserCount() {
return database.getUserCount();
}}
```#### 1.4.2. JSON request
```json
POST http://localhost:8080/jsonrpc/user
body:
{
"jsonrpc":"2.0",
"method": "User.createUser",
// "method": "User.create", # for @JsonRpcMethod
"params": {
"userName": "",
"firstName": "",
"password": ""
},
"id": "1"
}
```### 1.5. Parallel batch an Array filled with Request objects
The `ExecutorService` utilizes `ThreadPoolExecutor` as its default implementation.
It is configured through `ThreadPoolTaskExecutor` from `TaskExecutionAutoConfiguration`.
As a result, the `ExecutorService` and `@Async` share a thread pool.You can customize an `ExecutorService` to replace it.