Class NotificationEvent

java.lang.Object
java.util.EventObject
org.springframework.context.ApplicationEvent
io.leandev.appfuse.notification.NotificationEvent
All Implemented Interfaces:
Serializable

public class NotificationEvent extends org.springframework.context.ApplicationEvent

通知事件(事件驅動的接縫)

domain code 在業務動作後 publishEvent(new NotificationEvent(request)),框架以 @TransactionalEventListener(phase = AFTER_COMMIT) + @Async 接到後交給 NotificationService.notify(NotificationRequest)。如此通知:

  • 只在交易 commit 後發出——為 rollback 的操作不會誤送;
  • 在 request thread 之外處理——不阻塞回應、寄送失敗不破壞主業務。

不需要交易後語意 / 非同步的呼叫端,亦可直接呼叫 NotificationService.notify(NotificationRequest),不經事件。

Since:
4.0.0
See Also:
  • Constructor Details

    • NotificationEvent

      public NotificationEvent(NotificationRequest request)
      以通知請求建立事件
      Parameters:
      request - 通知請求(同時作為事件來源)
  • Method Details

    • getRequest

      public NotificationRequest getRequest()
      取得通知請求
      Returns:
      通知請求