-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
c0e4632
commit 2212771
Showing
9 changed files
with
117 additions
and
75 deletions.
There are no files selected for viewing
54 changes: 0 additions & 54 deletions
54
samples/src/main/java/io/github/ctlove0523/samples/HttpServerTests.java
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
server: | ||
port: 5230 | ||
port: 8080 | ||
|
||
spring: | ||
mvc: | ||
|
21 changes: 21 additions & 0 deletions
21
spring-cloud-consul/src/main/java/io/github/ctlove0523/consul/health/TestController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package io.github.ctlove0523.consul.health; | ||
|
||
import org.springframework.http.HttpStatus; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.stereotype.Controller; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
import org.springframework.web.bind.annotation.RequestMethod; | ||
|
||
@Controller | ||
public class TestController { | ||
|
||
@RequestMapping(value = "/api/lb",method = RequestMethod.GET) | ||
public ResponseEntity<String> lb() { | ||
return new ResponseEntity<>("lb", HttpStatus.OK); | ||
} | ||
|
||
@RequestMapping(value = "/api/no-lb",method = RequestMethod.GET) | ||
public ResponseEntity<String> noLb() { | ||
return new ResponseEntity<>("no-lb", HttpStatus.OK); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
server: | ||
port: 8765 | ||
port: 5231 | ||
spring: | ||
application: | ||
name: spring-cloud-consul-application | ||
|
22 changes: 22 additions & 0 deletions
22
spring-cloud-gateway/src/main/java/io/ctlove0523/spring/gateway/config/HttpClientConfig.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package io.ctlove0523.spring.gateway.config; | ||
|
||
import reactor.netty.http.client.HttpClient; | ||
|
||
import org.springframework.beans.BeansException; | ||
import org.springframework.beans.factory.config.BeanPostProcessor; | ||
import org.springframework.context.annotation.Configuration; | ||
import org.springframework.stereotype.Component; | ||
|
||
@Component | ||
public class HttpClientConfig implements BeanPostProcessor { | ||
|
||
@Override | ||
public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException { | ||
if (bean instanceof HttpClient) { | ||
HttpClient client = (HttpClient) bean; | ||
return client.metrics(true, s -> s); | ||
|
||
} | ||
return bean; | ||
} | ||
} |
42 changes: 42 additions & 0 deletions
42
spring-cloud-gateway/src/main/java/io/ctlove0523/spring/gateway/config/ServerConfigure.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
package io.ctlove0523.spring.gateway.config; | ||
|
||
import java.util.function.Function; | ||
|
||
import io.micrometer.core.instrument.Metrics; | ||
import io.micrometer.core.instrument.config.MeterFilter; | ||
import reactor.core.publisher.Mono; | ||
import reactor.netty.http.server.HttpServer; | ||
|
||
import org.springframework.boot.autoconfigure.web.reactive.ReactiveWebServerFactoryCustomizer; | ||
import org.springframework.boot.web.embedded.netty.NettyReactiveWebServerFactory; | ||
import org.springframework.boot.web.embedded.netty.NettyServerCustomizer; | ||
import org.springframework.boot.web.reactive.server.ReactiveWebServerFactory; | ||
import org.springframework.boot.web.server.WebServerFactoryCustomizer; | ||
import org.springframework.http.server.reactive.HttpHandler; | ||
import org.springframework.http.server.reactive.ServerHttpRequest; | ||
import org.springframework.http.server.reactive.ServerHttpResponse; | ||
import org.springframework.stereotype.Component; | ||
|
||
@Component | ||
public class ServerConfigure implements WebServerFactoryCustomizer<NettyReactiveWebServerFactory> { | ||
|
||
|
||
@Override | ||
public void customize(NettyReactiveWebServerFactory factory) { | ||
Metrics.globalRegistry | ||
.config() | ||
.meterFilter(MeterFilter.maximumAllowableTags("reactor.netty.http.server", "URI", 100, MeterFilter.deny())); | ||
|
||
factory.addServerCustomizers(new NettyServerCustomizer() { | ||
@Override | ||
public HttpServer apply(HttpServer httpServer) { | ||
return httpServer.metrics(true, new Function<String, String>() { | ||
@Override | ||
public String apply(String s) { | ||
return s; | ||
} | ||
}); | ||
} | ||
}); | ||
} | ||
} |
21 changes: 21 additions & 0 deletions
21
spring-cloud-gateway/src/main/java/io/ctlove0523/spring/gateway/health/TestController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package io.ctlove0523.spring.gateway.health; | ||
|
||
import org.springframework.http.HttpStatus; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.stereotype.Controller; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
import org.springframework.web.bind.annotation.RequestMethod; | ||
|
||
@Controller | ||
public class TestController { | ||
|
||
@RequestMapping(value = "/api/lb",method = RequestMethod.GET) | ||
public ResponseEntity<String> lb() { | ||
return new ResponseEntity<>("lb", HttpStatus.OK); | ||
} | ||
|
||
@RequestMapping(value = "/api/no-lb",method = RequestMethod.GET) | ||
public ResponseEntity<String> noLb() { | ||
return new ResponseEntity<>("no-lb", HttpStatus.OK); | ||
} | ||
} |