Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit e66e788

Browse files
committed
update readme
1 parent f39191c commit e66e788

File tree

3 files changed

+250
-250
lines changed

3 files changed

+250
-250
lines changed

‎README.md

Lines changed: 69 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Spring Boot Data Parallel Aggregation Library
1+
# Spring Boot 并行数据聚合库
22

33
[![Build Status](https://travis-ci.org/lvyahui8/spring-boot-data-aggregator.svg?branch=develop)](https://travis-ci.org/lvyahui8/spring-boot-data-aggregator)
44
[![Codecov](https://codecov.io/gh/lvyahui8/spring-boot-data-aggregator/branch/develop/graph/badge.svg)](https://codecov.io/gh/lvyahui8/spring-boot-data-aggregator/branch/develop)
@@ -9,44 +9,43 @@
99
[![Total alerts](https://img.shields.io/lgtm/alerts/g/lvyahui8/spring-boot-data-aggregator.svg?logo=lgtm&logoWidth=18)](https://lgtm.com/projects/g/lvyahui8/spring-boot-data-aggregator/alerts/)
1010
[![Language grade: Java](https://img.shields.io/lgtm/grade/java/g/lvyahui8/spring-boot-data-aggregator.svg?logo=lgtm&logoWidth=18)](https://lgtm.com/projects/g/lvyahui8/spring-boot-data-aggregator/context:java)
1111

12-
## Background and purpose
12+
## 背景与目的
1313

14-
When developing the background interface, in order to improve the development efficiency, we often write serial execution codes to call different interfaces, even if there is no dependency among these interfaces, which causes the last developed interface performance is low, and the data is not convenient to reuse.
14+
在开发后台接口时, 为了开发效率, 我们往往习惯编写串行执行的代码, 去调用不同的接口, 即使这些接口之间并无依赖, 这使得最后开发的接口性能低下, 且数据不方便复用
1515

16-
**This framework is designed to support parallel and data reuse while maintaining the development efficiency.**
16+
**此框架目的旨在保持开发效率的同时, 很方便地支持并行和数据复用**
1717

18-
Of course, in an extremely high concurrent scenario, the parallel call interface is not that helpful for performance improvement. However, it doesn't mean that this project is meaningless because most applications in the Internet don't have very high concurrent traffic.
18+
当然, 在极端高并发的场景下,CPU很可能已经跑满, 并行调用接口对性能提升并不明显, 但不代表这个项目没有价值. 因为互联网世界的大部分应用, 并不会有非常高的并发访问量
1919

20-
## Features
20+
## 特性
2121

22-
- **Getting dependencies asynchronously**
22+
- **异步获取依赖**
2323

24-
All dependencies defined by `@DataConsumer` will be got asynchronously. The provider method is executed when all the dependencies of the provider method parameters are got .
24+
所有 `@DataConsumer` 定义的依赖将异步获取. 当provider方法参数中的所有依赖获取完成, 才执行provider方法
2525

26-
- **Unlimited nesting**
26+
- **不限级嵌套**
2727

28-
Dependencies support deep nesting. The following example has only one layer of nesting relationship.
28+
依赖关系支持深层嵌套. 下面的示例只有一层
2929

30-
- **Exception handling**
30+
- **异常处理**
3131

32-
Currently supports two processing methods: ignore or stop
32+
目前支持两种处理方式: 忽略or终止
3333

34-
Ignore means that the provider method ignores the exception and returns a null value when it is executed. Stop means that once a provider method throws an exception, it will be thrown up step by step, and stop subsequent processing.
34+
忽略是指provider方法在执行时, 忽略抛出的异常并return null值; 终止是指一旦有一个provider方法抛出了异常, 将逐级向上抛出, 终止后续处理.
3535

36-
Exception handling configuration item supports consumer level or global level, and consumer level is priority to global level
36+
配置支持consumer级或者全局, 优先级 : consumer级 > 全局
3737

38-
- **Query Cache**
38+
- **查询缓存**
3939

40-
In one query life cycle of calling the Facade's query method, the result called by `@DataProvider` method may be reused. As long as the method signature and the parameters are consistent, the default method is idempotent, and the cached query result will be used directly.** However, this Not an absolute. Considering the multi-threading feature, sometimes the cache is not used.
40+
在调用Facade的query方法的一次查询生命周期内, **方法调用结果可能复用, 只要方法签名以及传参一致, 则默认方法是幂等的, 将直接使用缓存的查询结果.** 但这个不是绝对的, 考虑到多线程的特性, 可能有时候不会使用缓存
4141

42-
- **Timeout Control**
42+
- **超时控制**
4343

44-
`@DataProvider` annotation supports configuration timeout, query timeout will throw interrupt exception (InterruptedException), follow exception handling logic.
44+
`@DataProvider` 注解支持配置timeout, 超时将抛出中断异常 (InterruptedException), 遵循异常处理逻辑
4545

46+
## 使用方法
4647

47-
## Getting Started
48-
49-
### 1. Configuration
48+
### 1. 配置
5049

5150
pom.xml
5251

@@ -61,60 +60,59 @@ pom.xml
6160
application.properties
6261

6362
```properties
64-
# Specify the package to scan the annotations
63+
# 指定要扫描注解的包
6564
io.github.lvyahui8.spring.base-packages=io.github.lvyahui8.spring.example
6665
```
6766

68-
### 2. Annotation
69-
70-
- `@DataProvider`: define the data provider
67+
### 2. 添加注解
7168

72-
- `@DataConsumer`: define the method parameter dependency type as return the value of other interfaces, the other interface is a `@DataProvider`
69+
- `@DataProvider` 定义数据提供者
70+
- `@DataConsumer` 定义方法参数依赖类型为其他接口返回值, 其他接口是一个`@DataProvider`
71+
- `@InvokeParameter` 定义方法参数依赖类型为用户输入值
7372

74-
-`@InvokeParameter`: define the method parameter dependency type as the user input value
73+
### 3. 查询
7574

76-
### 3. Query
75+
通过 `DataFacade.get` 静态门面查询指定数据
7776

78-
Query the specified data via `DataFacade.get` static facade
77+
## 示例
7978

80-
## Example
79+
开发一个用户汇总数据接口, 包括用户的基础信息和博客列表
8180

82-
Developing a user summary data interface that includes the user's basic information and blog list.
81+
### 1. 定义提供基础数据的"原子"服务
8382

84-
### 1. Define an "atomic" service to provide user data
83+
使用`@DataProvider`定义接口为数据提供者
8584

86-
Use `@DataProvider` to define the interface as a data provider.
85+
使用`@InvokeParameter`指定要传递的用户输入参数
8786

88-
Use `@InvokeParameter` to specify the input parameters to pass.
87+
**博客列表服务**
8988

90-
**Blog list service**
91-
92-
require input parameter `userId`.
89+
需要参数`userId`
9390

9491
```java
9592
@Service
9693
public class PostServiceImpl implements PostService {
97-
@DataProvider("posts")
98-
@Override
99-
public List<Post> getPosts(@InvokeParameter("userId") Long userId) {
94+
@DataProvider("posts")
95+
@Override
96+
public List<Post> getPosts(@InvokeParameter("userId") Long userId) {
10097
```
10198

102-
**User basic information query service**
99+
**用户基础信息查询服务**
103100

104-
require input parameter `userId`.
101+
需要参数`userId`
105102

106103
```java
107104
@Service
108105
public class UserServiceImpl implements UserService {
109-
@DataProvider("user")
110-
@Override
111-
public User get(@InvokeParameter("userId") Long id) {
106+
@DataProvider("user")
107+
@Override
108+
public User get(@InvokeParameter("userId") Long id) {
112109
```
113110

114-
### 2. Call the aggregation interface
111+
### 2. 调用聚合接口
115112

116-
#### Method1:Functional call
113+
#### 方式一: 函数式调用
117114

115+
注意这里不能将函数式调用改为Lambda表达式, 两者的实际行为是不一致的.
118116

119117
```java
120118
User user = DataFacade.get(
@@ -131,51 +129,50 @@ Assert.notNull(user,"User must not be NULL");
131129
Assert.notNull(user.getPosts(),"User's posts must not be NULL");
132130
```
133131

134-
#### Method2:Define and implement an aggregation layer
132+
#### 方式二: 定义聚合层查询
135133

136-
Combine`@DataProvider` ( `@DataConsumer` \ `@InvokeParameter` ) to achieve aggregation function
134+
组合`@DataProvider` \ `@DataConsumer` \ `@InvokeParameter` 实现汇聚功能
137135

138136
```java
139137
@Component
140138
public class UserAggregate {
141-
@DataProvider("userWithPosts")
142-
public User userWithPosts(
143-
@DataConsumer("user") User user,
144-
@DataConsumer("posts") List<Post> posts) {
145-
user.setPosts(posts);
146-
return user;
147-
}
139+
@DataProvider("userWithPosts")
140+
public User userWithPosts(
141+
@DataConsumer("user") User user,
142+
@DataConsumer("posts") List<Post> posts) {
143+
user.setPosts(posts);
144+
return user;
145+
}
148146
}
149147
```
150148

151-
Specify queried data id, invoke parameters, and return type to invoke `facade.get` method
149+
指定要查询的data id, 查询参数, 返回值类型, 并调用`facade.get`方法即可
152150

153151
```java
154152
User user = DataFacade.get(/*data id*/ "userWithPosts",
155-
/*Invoke Parameters*/
156-
Collections.singletonMap("userId",1L),
157-
User.class);
153+
/*Invoke Parameters*/
154+
Collections.singletonMap("userId",1L),
155+
User.class);
158156
Assert.notNull(user,"User must not be NULL");
159157
Assert.notNull(user.getPosts(),"User's posts must not be NULL");
160158
```
161159

162-
**Invoke result**
160+
**运行结果**
163161

164-
As you can see, `user` interfaceand `posts` interfaceare executed by the asynchronous thread while `userWithPosts` service is executed by the calling thread.
162+
可以看到, user 和posts是由异步线程执行查询, 而userWithPosts是主调线程执行, 其中
165163

166-
- Basic user information query takes 1000ms
167-
- User blog list query takes 1000ms
168-
- **Total query takes 1005ms**
164+
- 基础user信息查询耗费时间 1000ms
165+
- 用户博客列表查询耗费时间 1000ms
166+
- **总的查询时间 1005ms**
169167

170168
```
171-
[aggregateTask-1] query id: user, costTime: 1000ms, resultType: User, invokeMethod: UserServiceImpl#get
172-
[aggregateTask-2] query id: posts, costTime: 1000ms, resultType: List, invokeMethod: PostServiceImpl#getPosts
173-
[ main] query id: userWithPosts, costTime: 1010ms, resultType: User, invokeMethod: UserAggregate#userWithPosts
174-
[ main] user.name:lvyahui8,user.posts.size:1
169+
[aggregateTask-1] query id: user, costTime: 1000ms, resultType: User, invokeMethod: UserServiceImpl#get
170+
[aggregateTask-2] query id: posts, costTime: 1000ms, resultType: List, invokeMethod: PostServiceImpl#getPosts
171+
[ main] query id: userWithPosts, costTime: 1010ms, resultType: User, invokeMethod: UserAggregate#userWithPosts
172+
[ main] user.name:lvyahui8,user.posts.size:1
175173
```
176174

177-
## Contributors
178-
179-
- Feego (lvyauhi8@gmail.com)
175+
## 贡献者
180176

177+
- Feego(lvyauhi8@gmail.com)
181178
- Iris G

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /