Created
March 23, 2024 22:47
-
-
Save paulparkinson/b69d3535cebd5085aa1bc16e3a560f18 to your computer and use it in GitHub Desktop.
Airline implementation of Oracle Database SagaParticipant
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Participant(name = "Airline") | |
/* @Participant declares the participant’s name to the saga framework */ | |
public class Airline extends SagaParticipant { | |
/* Airline extends the SagaParticipant class */ | |
@Request(sender = "TravelAgency") | |
/* The @Request annotates the method that handles incoming request from a given | |
sender, in this example the TravelAgency */ | |
public String handleTravelAgencyRequest(SagaMessageContext | |
info) { | |
/* Perform all DML with this connection to ensure | |
everything is in a single transaction */ | |
FlightService fs = new | |
FlightService(info.getConnection()); | |
fs.bookFlight(info.getPayload(), info.getSagaId()); | |
return response; | |
/* Local commit is automatically performed by the saga framework. | |
The response is returned to the initiator */ | |
} | |
@Compensate | |
/* @Compensate annotates the method automatically called to roll back a saga */ | |
public void compensate(SagaMessageContext info) { | |
fs.deleteBooking(info.getPayload(), | |
info.getSagaId()); | |
} | |
@Complete | |
/* @Complete annotates the method automatically called to commit a saga */ | |
public void complete(SagaMessageContext info) { | |
fs.sendConfirmation(info.getSagaId()); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment