전체 글
-
kafka Dead Letter Queue(DLQ, DLT)프로젝트/kafka 2023. 8. 7. 00:01
개요 AWS SQS에서는 Dead Letter Queue(DLQ)를 손쉽게 제공하고 연결할 수 있도록 합니다. 메시지가 실패하는 경우 재처리를 몇 번 할지도 console에서 간편하게 설정할 수 있습니다. Kafka의 경우 메시지 처리에 실패하면 Dead Letter Queue(DLQ)를 어떻게 관리할 수 있을까요? Kafka에서는 DLQ대신 DLT라는 개념을 사용합니다. DLT는 Dead Letter Topic의 약자입니다. SQS DLQ에 대해서는 다음글을 참고해 주세요. https://junuuu.tistory.com/740 [AWS] SQS DLQ 설정하기 DLQ란 무엇인가? DLQ(Dead Letter Queue)는 소프트웨어 시스템에서 오류로 인해 처리할 수 없는 메시지를 임시로 저장하는 특수..
-
kafka 메시지 삭제 정책프로젝트/kafka 2023. 8. 6. 00:01
개요 kafak를 운영하면 메시지를 언제까지 보관해야 할까요? kafka의 cleanup policy, retention policy, delete policy, compact policy 등에 대해 알아보고자 합니다. Kafka의 데이터는 어떻게 저장될까? kafka는 파티션에 데이터를 저장합니다. 카프카를 설정하면 파티션이 저장될 디렉토리의 위치를 log.dirs 매개변수에 지정할 수 있습니다. Kafka는 다른 메시징 시스템과 달리 토픽의 메시지가 소비된 후 즉시 삭제하지 않습니다. 대신 각 토픽의 구성에 따라 허용되는 공간과 관리 방식이 결정됩니다. Kafka의 구조는 Cluster -> Broker -> Topic -> Partition -> Segment Segment의 구조 특정 오프셋이나..
-
Kafka 객체 SERIALIZER, DESERIALIZER프로젝트/kafka 2023. 8. 5. 00:01
개요 Kafka를 사용하다 보면 메시지를 Stirng이 아닌 객체(DTO)로 전송하고 싶을 수 있습니다. 이때 Producer, Consumer Config를 알아보겠습니다. 테스트하기 위한 환경 local에서 실행할 수 있는 SpringBootApplication consumer 1대, producer 1대 docker, AWS MSK등으로 구성한 kafka 인프라 TestDTO data class TestDto( val col1: String, val col2: String, ) @Configuration @EnableKafka class KafkaProducerConfig { @Value("\${spring.kafka.producer.bootstrap-servers}") private lateini..
-
kafka Consumer group id 랜덤으로 부여프로젝트/kafka 2023. 8. 4. 00:01
개요 Consumer의 groupId를 랜덤으로 부여하여 pub/sub처럼 구성하고 싶었습니다. Instance가 여러 대일 때 동기화 하고자 했습니다. KafkaListener doc /** * Override the {@code group.id} property for the consumer factory with this value * for this listener only. * SpEL {@code #{...}} and property place holders {@code ${...}} are supported. * @return the group id. * @since 1.3 */ String groupId() default ""; groupId를 SpEL 문법을 통해서도 지정할 수 있습니다...
-
kafka consumer offset option (latest vs earliest)프로젝트/kafka 2023. 8. 3. 00:01
개요 만약 Consumer에서 동일한 토픽을 보고 다른 GroupId를 가진다면 새로운 Consumer가 생기는 경우 처음부터 메시지를 가져올 것이라 생각했고, 현재시점부터 메시지를 가져오기 원했습니다. Consumer의 auto-offset-reset 옵션 latest : 현재 시점부터 발생한 메시지부터 구독한다. (commit 관계없이 가장 최신) earliest : commit이 마지막으로 된 메세지부터 구독한다. (commit 기준으로 가장 오래된) none : 구독하고자 하는 topic의 offset 정보가 없으면 exception을 발생한다. 이미지로 살펴보기 consumer의 offset정보가 존재하지 않을 때 토픽의 가장 마지막 offset부터 읽습니다. earliest 옵션에 대해 오해한..
-
[AWS] SQS 가시성제한 0초 설정AWS 2023. 8. 2. 00:01
개요 Server가 여러 대의 Instance로 구성되어 있을 때 동기화를 위해 모두 SQS 메시지를 Consume 하게 하고 싶습니다. 예를 들어 @SqsListener를 가지는 Instance가 10대라면 동일한 메시지에 대해서 10번의 Consume이 발생하는 것입니다. 이를 테스트하기 전 다음과 같은 가설을 세워보았습니다. 가설 1 - 가시성 제한 0초 위의 요구사항을 구현하기 위해 가장 중요한 것은 가시성제한입니다. 가시성 제한은 기본적으로 30초이며 하나의 Consumer가 메시지를 읽고 있으면 30초간 다른 Consumer는 해당 메시지를 읽을 수 없습니다. 이 가시성 제한을 0초로 설정하면 모든 Consumer가 메시지를 읽을 수 있지 않을까요? 가설 2 - 네트워크 지연 하지만 네트워크 ..
-
Spring Boot Multiple Port 사용 (멀티 커넥트, 다중 포트)Spring Framework 2023. 7. 31. 00:01
개요 Spring Boot Application을 개발하며 여러 개의 Multipl Port로 접근가능하도록 설계할 순 없을까?라는 생각이 들었습니다. 예를 들어 8080, 8081, 8082로 모두 요청을 받고 싶은 경우 즉, Multiple Port를 사용하려면 어떻게 해야 할까요? 또는 HTTPS 접속, HTTP 접속 모두 해야 하는 경우에 사용할 수 있습니다. Tomcat의 Multiple Connectors @Configuration class EmbeddedTomcatConfiguration { @Bean fun servletContainer(): ServletWebServerFactory { val tomcat = TomcatServletWebServerFactory() tomcat.addA..