전체 글
-
Spring RequestContextHolder으로 Client IP 주소 가져오기Spring Framework 2023. 7. 22. 00:01
RequestContextHolder란? Spring 2.x부터 제공되던 기능으로 Spring 전역으로 Request에 대한 정보를 가져오고자 할 때 사용하는 유틸성 클래스입니다. 주로 Controller가 아닌, Service에서 Request 객체를 참고하려 할 때 사용합니다. private static final boolean jsfPresent = ClassUtils.isPresent("jakarta.faces.context.FacesContext", RequestContextHolder.class.getClassLoader()); private static final ThreadLocal requestAttributesHolder = new NamedThreadLocal("Request attr..
-
Spring WebSocket External Broker 적용(ActiveMQ)프로젝트/WebSocket 2023. 7. 21. 00:01
개요 In-memory Broker인 SimpleBroker를 사용하게 되면 Server Instance가 여러 대 존재할 때 상태에 대한 동기화가 제대로 이루어지지 않을 수 있습니다. 예를 들어, A유저는 Server1에서 웹소켓을 연동하였고, B유저는 Server2에서 웹소켓을 연동하였습니다. 만약 같은 /topic/same을 바라본다고 하더라도 Server1에서 message를 보내면 A만 받을 수 있을 것이며, Server2에서 message를 보내면 B만 받을 수 있습니다. 이에 따라 External Broker를 적용해보고자 합니다. RabbitMQ, ActiveMQ 등을 적용해 볼 수 있습니다. External Broker를 활용한 STOMP 구조도 SimpleBroker를 이용한 구조에서 ..
-
RSocket이란?프로젝트/WebSocket 2023. 7. 20. 00:01
RSocket이란? RSocket은 몇 가지 일반적인 마이크로서비스 통신 문제를 해결하기 위해 설계된 새로운 메시징 프로토콜입니다. TCP 또는 WebSocket을 통해 작동하는 유연한 프로토콜을 사용할 수 있습니다. 이는 변환없이 바이너리 메시지를 처리할 수 있음을 의미하고 Multiplexing, back-pressure, resumption, routing과 같은 제어 기능을 사용할 수 있으며, fire-and-forget, request-response, requset-stream, Channel 등을 이용할 수 있습니다. 또한 RSocket은 reactive로 동작하기 때문에 처리량이 많은 마이크로서비스 애플리케이션에 이상적입니다. Netflix, Pivotal, Alibaba, Facebook..
-
Spring Local Cache란?Spring Framework 2023. 7. 19. 00:01
Spring Local Cache란? Cache는 자주 액세스하는 데이터를 메모리에 저장하여 애플리케이션의 성능을 향상하는 데 사용되는 강력한 기술입니다. Spring Local Cache는 개발자가 애플리케이션의 메모리 내에서 응답 시간을 개선하고 백엔드 시스템의 부하를 줄이기 위해 데이터를 Local (일반적으로 JVM Heap)에 저장하는 메모리 내 캐시입니다. 장점 WAS의 인스턴스 메모리에 데이터를 저장하기 때문에 네트워크 지연 없이 매우 접근속도가 매우 빠릅니다. AWS/GCP Cloud의 Redis 등의 별도의 외부 종속성이 필요없습니다. 단점 메모리에 데이터를 저장하므로 캐시 크기는 사용 가능한 Heap 공간에 영향을 받습니다. 캐시가 너무 커지면 OOM이 발생할 수 있으며 적절한 캐시 크..
-
Kotlin + Spring Boot 3 Spring Data envers 적용Spring Framework 2023. 7. 18. 00:01
Spring Data envers란? 데이터베이스 테이블의 변경하면 가장 최근 상태만 알 수 있습니다. 하지만 envers를 사용하면 데이터 변경 이력을 관리하는 기능을 제공합니다. Gradle plugins { id("org.springframework.boot") version "3.1.0" id("io.spring.dependency-management") version "1.1.0" kotlin("jvm") version "1.8.21" kotlin("plugin.spring") version "1.8.21" kotlin("plugin.jpa") version "1.8.21" } dependencies { //Spring Web 의존성 implementation("org.springframewor..
-
Hard Delete와 Soft DeleteCS/데이터베이스 2023. 7. 17. 00:01
개요 데이터베이스에서 회원탈퇴와 같은 일이 일어났을 때 userStatus를 탈퇴상태로 바꿀 건지, 회원의 정보를 모두 삭제할지 고민하곤 합니다. hard delete와 soft delete에 대해 알아보고, 어떤 장단점이 있는지 알아보고자 합니다. Soft Delete란? 논리적으로만 삭제하는 방법입니다. 사용자가 한때 접근할 수 있었지만 더 이상 접근할 수 없는 데이터로 만들어 사용할 수 없게 만드는 프로세스입니다. 회원상태가 USING(이용 중)이라면 WITHDRAW(탈퇴)로 상태만 변경하여 해당 데이터는 DB에 그대로 남아있게 됩니다. UPDATE 쿼리가 발생합니다. Hard Delete란? 데이터베이스에서 영구적으로 데이터를 삭제하는 일입니다. DELETE 쿼리가 발생합니다. 다양한 관점에서 s..
-
log4j, logback, log4j2 비교Spring Framework 2023. 7. 16. 00:01
Logback이란? Logback은 Java에서 가장 많이 사용되었던 로깅 라이브러리인 log4j의 후속 버전입니다. 어떻게 보면 logback은 더욱 좋아진 log4j라고 보아도 무방합니다. log4j는 2015년에 단종을 발표했으며 logback은 Java 커뮤니티에서 가장 널리 사용되는 로깅 프레임워크 중 하나입니다. 물론 log4j의 후속버전으로 lo4j2가 존재합니다. log4j -> logback -> log4j2 순서로 출시되었습니다. Simple Logging Facade For Java(slf4 j)는 logback이나 log4js와 같은 로깅 프레임워크의 인터페이스 역할을 수행합니다. System.out.println() vs log4j 그냥 println으로 기록하면 안 될까요? 로깅..
-
프로메테우스란 무엇인가?모니터링 2023. 7. 15. 00:01
프로메테우스란? 구글의 쿠버네티스를 모니터링하기 위한 소프트웨어로 Borgmon이라는 것이 만들어졌는데 이를 비슷하게 오픈 소스로 공개한 것이 Prometheus입니다. 즉, Prometheus는 오픈소스 모니터링 시스템입니다. Spring Boot Application의 여러 메트릭을 수집하여 모니터링할 수 있는 환경을 구축할 수 있습니다. Spring Boot의 Actuator, Prometheus, Grafana 조합을 많이 사용하며 이를 통해 애플리케이션의 성능 및 상태에 대해 확인할 수 있습니다. HTTP를 통한 pull model을 통해 주기적으로 수집하여 시계열 데이터로 저장합니다. Spring Boot Actuator의 prometheus 앤드포인트를 사용하여 지표를 수집합니다. 메트릭이란..