# flow-controller
**Repository Path**: geekgo/flow-controller
## Basic Information
- **Project Name**: flow-controller
- **Description**: 限流
- **Primary Language**: Java
- **License**: Not specified
- **Default Branch**: master
- **Homepage**: None
- **GVP Project**: No
## Statistics
- **Stars**: 1
- **Forks**: 1
- **Created**: 2016-08-04
- **Last Updated**: 2020-12-19
## Categories & Tags
**Categories**: Uncategorized
**Tags**: None
## README
## flow-controller
It's very simple to use.
#### How to use
first declare your service :
```java
@RateLimit
public class HelloService {
@QPSRate(rate = 1)
public void sayPerSecond() {
System.out.println("say one per second");
}
@QPSRate(rate = 0.5)
public void sayPer2Second() {
System.out.println("say one per 2 seconds");
}
public void sayData(@DPSRate(rate = 1) byte[] data) {
System.out.println("say data ");
}
}
```
1. write a service class and declare with `@RateLimit ` annotation.
2. put `@QPSRate`annotation upon the method you want to limit, for sake of limitation you need give the `rate` value. `rate` value control the total number of execution within a second.
3. put `@DPSRate` annotation besides one of method paramethers, you don't have to give the `rate`. it will automatically evaluate by:
1. if parameter is a number, rate would be that value
2. if parameter is an array, rate would be size of it
### Use without setting up spring framework
```java
FlowControllerContext context = new FlowControllerContext();
FlowControllerInterceptor interceptor = new FlowControllerInterceptor(context);
context.addRateLimiters(HelloService.class);
final HelloService helloService = interceptor.create(HelloService.class);
for (int i=0;i<5;i++){
executorService.submit(new Runnable() {
@Override
public void run() {
byte[] b = {'a','b','c','d'};
helloService.sayData(b);
}
});
}
executorService.shutdown();
```
### Use with spring framework
```xml
```
- be care of `xmlns:rate="http://www.edream.cf/schema/ratelimit`
give the schemaLocation to `http://www.edream.cf/schema/ratelimit.xsd` and give `annotation-driven` scan packages. all work will be done.
```java
@Resource
private HelloService service;
```
use spring `DI` to reference your service. and enjoy it!
### How to get it
- **maven**
```
1.0.0-SNAPSHOT
```