in generic-examples/saga/Payment.java [25:49]
public void configure() throws Exception {
LRASagaService service = new LRASagaService();
service.setCoordinatorUrl("http://lra-coordinator");
service.setLocalParticipantUrl("http://payment");
getContext().addService(service);
rest("/api/").post("/pay")
.param().type(RestParamType.query).name("type").required(true).endParam()
.param().type(RestParamType.header).name("id").required(true).endParam()
.to("direct:pay");
from("direct:pay")
.saga()
.propagation(SagaPropagation.MANDATORY)
.option("id", header("id"))
.compensation("direct:cancelPayment")
.log("Paying ${header.type} for order #${header.id}")
.choice()
.when(x -> Math.random() >= 0.85)
.throwException(new RuntimeException("Random failure during payment"))
.end();
from("direct:cancelPayment")
.log("Payment #${header.id} has been cancelled");
}