Web/Spring 2023. 11. 5. 15:16

https://jessyt.tistory.com/m/151?category=966697

 

Spring-Kafka Lifecycle

이번 글에서는 Spring-Kafka의 Lifecycle에 대해서 작성해보겠습니다. 목차 Lifecycle Lifecycle Management 주의사항 1. Lifecycle @KafkaListener는 Application Context 안에 Bean이 아닙니다. @KafkaListener는 KafkaListenerEndpointR

jessyt.tistory.com


해당 포스팅 말고 다음 포스팅에도 읽어볼만한 주제가
많음

https://shining-life.tistory.com/m/3

 

4.1.3. Receiving Messages - (1) MessageListenerContainer

카프카 메시지를 수신하는 방법 두 가지 1. MessageListenerContainer Configuring 2. @KafkaListener 어노테이션을 사용하여, 메시지 리스너를 구현 Message Listeners message listener를 위해 제공되는 8가지 인터페이스

shining-life.tistory.com

nack() 설명

https://docs.spring.io/spring-cloud-stream-binder-kafka/docs/3.1.3/reference/html/spring-cloud-stream-binder-kafka.html#kafka-consumer-properties

 

Spring Cloud Stream Kafka Binder Reference Guide

This guide describes the Apache Kafka implementation of the Spring Cloud Stream Binder. It contains information about its design, usage, and configuration options, as well as information on how the Stream Cloud Stream concepts map onto Apache Kafka specifi

docs.spring.io

spring cloud stream kafka docs

spring kafka streams functional 방식으로 컨슈머를 구성하면 왠지..batch mode가 false 이고 레코드 단위로 컨슘 and 커밋하는듯함. 그래서 일전에 반드시 실패하는 로직 경우 커밋을 하지 못하고 무한 컨슘(이건 더 알아봐야 할듯함)

일단 위 설명에는 아래와 같이 써있음

If the ackMode is not set and batch mode is not enabled, RECORD ackMode will be used.



spring kafka docs

https://docs.spring.io/spring-kafka/docs/

 

Index of /spring-kafka/docs

 

docs.spring.io

 

posted by 여성게
:
Web/Spring 2023. 11. 5. 14:35

https://docs.spring.io/spring-kafka/docs/current/reference/html/#committing-offsets

 

Spring for Apache Kafka

When using Spring for Apache Kafka in a Spring Boot application, the Apache Kafka dependency versions are determined by Spring Boot’s dependency management. If you wish to use a different version of kafka-clients or kafka-streams, and use the embedded ka

docs.spring.io


https://hanseom.tistory.com/m/174

 

08. 스프링 카프카 컨슈머(Spring Kafka Consumer)

스프링 카프카 컨슈머는 기존 컨슈머를 2개의 타입으로 나누고 커밋을 7가지로 나누어 세분화 했습니다. 1. 타입 레코드 리스너(MessageListener): 단 1개의 레코드를 처리합니다. (스프링 카프카 컨슈

hanseom.tistory.com


BATCH 타입일 경우 poll로 가져온 모든 레코드 처리가 완료된 후에 한번에 커밋한다.

MANUAL 타입일 경우 커밋을 하면 다음 poll때 커밋한다. 리스너에서 레코드 단위로 처리하게 되어 매번 acknowledge()를 호출하면 BATCH 타입과 동일하게 동작한다.(AcknowledgingMessageListener 또는 BatchAcknowledgingMessageListener를 리스너로 사용해야 한다.)

MANUAL_IMMEDIATE 타입은 acknowledge() 호출시 즉시 커밋한다.(AcknowledgingMessageListener 또는 BatchAcknowledgingMessageListener를 리스너로 사용해야 한다.)

 

https://docs.spring.io/spring-kafka/reference/kafka/receiving-messages/message-listeners.html

 

Message Listeners :: Spring Kafka

When you use a message listener container, you must provide a listener to receive data. There are currently eight supported interfaces for message listeners. The following listing shows these interfaces:

docs.spring.io

스프링 카프카 메시지 리스너 레퍼런스

posted by 여성게
:
Web/Spring 2023. 11. 2. 22:30

https://m.youtube.com/watch?v=XBXmHCy1EBA&pp=ygUT64yA7Jqp65-JIO2KuOuemO2UvQ%3D%3D


https://m.youtube.com/watch?v=qzHjK1-07fI&pp=ygUT64yA7Jqp65-JIO2KuOuemO2UvQ%3D%3D

posted by 여성게
:
Web/Spring 2021. 11. 17. 18:21

웹플럭스에서 블록킹 연산을 발생시키는 채널이 있다면, 이벤트 채널을 관리하는 이벤트 루프 자체에 블럭킹이 발생하기 때문에 전체적으로 요청 처리를 하나도 못하는 문제가 발생할 수 있다. 그렇기 때문에 블럭킹을 발생시키는 연산이 있을 경우 스케쥴을 분리시켜주는 것이 좋고, 실제로 리액터에서도 이러한 것을 고려해 스케쥴러 생성 팩토리 메서드를 제공한다.

위 두개의 팩토리 메서드는 non-blocking 연산을 위한 스케쥴러 팩토리 메서드이다. 오래 걸리는 연산 등을 이벤트 루프 쓰레드에서 분리하고 싶을 때 사용하며, 블럭킹 연산이 포함되지 않은 연산에서만 사용해야한다. 만약 블록킹 연산에 대해 스케쥴을 분리하고 싶다면 boundedElastic()을 이용하면 된다.

 

사용법은 아래와 같다.

 

 

그런데, 블록킹 연산에 대해 스케쥴 분리하면 된다는 것은 알겠는데 이걸 어떻게 일일이 찾아서 분리해줄까? 이것은 메서드 시그니쳐로 약속하자.

 

 

위 두개의 메서드는 동기 메서드이며, 첫번째 메서드는 동기코드이며 블럭킹을 유발시키는 코드이다.(InterruptedException 발생) 세번째 메서드는 블록킹 콜이 없는 비동기 메서드이다. 첫번째 두번째 메서드는 사용하는 쪽에서 스케쥴 분리를 신경쓰면 되고 세번째 메서드는 해당 메서드 안에서 스케쥴 분리 처리를 해주어야한다. 근데 진짜 위 메서드 시그니처를 지키면 블록킹 콜이 발생하지 않을까?.. 이것을 찾기위한 도구로 BlockHound가 있다.

 

 

BlockHound는 운영환경에 같이 띄우면 안된다.(실제 바이트 코드등의 영향을 줄 수 있어서) 그렇기에 테스트 코드와 결합하여 사전에 블록킹 연산을 찾아내는 용도로만 사용하자 !(비효율적인 연산 등을 잡는 역할로는 사용 불가)

 

출처: IfKakao

posted by 여성게
:
Web/Gradle 2020. 8. 17. 18:06

 

그래들 프로젝트를 사용중인데, 간혹 idea에서 "Could not initialize class org.codehaus.groovy.runtime.InvokerHelper"라는 에러 메시지가 뜨는 경우가 있다. 여러가지 요인이 있을 수 있지만, 필자가 저 에러를 보았던 순간은 jdk 1.8에서 jdk14 버전으로 올리면서 났던 에러 메시지 인데, 이유는 gradle version이 jdk14를 지원하지 못하는 낮은 버전이었기 때문이다.

 

 

그래서, 프로젝트 디렉토리중 "gradle/wrapper/gradle-wrapper.properties"에서 gradle 버전을 올려주어서 해결하였다.(5.x -> 6,3)

posted by 여성게
:
Web/gRPC 2020. 7. 15. 20:27

 

이번 시간에 다루어볼 내용은 proto message로 생성한 Java를 Json String으로 변환하는 방법이다. proto로 생성한 java 인스턴스를 아래와 같이 json string으로 바꾸려면 예외가 발생한다.

 

#protoJava - proto로 생성한 java instance
ObjectMapper mapper = new ObjectMapper();
mapper.writeValueAsString(protoJava);

 

그렇기 때문에 protobuf의 JsonFormat으로 jsonString을 변환해주면 된다.

 

#protoJava - proto file로 생성한 java instance
final String jsonString = JsonFormat.printer().print(protoJava);

'Web > gRPC' 카테고리의 다른 글

gRPC - Protobuf란? 구글 프로토콜 버퍼(protocol buffers)  (0) 2020.05.03
gRPC - java gRPC 간단한 사용법  (0) 2020.05.03
gRPC - gRPC란 무엇인가?  (0) 2020.05.02
posted by 여성게
:
Web/Spring 2020. 6. 25. 16:03

 

오늘 다루어볼 내용은 spring data mongo + querydsl 연동 및 간단한 예제를 다루어볼 것이다. 예제 환경은 아래와 같다.

 

- gradle : 6.4.1
- spring boot : 2.3.1.RELEASE

 

모든 코드는 아래 깃헙을 참고하자.

 

yoonyeoseong/spring-mongo-querydsl

Contribute to yoonyeoseong/spring-mongo-querydsl development by creating an account on GitHub.

github.com

 

<gradle 설정>

아래는 spring data mongo와 querydsl 연동을 위한 gradle 설정이다.

 

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
buildscript {
    ext {
        queryDslVersion = '4.3.0'
    }
    repositories {
        maven {
            url "https://plugins.gradle.org/m2/"
        }
    }
    dependencies {
        classpath("org.springframework.boot:spring-boot-gradle-plugin:2.3.1.RELEASE")
    }
}
 
plugins {
    id 'org.springframework.boot' version '2.3.1.RELEASE'
    id 'io.spring.dependency-management' version '1.0.9.RELEASE'
    id "com.ewerk.gradle.plugins.querydsl" version '1.0.10'
    id 'java'
    id 'idea'
}
 
group = 'com.levi'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = '14'
 
repositories {
    mavenCentral()
}
 
dependencies {
    compile 'org.springframework.boot:spring-boot-starter-data-mongodb-reactive'
    compile 'org.springframework.boot:spring-boot-starter-webflux'
    compile('org.springframework.boot:spring-boot-configuration-processor')
 
    compile "com.querydsl:querydsl-mongodb:${queryDslVersion}"
 
    compile 'org.projectlombok:lombok'
 
    annotationProcessor(
            'org.springframework.boot:spring-boot-configuration-processor',
            "com.querydsl:querydsl-apt:${queryDslVersion}",
            'org.projectlombok:lombok'
    )
 
    testImplementation('org.springframework.boot:spring-boot-starter-test') {
        exclude group: 'org.junit.vintage', module: 'junit-vintage-engine'
    }
    testImplementation 'io.projectreactor:reactor-test'
}
 
test {
    useJUnitPlatform()
}
 
def querydslSrcDir = 'src/main/querydsl'
 
querydsl {
    springDataMongo = true
    querydslSourcesDir = querydslSrcDir
}
 
sourceSets {
    main {
        java {
            srcDirs = ['src/main/java', querydslSrcDir]
        }
    }
}
 
compileQuerydsl{
    options.annotationProcessorPath = configurations.querydsl
}
 
configurations {
    compileOnly {
        extendsFrom annotationProcessor
    }
    querydsl.extendsFrom compileClasspath
}
 
project.afterEvaluate {
    project.tasks.compileQuerydsl.options.compilerArgs = [
            "-proc:only",
            "-processor", project.querydsl.processors() + ',lombok.launch.AnnotationProcessorHider$AnnotationProcessor'
    ]
}
 
cs

 

작성중...

 

 

<참고>

 

Spring Data MongoDB - Reference Documentation

As of version 3.6, MongoDB supports the concept of sessions. The use of sessions enables MongoDB’s Causal Consistency model, which guarantees running operations in an order that respects their causal relationships. Those are split into ServerSession inst

docs.spring.io

 

gradle 프로젝트에서 querydsl 설정하기

gradle 4.6 / querydsl 4.2.1 / spring-data-jpa 1.11.13.RELEASE / spring-data-mongodb 1.10.8.RELEASE이 환경을 어떻게 gradle 설정으로 푸는지 정리힙니다.

mingpd.github.io

 

ewerk/gradle-plugins

A collection of Gradle plugins. Contribute to ewerk/gradle-plugins development by creating an account on GitHub.

github.com

posted by 여성게
:
Web/Spring 2020. 6. 25. 15:56

 

Spring Data MongoDB - Reference Documentation

As of version 3.6, MongoDB supports the concept of sessions. The use of sessions enables MongoDB’s Causal Consistency model, which guarantees running operations in an order that respects their causal relationships. Those are split into ServerSession inst

docs.spring.io

 

posted by 여성게
: