본문 바로가기

Programming/Java, Spring98

[Spring Cloud] JWT 토큰 생성과 API Gateway에서 검증 필터 구현 스프링 부트 프로젝트에서 JWT 토큰을 생성하기 dependencies dependencies { implementation 'org.springframework.boot:spring-boot-starter-web' implementation 'org.springframework.boot:spring-boot-starter-security' implementation 'io.jsonwebtoken:jjwt-api:0.11.2' implementation 'io.jsonwebtoken:jjwt-impl:0.11.2' implementation 'io.jsonwebtoken:jjwt-jackson:0.11.2' // 다른 종속성들... } yml token: expiration_time: 86400000 s.. 2023. 6. 1.
[Spring Cloud] API Gateway Routing 시 마이크로서비스 식별 주소값을 제외하고 실용적인 uri를 전달하는 방식 기존 변경 filters의 RewritePath를 통해서 "/user-service/"를 생략하도록 변경한다. 기존의 방식으로는 컨트롤러에서 prefix를 다음과 같이 지정해주어야 했다. 예를 들어 포트 번호가 60000이라 한다면 http://127.0.0.1:6000/user-service/health_check 처럼 마이크로 서비스를 인식해주는 식별자로서 "user-service"라는 prefix가 필요했다. 그런데 마이크로서비스 입장에서는 "user-service"라는 prefix는 redundant하다. 서두의 주소를 나타내는 uri에서 이미 해당하는 마이크로서비스의 주소를 나타내고 있기 때문에 http://127.0.0.1/60000/login 만으로도 충분한 의미전달이 되기 때문이다. 그런데.. 2023. 6. 1.
[Spring Cloud] Users MicroService를 Api Gateway에 등록하기 간단하게 UserService를 구현하고 이를 API Gateway에 등록해보자. 구현 코드 https://github.com/renechoi/msa-with-springcloud/commit/09d9da6fd3a937c888ee4f839f0d6216dd680965 feat: user-service 구현 · renechoi/msa-with-springcloud@09d9da6 - entity, service, dto, repository, controller - create - password encoding github.com API Gateway 서버의 yml 파일에 다음과 같이 추가해준다. routes: - id: user-service uri: lb://USER-SERVICE predicates: .. 2023. 5. 31.
[Spring Cloud] API Gateway Service / routing, filter API Gateway Service의 역할 : - 클라이언트 대신 엔드포인트를 요청하고 요청을 받으면 다시 클라이언트에게 전달해주는 프락시 역할을 해준다. - 시스템 내부 구조는 숨기고 요청에 대해 적절히 가공해서 응답할 수 있다는 장점 => 클라이언트가 직접적으로 microservice를 호출하지 않고 게이트웨이만 상대하도록 한다. - 인증 및 권한 부여 - 서비스 검색 통합 - 응답 캐싱 - 정책, 회로 차단기 - 속도 제한 - 부하 분산 - 로깅, 추적, 상관관계 - 헤더, 쿼리 문자열 및 청구 변환 - ip 허용 목록에 추가 Netflix Ribbon Spring cloud 에서의 MSA 간 통신 1) RestTemplate - 자주 사용 : 인스턴스 만들고 get/post 등의 요청으로 보낼 수.. 2023. 5. 31.
[Spring Cloud] Discovery Server 만들고 User service 등록하기 Eureka Server 구현 ext { set('springCloudVersion', "2021.0.7") } dependencies { implementation 'org.springframework.cloud:spring-cloud-starter-netflix-eureka-server' testImplementation 'org.springframework.boot:spring-boot-starter-test' } dependencyManagement { imports { mavenBom "org.springframework.cloud:spring-cloud-dependencies:${springCloudVersion}" } } yml 파일 server: port: 8761 spring: appli.. 2023. 5. 31.