서비스1, 2를 다음과 같이 등록
각각의 서버주소/welcome으로 접근 시 welcomMsg 리턴하도록 컨트롤러를 생성 및 등록했음.
server:
port: 8071
eureka:
client:
fetch-registry: false
register-with-eureka: false
spring:
application:
name: first-service
server:
port: 8072
eureka:
client:
fetch-registry: false
register-with-eureka: false
spring:
application:
name: second-service
@RestController
@RequestMapping("/first-service")
public class FirstServiceController {
@GetMapping("/welcome")
public String welcome(){
return "welcome to the first service!";
}
}
@RestController
@RequestMapping("/second-service")
public class SecondServiceController {
@GetMapping("/welcome")
public String welcome(){
return "welcome to the second service!";
}
}
dependency : spring-cloud-gateway, eureka discovery client
server:
port: 8000
eureka:
client:
register-with-eureka: false
fetch-registry: false
service-url:
defaultZone : <http://localhost:8761/eureka>
spring:
application:
name: api-service
cloud:
gateway:
routes:
- id : first-service
uri : <http://localhost:8071/>
predicates:
- Path=/first-service/** # <http://localhost:8071/first-service/**> 로 포워딩
- id : second-service
uri : <http://localhost:8072/>
predicates:
- Path=/second-service/** # <http://localhost:8071/second-service/**> 로 포워딩
predicates는 조건으로 클라이언트의 Path에 따라 uri를 매핑하게 된다.
스프링 클라우드는 기본적으로 Zuul과 달리 비동기 처리가 가능하다(톰캣서버가 아닌 Netty WAS를 사용)