# Step 1: Create saga topics
kafka-topics.sh --create --topic saga-events --bootstrap-server localhost:9092 --partitions 3 --replication-factor 1
kafka-topics.sh --create --topic saga-compensation --bootstrap-server localhost:9092 --partitions 3 --replication-factor 1
# Step 2: Publish order-created event
echo '{"order_id":"ORD-001","step":"order-created","status":"success"}' | kafka-console-producer.sh --bootstrap-server localhost:9092 --topic saga-events
# Step 3: Consume and verify
kafka-console-consumer.sh --bootstrap-server localhost:9092 --topic saga-events --from-beginning --max-messages 1
# Step 4: Simulate payment failure - publish compensation
echo '{"order_id":"ORD-001","step":"payment-failed","action":"rollback-order"}' | kafka-console-producer.sh --bootstrap-server localhost:9092 --topic saga-compensation
# Step 5: Verify compensation event
kafka-console-consumer.sh --bootstrap-server localhost:9092 --topic saga-compensation --from-beginning --max-messages 1This demonstrates a simplified saga flow: creating coordination topics, publishing an order event, simulating a payment failure, and publishing a compensation event for rollback.