Skip to content

Commit c270c7a

Browse files
committed
fix: DeadLetterEventPublisher가 TraceId를 세팅하도록 수정한다
1 parent d747f2c commit c270c7a

File tree

2 files changed

+26
-12
lines changed

2 files changed

+26
-12
lines changed
Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,28 @@
11
package org.gitanimals.supports.deadletter
22

3+
import org.gitanimals.core.IdGenerator
4+
import org.gitanimals.core.filter.MDCFilter.Companion.TRACE_ID
35
import org.rooftop.netx.api.SagaEvent
46
import org.rooftop.netx.spi.DeadLetterListener
7+
import org.slf4j.MDC
58
import org.springframework.context.ApplicationEventPublisher
69

710
class DeadLetterEventPublisher(
811
private val applicationEventPublisher: ApplicationEventPublisher,
912
) : DeadLetterListener {
1013

1114
override fun listen(deadLetterId: String, sagaEvent: SagaEvent) {
12-
applicationEventPublisher.publishEvent(
13-
DeadLetterEvent(
14-
deadLetterId = deadLetterId,
15-
sagaEvent = sagaEvent,
15+
runCatching {
16+
MDC.put(TRACE_ID, IdGenerator.generate().toString())
17+
applicationEventPublisher.publishEvent(
18+
DeadLetterEvent(
19+
deadLetterId = deadLetterId,
20+
sagaEvent = sagaEvent,
21+
)
1622
)
17-
)
23+
}.also {
24+
MDC.remove(TRACE_ID)
25+
}
1826
}
1927
}
2028

src/main/kotlin/org/gitanimals/supports/deadletter/DeadLetterTestController.kt

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package org.gitanimals.supports.deadletter
22

3+
import org.gitanimals.core.TraceIdContextOrchestrator
4+
import org.gitanimals.core.TraceIdContextRollback
35
import org.rooftop.netx.api.OrchestratorFactory
46
import org.springframework.web.bind.annotation.GetMapping
57
import org.springframework.web.bind.annotation.RequestParam
@@ -17,21 +19,25 @@ class DeadLetterTestController(
1719
) {
1820
val orchestrator = orchestratorFactory.create<String>("dead-letter-test")
1921
.startWithContext(
20-
contextOrchestrate = { _, it -> it },
21-
contextRollback = { _, it ->
22+
contextOrchestrate = TraceIdContextOrchestrator { _, it -> it },
23+
contextRollback = TraceIdContextRollback { _, it ->
2224
it
2325
}
2426
)
2527
.joinWithContext(
26-
contextOrchestrate = { _, it -> it },
27-
contextRollback = { _, it ->
28+
contextOrchestrate = TraceIdContextOrchestrator { _, it -> it },
29+
contextRollback = TraceIdContextRollback { _, it ->
2830
throw IllegalStateException("add dead letter")
2931
}
3032
)
31-
.commitWithContext { _, _ ->
33+
.commitWithContext(TraceIdContextOrchestrator { _, _ ->
3234
throw IllegalStateException("test dead-letter")
33-
}
35+
})
3436

35-
orchestrator.sagaSync(message, context = mapOf("hello" to "world"))
37+
val result = orchestrator.sagaSync(message, context = mapOf("hello" to "world"))
38+
39+
if (result.isSuccess.not()) {
40+
result.throwError()
41+
}
3642
}
3743
}

0 commit comments

Comments
 (0)