Skip to content

Commit

Permalink
domain_event_api 모듈 제거 (#222)
Browse files Browse the repository at this point in the history
  • Loading branch information
Zeniuus authored Nov 3, 2023
1 parent 8e44d0b commit 7175d73
Show file tree
Hide file tree
Showing 13 changed files with 42 additions and 256 deletions.
Empty file.
27 changes: 0 additions & 27 deletions app-server/subprojects/domain_event_api/build.gradle.kts

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

1 change: 0 additions & 1 deletion app-server/subprojects/spring_message/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ dependencies {
val kotlinLoggingVersion: String by project

implementation(projects.stdlib)
implementation(projects.domainEventApi)

implementation("org.springframework.boot:spring-boot-starter-web")
implementation("io.github.microutils:kotlin-logging-jvm:$kotlinLoggingVersion")
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package club.staircrusher.spring_message

import club.staircrusher.stdlib.domain.event.DomainEvent
import org.springframework.context.ApplicationEvent

data class JacksonSerializedSpringEvent<T : DomainEvent>(
val type: Class<T>,
val value: String,
): ApplicationEvent(value)

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
package club.staircrusher.spring_message

import club.staircrusher.domain_event_api.ProtoEventConverter
import club.staircrusher.stdlib.di.annotation.Component
import club.staircrusher.stdlib.domain.event.DomainEventSubscriber
import com.fasterxml.jackson.databind.ObjectMapper
import mu.KotlinLogging
import org.springframework.context.ApplicationListener

@Component
class SpringEventListener(
private val domainEventSubscribers: List<DomainEventSubscriber<*>>,
private val protoEventConverter: ProtoEventConverter,
): ApplicationListener<ProtoSpringEvent> {
private val objectMapper: ObjectMapper,
): ApplicationListener<JacksonSerializedSpringEvent<*>> {
private val logger = KotlinLogging.logger {}

@Suppress("TooGenericExceptionCaught")
override fun onApplicationEvent(springEvent: ProtoSpringEvent) {
val event = protoEventConverter.convertProtoToEvent(springEvent.proto)
override fun onApplicationEvent(springEvent: JacksonSerializedSpringEvent<*>) {
val event = objectMapper.readValue(springEvent.value, springEvent.type)
domainEventSubscribers.forEach {
try {
it(event)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
package club.staircrusher.spring_message

import club.staircrusher.domain_event_api.ProtoEventConverter
import club.staircrusher.stdlib.di.annotation.Component
import club.staircrusher.stdlib.domain.event.DomainEvent
import club.staircrusher.stdlib.domain.event.DomainEventPublisher
import com.fasterxml.jackson.databind.ObjectMapper
import org.springframework.context.ApplicationEventPublisher
import org.springframework.context.ApplicationEventPublisherAware

@Component
class SpringEventPublisher(
private val protoEventConverter: ProtoEventConverter,
private val objectMapper: ObjectMapper,
): ApplicationEventPublisherAware, DomainEventPublisher {
lateinit var eventPublisher: ApplicationEventPublisher

Expand All @@ -18,7 +18,10 @@ class SpringEventPublisher(
}

override suspend fun publishEvent(event: DomainEvent) {
val message = protoEventConverter.convertEventToProto(event)
eventPublisher.publishEvent(ProtoSpringEvent(message))
val value = objectMapper.writeValueAsString(event)
eventPublisher.publishEvent(JacksonSerializedSpringEvent(
type = event.javaClass,
value = value,
))
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package club.staircrusher.spring_web.jackson

import com.fasterxml.jackson.annotation.JsonInclude
import org.springframework.boot.autoconfigure.jackson.Jackson2ObjectMapperBuilderCustomizer
import org.springframework.context.annotation.Bean
import org.springframework.context.annotation.Configuration
import org.springframework.http.converter.json.Jackson2ObjectMapperBuilder


@Configuration(proxyBeanMethods = false)
open class SccJacksonConfig {
@Bean
open fun jsonCustomizer(): Jackson2ObjectMapperBuilderCustomizer? {
return Jackson2ObjectMapperBuilderCustomizer { builder: Jackson2ObjectMapperBuilder ->
builder
.serializationInclusion(JsonInclude.Include.NON_ABSENT)
.failOnUnknownProperties(false)
}
}
}
2 changes: 1 addition & 1 deletion docs/architecture-app-server.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ Bounded context의 경계는 프로젝트가 발전함에 따라 얼마든지

Domain event의 발행과 구독은 아래의 workflow로 작업할 수 있습니다.

1. Domain event 정의 - `domain_event` 모듈과 `domain_event_api` 모듈에서 domain event를 정의합니다. 정의하는 방식은 다른 domain event가 정의된 방식을 참고해 주세요.
1. Domain event 정의 - `domain_event` 모듈에서 domain event를 정의합니다. 정의하는 방식은 다른 domain event가 정의된 방식을 참고해 주세요.
2. Domain event 발행 - `stdlib` 모듈의 `DomainEventPublisher`를 사용해서 domain event를 발행할 수 있습니다.
3. Domain event 구독 - `stdlib` 모듈의 `DomainEventSubscriber`를 사용해서 domain event를 구독할 수 있습니다.

Expand Down

0 comments on commit 7175d73

Please sign in to comment.