728x90
반응형

2020/12 6

Spring Cloud Gateway - Route Predicate & Gateway Filter Factory

Gateway를 만들면서 사용할 수 있는 룰들을 셋팅하는데 있어서 구글링 및 공식 Document를 보는 것에 시간이 걸려 하나씩 정리해 둔다. 참고로 사용하게 되는 Predicate Factory는 org.springframework.cloud.gateway.handler.predicate 아래에 있다. ( github.com/spring-cloud/spring-cloud-gateway/tree/2.2.x/spring-cloud-gateway-server/src/main/java/org/springframework/cloud/gateway/handler/predicate ) @Autowired private SecureHeadersProperties secureHeadersProperties; /** ..

Architecture/MSA 2020.12.28

API 호출 테스트를 위한 간단한 팁

api 호출을 할 경우 일부러 타임아웃 Exception과 같은 상황을 만들어서 테스트 하는 경우가 있다. 이럴 경우 Target API에 일부러 Sleep을 주어 상황을 만들어서 작업을 하였는데 그렇게 할 필요가 없다. spring.io/guides/gs/gateway/를 보면서 Srping Cloud Gateway를 구축하고 있는데 예제로 사용되어지는 httpbin.org 이라는 사이트를 이용하면 된다. 가령 간단하게 3초 딜레이 되는 경우를 테스트 하고 싶다면 http://httpbin.org/delay/3 이라고 호출하면 된다. 전체적인 내용은 swagger로 정리되어져 있기 때문에 http://httpbin.org 메인을 참고하면 된다. httpbin.org A simple HTTP Reques..

Java/Spring 2020.12.21

Hystrix, Feign을 이용한 개발

아직 프로토타입까지만 작성하였지만 기본적인 내용이 돌아가기에 현재의 상태를 기록한다. application.yml 파일 feign: hystrix: enabled: true client: config: feignName: connectTimeout: 5000 readTimeout: 5000 loggerLevel: full hystrix: command: default: # 5초 타임아웃. 1분동안 최소 5회 호출 이상, 50% 이상 실패면 circuit open execution: isolation: thread: timeoutInMilliseconds: 5000 metrics: rollingStats: timeInMilliseconds: 60000 circuitBreaker: requestVolumeT..

Architecture/MSA 2020.12.18

AttributeConverter class registered multiple times 에러가 발생할 경우

다른 사람이 Push 해 둔 소스를 Pull 받아 Springboot를 실행하는데 "AttributeConverter class registered multiple times" 에러가 뜨면서 실행이 되지 않았다. 관련된 에러가 Entity의 Converter 부분이여서 Database 연동 문제인줄 알고 intellij에서 Database source를 연결하였지만 실패... 구글링 해 보니 해당 Converter가 여러 곳에서 사용되면 그런 문제가 발생된다는 답이 몇 개 보여 converter를 사용 하는 곳을 다 주석 처리해 봐도 안되서 실패... 결국 로컬 Git repository 삭제 후 다시 Clone 받아서 실행해 보니 성공 함.

Java/Spring 2020.12.16

Zuul을 이용한 Gateway 구축 시 설정

Zuul을 이용하여 MSA의 Api Gateway 구축을 테스트 삼아 하고 있는데 설정 값을 지정하면서 알게 된 내용을 정리한다. application.yml 파일을 아래와 같이 설정 하였다. spring: application: name: api-gateway server: port: 8801 eureka: instance: instance-id: zuul-inst001 client: service-url: defaultZone: http://localhost:8761/eureka zuul: routes: chauffeur: path: /chauffeur/** stripPrefix: true path 에 지정하는 값은 client에서 api gateway로 호출할 때의 url path 이다. 해당 pa..

Architecture/MSA 2020.12.11

테스트 코드 작성 시 willReturn 값이 안나오는 경우

오랜만에 테스트 코드를 작성하기 위해 구글링 해서 작성을 했는데 내가 짜 놓은 시나리오대로 동작을 하지 않아 더 구글링, 그리고 주변에 사람들에게 질문을 하였지만.... 해답은 안 보였다. 작성한 테스트 코드는 아래와 같다. import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest; import org.springframework.boot.test.mock.mockito.MockBean; import org.springf..

Java/Spring 2020.12.02
728x90
반응형