Skip to content

Commit

Permalink
gateway cloud
Browse files Browse the repository at this point in the history
  • Loading branch information
forezp committed Nov 20, 2018
1 parent 0b0d6f4 commit 863339f
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,29 +15,29 @@
* @author fangzhipeng
* create 2018-11-16
**/
public class ElapsedGatewayFilterFactory extends AbstractGatewayFilterFactory<ElapsedGatewayFilterFactory.Config> {
public class RequestTimeGatewayFilterFactory extends AbstractGatewayFilterFactory<RequestTimeGatewayFilterFactory.Config> {


private static final Log log = LogFactory.getLog(GatewayFilter.class);
private static final String ELAPSED_TIME_BEGIN = "elapsedTimeBegin";
private static final String REQUEST_TIME_BEGIN = "requestTimeBegin";
private static final String KEY = "withParams";

@Override
public List<String> shortcutFieldOrder() {
return Arrays.asList(KEY);
}

public ElapsedGatewayFilterFactory() {
public RequestTimeGatewayFilterFactory() {
super(Config.class);
}

@Override
public GatewayFilter apply(Config config) {
return (exchange, chain) -> {
exchange.getAttributes().put(ELAPSED_TIME_BEGIN, System.currentTimeMillis());
exchange.getAttributes().put(REQUEST_TIME_BEGIN, System.currentTimeMillis());
return chain.filter(exchange).then(
Mono.fromRunnable(() -> {
Long startTime = exchange.getAttribute(ELAPSED_TIME_BEGIN);
Long startTime = exchange.getAttribute(REQUEST_TIME_BEGIN);
if (startTime != null) {
StringBuilder sb = new StringBuilder(exchange.getRequest().getURI().getRawPath())
.append(": ")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public static void main(String[] args) {
}

@Bean
public ElapsedGatewayFilterFactory elapsedGatewayFilterFactory() {
return new ElapsedGatewayFilterFactory();
public RequestTimeGatewayFilterFactory requestTimeGatewayFilterFactory() {
return new RequestTimeGatewayFilterFactory();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ spring:
gateway:
discovery:
locator:
enabled: true
enabled: false
lowerCaseServiceId: true
routes:
- id: service-hi
Expand All @@ -17,7 +17,7 @@ spring:
- Path=/demo/**
filters:
- StripPrefix=1
- Elapsed=false
- RequestTime=true

eureka:
client:
Expand Down
36 changes: 18 additions & 18 deletions sc-f-gateway-filter/.idea/workspace.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 863339f

Please sign in to comment.