spring cloud : spring cloud gateway - logging filter, load balancer
This commit is contained in:
@@ -1,16 +1,27 @@
|
||||
package com.example.firstservice;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.core.env.Environment;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.RequestHeader;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
|
||||
@Slf4j
|
||||
@RestController
|
||||
@RequestMapping("/first-service")
|
||||
public class FirstServiceController {
|
||||
|
||||
Environment env;
|
||||
|
||||
@Autowired
|
||||
public FirstServiceController(Environment env) {
|
||||
this.env = env;
|
||||
}
|
||||
|
||||
@GetMapping("/welcome")
|
||||
public String welcome() {
|
||||
return "Welcome to the First Service.";
|
||||
@@ -23,7 +34,9 @@ public class FirstServiceController {
|
||||
}
|
||||
|
||||
@GetMapping("/check")
|
||||
public String check() {
|
||||
return "Hi, there. This is a message from first Service.";
|
||||
public String check(HttpServletRequest request) {
|
||||
log.info("Server port={}", request.getServerPort());
|
||||
return String.format("Hi, there. This is a message from first Service on PORT %s",
|
||||
env.getProperty("local.server.port"));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,10 +1,16 @@
|
||||
server:
|
||||
port: 8081
|
||||
port: 0
|
||||
|
||||
spring:
|
||||
application:
|
||||
name: my-first-service
|
||||
|
||||
eureka:
|
||||
client:
|
||||
register-with-eureka: false
|
||||
fetch-registry: false
|
||||
fetch-registry: true
|
||||
register-with-eureka: true
|
||||
service-url:
|
||||
defaultZone: http://localhost:8761/eureka
|
||||
|
||||
instance:
|
||||
instance-id: ${spring.application.name}:${spring.application.instance-id:${random.value}}
|
||||
Reference in New Issue
Block a user