Skip to content

Commit 840d59c

Browse files
committed
CAMEL-21958: camel-core: Java DSL. Fix endChoice() to reuse end() and scope to current/nearest choice.
1 parent 8b82bd6 commit 840d59c

File tree

1 file changed

+16
-19
lines changed
  • saga/saga-payment-service/src/main/java/org/apache/camel/example/saga

1 file changed

+16
-19
lines changed

saga/saga-payment-service/src/main/java/org/apache/camel/example/saga/PaymentRoute.java

Lines changed: 16 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -26,26 +26,23 @@ public class PaymentRoute extends RouteBuilder {
2626

2727
@Override
2828
public void configure() throws Exception {
29-
30-
from("jms:queue:{{example.services.payment}}")
31-
.routeId("payment-service")
32-
.saga()
33-
.propagation(SagaPropagation.MANDATORY)
34-
.option("id", header("id"))
35-
.compensation("direct:cancelPayment")
36-
.log("Paying ${header.payFor} for order #${header.id}")
37-
.setBody(header("JMSCorrelationID"))
38-
.choice()
39-
.when(x -> Math.random() >= 0.85)
40-
.log("Payment ${header.payFor} for saga #${header.id} fails!")
41-
.throwException(new RuntimeException("Random failure during payment"))
42-
.endChoice()
43-
.end()
44-
.log("Payment ${header.payFor} done for order #${header.id} with payment transaction ${body}")
45-
.end();
29+
from("jms:queue:{{example.services.payment}}")
30+
.routeId("payment-service")
31+
.saga()
32+
.propagation(SagaPropagation.MANDATORY)
33+
.option("id", header("id"))
34+
.compensation("direct:cancelPayment")
35+
.log("Paying ${header.payFor} for order #${header.id}")
36+
.setBody(header("JMSCorrelationID"))
37+
.choice()
38+
.when(x -> Math.random() >= 0.85)
39+
.log("Payment ${header.payFor} for saga #${header.id} fails!")
40+
.throwException(new RuntimeException("Random failure during payment"))
41+
.end()
42+
.log("Payment ${header.payFor} done for order #${header.id} with payment transaction ${body}");
4643

4744
from("direct:cancelPayment")
48-
.routeId("payment-cancel")
49-
.log("Payment for order #${header.id} has been cancelled");
45+
.routeId("payment-cancel")
46+
.log("Payment for order #${header.id} has been cancelled");
5047
}
5148
}

0 commit comments

Comments
 (0)