Using events

Events, as you may know, are runtime incidents that you do care about. CDI provides a loosely coupled model, following the observer design pattern, which allows you to fire an event from a CDI bean, and handling the event from one or more other CDI beans. The key advantages of the CDI events model are:

  • Event producers and observers are decoupled from each other
  • Observers can define selectors to limit the set of events they consume
  • Observers are aware of database transactions and can consume events according to transaction states

In our booking application, we are going to use events in order to notify end users by email with either the success or failure of their booking operations, without tightly coupling the mailing code ...

Get Developing Middleware in Java EE 8 now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.