본문 바로가기

Spring34

배포된 애플리케이션 git branch/commit 정보 바로 확인하기 먼저 build.gradle 에 플러그인을 추가한다. 이 플러그인은 git branch/commit 정보를 git.properties 파일로 만들어 준다. plugins { id "com.gorylenko.gradle-git-properties" version "2.2.3" } 추가적으로 customProperty 도 넣을 수 있다. 더 자세한 내용은 여기에 있다. gitProperties { customProperty 'ybs.hello', 'world' customProperty "project_version", { project.version } } 컨트롤러에서는 아래와 같이 @Value 애노테이션으로 프로퍼티 git.properties 값을 가져올 수 있다. @SpringBootApplicatio.. 2021. 12. 19.
WebClient 사용할때 주의 (6편) WebClient 로 요청을 보내고 받은 응답 객체는 아래와 같다. 이때 message 값이 nullable 하다고 해보자. public class ResponseDto { private String id; @Nullable private String message; public String getMessage() { return message; } } ResponseDto 로 deserialize 한 후에 map 연산자를 이용해 message 를 가져오면 NPE가 발생한다. webClientBuilder ... 생략 .retrieve() .bodyToMono(ResponseDto.class) .map(responseDto -> responseDto.getMessage()) .onErrorResume(t.. 2021. 12. 15.
application warm up warm up 은 애플리케이션 로딩 후, 타 서비스 api 커넥션 연결, db 커넥션 연결, 캐시 등의 작업을 미리 수행하는 것을 의미한다. 만약 warm up 을 하지 않으면 초기 요청들은 실패할 위험이 있고, 순단에 가까운 장애까지 발생할 수 있다. 그래서 서비스 규모가 클수록 warm up 은 필수가 된다. warm up 의 개념은 단순하다. 그래서 구현이 크게 어렵지 않다. 애플리케이션 배포 후 실제 사용자 요청을 받기 전에 미리 요청을 보내면 되기 때문에 스크립트로 구현하기도 한다. 하지만 이글에서 소개하는 방법은 spring-boot-actuator-health 를 이용한다. cf) 팀에서 사용중인 warm up 기능 중 핵심부분만 따로 정리했다. 먼저 spring-boot-actuate-he.. 2021. 12. 5.
json error stack trace print 여부 커스텀 프로퍼티 먼저 application.yml 에 원하는 커스텀 프로퍼티를 추가한다. 보통 deploy phase 에 따라 다르게 설정된다. response: print-stack-trace: true 다음으로 /resources/META-INF/spring-configuration-metadata.json 파일에 프로퍼티에 대한 메타데이터를 추가한다. { "groups": [ { "name": "response", "type": "com.toy.config.ResponseProperties", "sourceType": "com.toy.config.ResponseProperties" } ], "properties": [ { "name": "response.print-stack-trace", "type": "java... 2021. 11. 22.
WebClient 사용할때 주의 (5편) Metric 먼저 Webclient 레벨에서 보내는 metric과 내부 구현체인 reactor.netty 레벨에서 보내는 metric 은 서로 다르다. WebClient 레벨에서 보내는 metric은 DefaultWebClientExchangeTagsProvider 에서 설정해서 보내고 있으며, uri template 단위로 태그 하고 있다. public class DefaultWebClientExchangeTagsProvider implements WebClientExchangeTagsProvider { @Override public Iterable tags(ClientRequest request, ClientResponse response, Throwable throwable) { Tag method.. 2021. 11. 11.
WebClient 사용할때 주의 (4편) 이전 WebClient 글 예제 코드로 아래와 같이 clientResponse.createException().flatMap() 과 onErrorResume 을 사용했는데 flatMap 을 해서 다시 Mono.error 로 감싸는, 어떻게 보면 비효율적인 코드다. AS-IS .retrieve() .onStatus( httpStatus -> httpStatus != HttpStatus.OK, clientResponse -> { return clientResponse.createException() .flatMap(it -> Mono.error(new RuntimeException("code : " + clientResponse.statusCode()))); }) .bodyToMono(String.class.. 2021. 11. 5.