Skip to content

Commit f29d566

Browse files
committed
remove workflow and saga state comments
1 parent 1dc8009 commit f29d566

4 files changed

Lines changed: 1 addition & 48 deletions

File tree

common/src/main/java/com/example/common/enums/SagaStep.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ public enum SagaStep {
1010
COMPLETED,
1111
FAILED,
1212

13-
// Compensating steps (Phase 4)
13+
// Compensating steps
1414
RELEASE_INVENTORY,
1515
REFUND_PAYMENT,
1616
CANCEL_ORDER

orchestrator/src/main/java/com/example/orchestrator/messaging/KafkaConsumerConfig.java

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,6 @@
1717
import com.fasterxml.jackson.databind.ObjectMapper;
1818
import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule;
1919

20-
/**
21-
* Kafka consumer configuration for orchestrator.
22-
*
23-
* <p>Orchestrator consumes worker events (inventory.events, payment.events, order.events) to
24-
* advance saga state.
25-
*
26-
* <p>Consumer group: orchestrator-group Acknowledgment mode: MANUAL (commit after successful
27-
* processing) Concurrency: 1 per topic (can increase for higher throughput)
28-
*/
2920
@Configuration
3021
public class KafkaConsumerConfig {
3122

orchestrator/src/main/java/com/example/orchestrator/service/CheckoutOrchestrator.java

Lines changed: 0 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -36,12 +36,10 @@ public class CheckoutOrchestrator {
3636

3737
@Transactional
3838
public UUID startCheckout(StartCheckoutRequest request) {
39-
// Create saga in STARTED state
4039
Saga saga = sagaStateService.createSaga(request.getCustomerId(), maxRetries);
4140
log.info(
4241
"[saga={}] Checkout started for customer={}", saga.getSagaId(), request.getCustomerId());
4342

44-
// Store original request payload as JSON for future steps
4543
try {
4644
String requestJson = objectMapper.writeValueAsString(request);
4745
saga.setRequestPayload(requestJson);
@@ -54,22 +52,16 @@ public UUID startCheckout(StartCheckoutRequest request) {
5452
"Failed to serialize request payload for saga=" + saga.getSagaId(), e);
5553
}
5654

57-
// Publish RESERVE_INVENTORY command
5855
publishCommand(saga.getSagaId(), CommandType.RESERVE_INVENTORY, request);
5956

6057
return saga.getSagaId();
6158
}
6259

63-
/** Get the current state of a saga. */
6460
@Transactional(readOnly = true)
6561
public Saga getStatus(UUID sagaId) {
6662
return sagaRepository.findById(sagaId).orElseThrow(() -> new SagaNotFoundException(sagaId));
6763
}
6864

69-
/**
70-
* Handle InventoryReservedEvent from inventory.events topic. Advance saga to AUTHORIZE_PAYMENT
71-
* and publish payment command.
72-
*/
7365
@Transactional
7466
public void handleInventoryReserved(UUID sagaId, UUID reservationId) {
7567
log.info(
@@ -80,7 +72,6 @@ public void handleInventoryReserved(UUID sagaId, UUID reservationId) {
8072
Saga saga =
8173
sagaRepository.findById(sagaId).orElseThrow(() -> new SagaNotFoundException(sagaId));
8274

83-
// Idempotency check: only process if still on RESERVE_INVENTORY step
8475
if (saga.getCurrentStep() != SagaStep.RESERVE_INVENTORY) {
8576
log.info(
8677
"[saga={}] Already past step {}, skipping (idempotency)",
@@ -89,18 +80,12 @@ public void handleInventoryReserved(UUID sagaId, UUID reservationId) {
8980
return;
9081
}
9182

92-
// Advance saga state
9383
sagaStateService.advanceStep(sagaId, SagaStep.AUTHORIZE_PAYMENT);
9484

95-
// Publish AUTHORIZE_PAYMENT command (need to reconstruct request - stored in saga or outbox)
9685
StartCheckoutRequest request = buildRequestFromSaga(saga);
9786
publishCommand(sagaId, CommandType.AUTHORIZE_PAYMENT, request);
9887
}
9988

100-
/**
101-
* Handle PaymentAuthorizedEvent from payment.events topic. Advance saga to CREATE_ORDER and
102-
* publish order command.
103-
*/
10489
@Transactional
10590
public void handlePaymentAuthorized(UUID sagaId, UUID paymentId) {
10691
log.info(
@@ -109,7 +94,6 @@ public void handlePaymentAuthorized(UUID sagaId, UUID paymentId) {
10994
Saga saga =
11095
sagaRepository.findById(sagaId).orElseThrow(() -> new SagaNotFoundException(sagaId));
11196

112-
// Idempotency check: only process if still on AUTHORIZE_PAYMENT step
11397
if (saga.getCurrentStep() != SagaStep.AUTHORIZE_PAYMENT) {
11498
log.info(
11599
"[saga={}] Already past step {}, skipping (idempotency)",
@@ -118,35 +102,29 @@ public void handlePaymentAuthorized(UUID sagaId, UUID paymentId) {
118102
return;
119103
}
120104

121-
// Record payment ID
122105
sagaStateService.recordPayment(sagaId, paymentId);
123106
sagaStateService.advanceStep(sagaId, SagaStep.CREATE_ORDER);
124107

125-
// Publish CREATE_ORDER command
126108
StartCheckoutRequest request = buildRequestFromSaga(saga);
127109
publishCommand(sagaId, CommandType.CREATE_ORDER, request);
128110
}
129111

130-
/** Handle OrderCreatedEvent from order.events topic. Mark saga as COMPLETED. */
131112
@Transactional
132113
public void handleOrderCreated(UUID sagaId, UUID orderId) {
133114
log.info("[saga={}] Order created orderId={}, marking COMPLETED", sagaId, orderId);
134115

135116
Saga saga =
136117
sagaRepository.findById(sagaId).orElseThrow(() -> new SagaNotFoundException(sagaId));
137118

138-
// Idempotency check: only process if still on CREATE_ORDER step
139119
if (saga.getCurrentStep() != SagaStep.CREATE_ORDER) {
140120
log.info(
141121
"[saga={}] Already past step {}, skipping (idempotency)", sagaId, SagaStep.CREATE_ORDER);
142122
return;
143123
}
144124

145-
// Mark saga completed
146125
sagaStateService.completeSaga(sagaId, orderId);
147126
}
148127

149-
/** Publish a command to checkout.commands topic with sagaId as partition key. */
150128
private void publishCommand(UUID sagaId, CommandType commandType, StartCheckoutRequest request) {
151129
CheckoutCommand command = new CheckoutCommand();
152130
command.setSagaId(sagaId);
@@ -171,12 +149,6 @@ private void publishCommand(UUID sagaId, CommandType commandType, StartCheckoutR
171149
}
172150
}
173151

174-
/**
175-
* Reconstruct StartCheckoutRequest from saga state.
176-
*
177-
* <p>Deserializes the original request from saga.requestPayload. Falls back to hardcoded test
178-
* data if payload is missing (for backwards compatibility with old sagas).
179-
*/
180152
private StartCheckoutRequest buildRequestFromSaga(Saga saga) {
181153
// Try to deserialize from stored payload
182154
if (saga.getRequestPayload() != null) {
@@ -194,7 +166,6 @@ private StartCheckoutRequest buildRequestFromSaga(Saga saga) {
194166
saga.getSagaId());
195167
}
196168

197-
// FALLBACK: Use hardcoded test data (for backwards compatibility)
198169
StartCheckoutRequest request = new StartCheckoutRequest();
199170
request.setCustomerId(saga.getCustomerId());
200171

order-worker/src/main/java/com/example/order/service/OrderService.java

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,6 @@
1616
import lombok.RequiredArgsConstructor;
1717
import lombok.extern.slf4j.Slf4j;
1818

19-
/**
20-
* Real order creation logic.
21-
*
22-
* <p>IDEMPOTENCY: If an order already exists for this sagaId, return the existing orderId without
23-
* creating a duplicate record.
24-
*
25-
* <p>FAILURE SCENARIOS: customerId "cust_error" → TransientWorkerException (simulate DB issue) Same
26-
* sagaId twice → idempotency returns existing orderId
27-
*/
2819
@Slf4j
2920
@Service
3021
@RequiredArgsConstructor

0 commit comments

Comments
 (0)