이벤트 서버 개발
## 개발 목표
1. 교육을 선착순으로 진행해야 한다.
아래 블로그를 올만에 정독했다.ㅋ
Redis&Kafka를 활용한 선착순 쿠폰 이벤트 개발기 (feat. 네고왕)
안녕하세요. 유저혜택개발팀 쿠폰 백앤드 개발자 페이든입니다.
techblog.gccompany.co.kr
## 우리내 CASE 체크!
일단 우리내 스펙을 확인해야 한다. 투머취 할 필요는 없으니깐
동접 2천명 내외고 "60"명에 대한 선착순이다.
:: 결론 별도 서버 하나 띄어서 진행하면 충분할듯!! 야호
## 서버 스펙은..
- 코틀린, r2dbc, redis-reactive
Kotlin integration — Armeria documentation
Kotlin integration Coroutines support for annotated services Visit annotated-http-service-kotlin to check out a fully working example. You can implement annotated services with Kotlin coroutines by adding the following dependency: Then, define the sus…
armeria.dev
다시 처음부터는 셋팅하는 것은 하악하악...
기본적으로 WebFlux를 이용하고자 했고 아르메리아 엔진교체를 하려고 구성을 했다.
현 시점에서 아르메리아는 스프링 3.0 이상에서 지원하지 않는다. 엌 아니네ㅋ 한참을 엄한데서..삽질했눼..
implementation 'com.linecorp.armeria:armeria-spring-boot2-webflux-starter'
-->
implementation 'com.linecorp.armeria:armeria-spring-boot3-webflux-starter'
이제의 고민은 자바로 갈지 코틀린 갈지.. 늘 새로운 것이 좋은것만은 아니다.
익숙한것들이 좋으제...타성에 젖지 않기 위해서 익숙한것들과 결별하자.
친절하지 않은 블로그이지만 올만에 스텝 by 스텝!ㅋ
1. 코틀린과 그래들-그루비로 선택한다. (메이븐만 아니면 되지 않을까.ㅎㅎ)
2. 추가적으로 필요한 부분은 별도 그래들로 작성한다. 물론 대충 만들고 전부 추가해도 된다.
3. 전체 의존이다. // 주석 있는 부분이 별도 추가!
dependencies {
implementation 'org.springframework.boot:spring-boot-starter-data-r2dbc'
implementation 'org.springframework.boot:spring-boot-starter-data-redis-reactive'
implementation 'io.projectreactor.kotlin:reactor-kotlin-extensions'
implementation 'org.jetbrains.kotlin:kotlin-reflect'
implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-reactor'
// armeria
implementation 'com.linecorp.armeria:armeria-spring-boot3-webflux-starter'
implementation platform('com.linecorp.armeria:armeria-bom:1.26.2')
// mysql r2dbc
implementation 'io.r2dbc:r2dbc-pool:1.0.0.RELEASE'
runtimeOnly 'io.asyncer:r2dbc-mysql:0.9.5'
compileOnly 'org.projectlombok:lombok'
annotationProcessor 'org.projectlombok:lombok'
testImplementation 'org.springframework.boot:spring-boot-starter-test'
testImplementation 'io.projectreactor:reactor-test'
}
4. resources 폴더 하위로 application.yml 만들어 준다. (자신 설정에 맞게 수정)
server:
port: 80
spring:
config:
activate:
on-profile: local
r2dbc:
url: r2dbc:mysql://127.0.0.1:3306/oauth2?useUnicode=true&serverTimezone=Asia/Seoul
username: oauth2
password: oauth2@1234
pool:
enabled: true
initial-size: 5
max-size: 20
max-idle-time: 157s
max-life-time: 157s
validation-query: select count(1) from client
data:
redis:
host: localhost
port: 6379
password: 111111
5. 아르메리아 설정을 한다. (테스트 주소 포함)
@Configuration
class ArmeriaConfig {
@Bean
fun armeriaServerConfigurator(): ArmeriaServerConfigurator {
return ArmeriaServerConfigurator { serverBuilder: ServerBuilder ->
// 접근 로그
serverBuilder.decorator(LoggingService.newDecorator())
serverBuilder.accessLogWriter(AccessLogWriter.common(), true)
// 5초 이상 걸리는 request 손절
serverBuilder.requestTimeout(Duration.ofSeconds(5))
serverBuilder.serviceUnder("/test") { _: ServiceRequestContext?, _: HttpRequest? ->
HttpResponse.of("안녕!! 추억안녕!! 너무나..눈물이나용")
}
}
}
}
6. 전체 그림
7. 셋팅이 반이다.
나도 5만명 트래픽 경험해보고 싶다..여기 어때? ㅉ때!!
레디스 조져 보자.!