Skip to content

Events: Transactional Observers #15

Description

@hendryluk

Expanding on #7

CDI spec allows you to specify that a particular observer should receive event notifications during the before or after completion phase of the transaction in which the event was raised. I.e. it defers the notifications of an event until the intended phase of the transaction has been reached (as opposed to the current implementation that only allows immediate notifications).
Ref: https://docs.jboss.org/weld/reference/latest/en-US/html/events.html#_transactional_observers

Supported options are:

  • IN_PROGRESS
  • AFTER_SUCCESS
  • AFTER_FAILURE
  • AFTER_COMPLETION
  • BEFORE_COMPLETION

Example

public void OnLoggedIn([Observes(During=TransactionPhase.AfterSuccess)] LoggedIn evt)
{
   /* handles */
}

This is important e.g. in scenario where you want to send an outbound customer email only after the transaction has been successfully committed.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions