merge: PR #21을 합친 검사 브랜치에 넣는다
This commit is contained in:
@@ -27,6 +27,8 @@ Kafka ─▶ platform consumer (starter-kafka)
|
||||
- `IdempotentConsumer.TransactionRunner`(애플리케이션 `PlatformTransactionManager` 위의
|
||||
`TransactionTemplate`). inbox 예약과 use case의 JPA 쓰기가 한 트랜잭션에서 함께 커밋되거나 함께
|
||||
롤백된다. handler가 실패하면 예약도 롤백되어 재전달이 효과를 다시 적용한다.
|
||||
이 트랜잭션은 30초 상한(`TransactionPort` 쓰기와 같은 값)으로 열린다. handler의 유스케이스 `inWrite`는 이
|
||||
트랜잭션에 합류해 자기 상한을 쓰지 않으므로, 막힌 문장이나 잠금 대기는 이 상한에서 끊긴다.
|
||||
- platform starter(`MessagingReliabilityAutoConfiguration`)가 이 두 bean으로 `IdempotentConsumer`를
|
||||
만든다. platform은 애플리케이션의 datasource·트랜잭션을 스스로 고르지 않는다는 기존 설계를 그대로 둔다.
|
||||
- 애플리케이션의 handler(`MessageHandler<T>` 구현)는 이 leaf에 둔다. 컨트롤러가 HTTP 요청을 use case
|
||||
|
||||
+10
@@ -68,12 +68,22 @@ public class MessagingInboxAutoConfiguration {
|
||||
return new MessagingInboxSchemaStream(dataSource);
|
||||
}
|
||||
|
||||
/**
|
||||
* The upper bound on one delivery's transaction, in whole seconds: the same 30 s as one {@code
|
||||
* TransactionPort} write ({@code app.persistence-jpa.transaction.write-timeout}). The handler's
|
||||
* use case joins this transaction, and a joined {@code inWrite} leaves the deadline to the call
|
||||
* that began it, so without one here a blocked statement or lock wait held the connection and the
|
||||
* partition for as long as it lasted (review 2026-11-12).
|
||||
*/
|
||||
static final int TRANSACTION_TIMEOUT_SECONDS = 30;
|
||||
|
||||
/** Runs the inbox reservation and the handler in one application transaction. */
|
||||
@Bean
|
||||
@ConditionalOnMissingBean(IdempotentConsumer.TransactionRunner.class)
|
||||
public IdempotentConsumer.TransactionRunner messagingInboxTransactions(
|
||||
PlatformTransactionManager transactionManager) {
|
||||
TransactionTemplate template = new TransactionTemplate(transactionManager);
|
||||
template.setTimeout(TRANSACTION_TIMEOUT_SECONDS);
|
||||
return new IdempotentConsumer.TransactionRunner() {
|
||||
@Override
|
||||
public <T> T inTransaction(java.util.function.Supplier<T> work) {
|
||||
|
||||
+23
-1
@@ -164,6 +164,25 @@ class MessagingInboxAutoConfigurationTest {
|
||||
assertThat(transactions.outcomes).containsExactly("commit", "rollback");
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("트랜잭션 runner는 TransactionPort 쓰기와 같은 30초 상한으로 트랜잭션을 연다")
|
||||
void theRunnerOpensItsTransactionWithTheWriteTimeout() {
|
||||
// given
|
||||
RecordingTransactions transactions = new RecordingTransactions();
|
||||
IdempotentConsumer.TransactionRunner runner =
|
||||
new MessagingInboxAutoConfiguration().messagingInboxTransactions(transactions);
|
||||
|
||||
// when
|
||||
runner.inTransaction(() -> "applied");
|
||||
|
||||
// then
|
||||
assertThat(transactions.timeouts)
|
||||
.as(
|
||||
"the handler's use case joins this transaction, and a joined inWrite leaves the deadline"
|
||||
+ " to the call that began it")
|
||||
.containsExactly(30);
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("같은 메시지가 두 번 전달돼도 handler의 부작용은 한 번만 일어난다")
|
||||
void theSameMessageDeliveredTwiceRunsTheSideEffectOnce() {
|
||||
@@ -232,6 +251,7 @@ class MessagingInboxAutoConfigurationTest {
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
private final transient List<String> outcomes = new ArrayList<>();
|
||||
private final transient List<Integer> timeouts = new ArrayList<>();
|
||||
|
||||
@Override
|
||||
protected Object doGetTransaction() {
|
||||
@@ -239,7 +259,9 @@ class MessagingInboxAutoConfigurationTest {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void doBegin(Object transaction, TransactionDefinition definition) {}
|
||||
protected void doBegin(Object transaction, TransactionDefinition definition) {
|
||||
timeouts.add(definition.getTimeout());
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void doCommit(DefaultTransactionStatus status) {
|
||||
|
||||
Reference in New Issue
Block a user