Java Reference
In-Depth Information
ticketService.bookSeat(seatId);
final FacesMessage m =
new FacesMessage(FacesMessage.SEVERITY_INFO,
"Registered!",
"Registration successful");
facesContext.addMessage(null, m);
logger.info("Seat booked.");
money = money - price;
bookingQueueProducer.sendMessage("[JMS Message]
User registered seat " + seatId);
}
// Some code
}
From JMS 2.0, messages can be sent asynchronously, but then it is important to control
whether the operations are successful or not. To do this, we have to create an object that
implements the CompletionListener interface, as follows:
@ApplicationScoped
public class BookingCompletionListener implements
CompletionListener {
@Inject
private Logger logger;
@Override
public void onCompletion(Message message) {
try {
final String text =
message.getBody(String.class);
logger.info("Send was successful: " + text));
} catch (Throwable e) {
logger.severe("Problem with message format");
}
Search WWH ::




Custom Search