Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
A
ali-middleware-5-sync
Manage
Activity
Members
Labels
Plan
Issues
0
Issue boards
Milestones
Wiki
Code
Merge requests
0
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Recolic
ali-middleware-5-sync
Commits
72c0a756
There was an error fetching the commit references. Please try again later.
Commit
72c0a756
authored
6 years ago
by
xujingfeng
Browse files
Options
Downloads
Patches
Plain Diff
add the samples of requestLimiter and client Filter
parent
d125c18f
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
README.MD
+89
-0
89 additions, 0 deletions
README.MD
workspace-provider/src/main/java/com/aliware/tianchi/TestRequestLimiter.java
+1
-1
1 addition, 1 deletion
...src/main/java/com/aliware/tianchi/TestRequestLimiter.java
with
90 additions
and
1 deletion
README.MD
+
89
−
0
View file @
72c0a756
...
...
@@ -195,6 +195,95 @@ resources/META-INF/services/org.apache.dubbo.rpc.service.CallbackService
以上 CallbackListener 和 CallbackService 结合使用,实现了一个服务提供者每 5 秒向客户端推送服务器时间的能力,选手可以自行扩展。
#### org.apache.dubbo.remoting.transport.RequestLimiter
```
java
@SPI
public
interface
RequestLimiter
{
boolean
tryAcquire
(
Request
request
,
int
activeTaskCount
);
}
```
限流扩展接口,服务端扩展接口
**接口实现示例**
```
java
public
class
TestRequestLimiter
implements
RequestLimiter
{
@Override
public
boolean
tryAcquire
(
Request
request
,
int
activeTaskCount
)
{
return
true
;
}
}
```
请求参数说明:
-
request 服务请求详细信息
-
activeTaskCount 服务端对应线程池的活跃线程数
返回值说明:
-
false 不提交给服务端业务线程池直接返回,客户端可以在 Filter 中捕获 RpcException
-
true 不限流
**添加 SPI 声明文件**
```
com.aliware.tianchi.TestRequestLimiter
```
文件内容只有一行,存放位置需要固定在:
resources/META-INF/services/org.apache.dubbo.remoting.transport.RequestLimiter
#### org.apache.dubbo.rpc.Filter
```
java
@SPI
public
interface
Filter
{
Result
invoke
(
Invoker
<?>
invoker
,
Invocation
invocation
)
throws
RpcException
;
default
Result
onResponse
(
Result
result
,
Invoker
<?>
invoker
,
Invocation
invocation
)
{
return
result
;
}
}
```
**接口实现示例**
```
java
@Activate
(
group
=
Constants
.
CONSUMER
)
public
class
TestClientFilter
implements
Filter
{
@Override
public
Result
invoke
(
Invoker
<?>
invoker
,
Invocation
invocation
)
throws
RpcException
{
try
{
Result
result
=
invoker
.
invoke
(
invocation
);
return
result
;
}
catch
(
Exception
e
){
// do sth
throw
e
;
}
}
}
```
**添加 SPI 声明文件**
```
com.aliware.tianchi.TestClientFilter
```
文件内容只有一行,存放位置需要固定在:
resources/META-INF/services/org.apache.dubbo.rpc.Filter
### 接口说明
-
开发接口固定为
`UserLoadBalance`
,选手可以修改其实现,但不能重命名、移动其位置,包括其 SPI 定义文件,否则评测程序无法正常加载选手的代码
...
...
This diff is collapsed.
Click to expand it.
workspace-provider/src/main/java/com/aliware/tianchi/TestRequestLimiter.java
+
1
−
1
View file @
72c0a756
...
...
@@ -15,7 +15,7 @@ public class TestRequestLimiter implements RequestLimiter {
/**
* @param request 服务请求
* @param activeTaskCount 服务端对应线程池的活跃线程数
* @return false 不提交给服务端业务线程池直接返回,客户端可以在 Filter 中捕获
搭配
RpcException
* @return false 不提交给服务端业务线程池直接返回,客户端可以在 Filter 中捕获 RpcException
* true 不限流
*/
@Override
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment