Class NotificationService
java.lang.Object
io.leandev.appfuse.notification.NotificationService
通知子系統的門面
接受 NotificationRequest,解析收件人(RecipientResolver)、
依 type×channel×locale 渲染(NotificationTemplateResolver)、把每則展開的訊息寫入 Outbox
(PENDING),再對每列觸發 fast-path 非同步遞送(NotificationOutboxDispatcher.dispatchAsync(UUID))。
實際遞送與重試由 dispatcher 負責;本服務只到「寫入 Outbox + 觸發」為止。
一般經 NotificationEvent + @TransactionalEventListener(AFTER_COMMIT) 在交易後非同步進入;
不需該語意者亦可直接呼叫 notify(NotificationRequest)。
租戶(ADR-017
決策三):本服務不觸碰租戶欄位——tenant 專案的應用 Outbox entity 帶 @TenantId,寫入時由
Hibernate 於呼叫執行緒(請求 / 交易後同步,context 仍在)自動注入當前租戶;去重查詢
(NotificationOutboxRepositoryBase.findByDedupeKey(String) 單欄)同理自動限縮本租戶。ownership
專案的 entity 無租戶欄位、天然全域。後續非同步遞送再依列重建 context(見 dispatcher)。
- Since:
- 4.0.0
-
Field Summary
Fields -
Constructor Summary
ConstructorsModifierConstructorDescription<T extends NotificationOutboxBase>NotificationService(RecipientResolver recipientResolver, NotificationTemplateResolver templateResolver, NotificationOutboxRepositoryBase<T> outboxRepository, Supplier<T> outboxFactory, NotificationOutboxDispatcher dispatcher, NotificationDeepLinkProvider deepLinkProvider, NotificationPreferenceFilter preferenceFilter, Set<ChannelType> defaultChannels, RetryPolicyResolver retryPolicyResolver, Clock clock) <T extends NotificationOutboxBase>NotificationService(RecipientResolver recipientResolver, NotificationTemplateResolver templateResolver, NotificationOutboxRepositoryBase<T> outboxRepository, Supplier<T> outboxFactory, NotificationOutboxDispatcher dispatcher, NotificationDeepLinkProvider deepLinkProvider, NotificationPreferenceFilter preferenceFilter, Set<ChannelType> defaultChannels, RetryPolicyResolver retryPolicyResolver, Clock clock, TextCipher payloadCipher) 建立具持久化 payload 保護的通知門面。 -
Method Summary
Modifier and TypeMethodDescriptionvoidnotify(NotificationRequest request) 處理一則通知請求:解析 → 渲染 → 寫入 Outbox → 觸發 fast-path 遞送
-
Field Details
-
MODEL_KEY_DEEP_LINK
-
STANDALONE_DEDUPE_PREFIX
「每列自成一鍵」去重值的前綴——標示該列由呼叫端未提供dedupeKey而自動填入(見newStandaloneDedupeKey())。前綴使這類列在 DB 中一眼可辨,且不會與顯式去重鍵 (形如{key}:{CHANNEL}:{addressHash})相撞。- See Also:
-
-
Constructor Details
-
NotificationService
public <T extends NotificationOutboxBase> NotificationService(RecipientResolver recipientResolver, NotificationTemplateResolver templateResolver, NotificationOutboxRepositoryBase<T> outboxRepository, Supplier<T> outboxFactory, NotificationOutboxDispatcher dispatcher, NotificationDeepLinkProvider deepLinkProvider, NotificationPreferenceFilter preferenceFilter, Set<ChannelType> defaultChannels, RetryPolicyResolver retryPolicyResolver, Clock clock) - Type Parameters:
T- 應用宣告的具體 Outbox entity(繼承NotificationOutboxBase)- Parameters:
recipientResolver- 收件人解析 SPItemplateResolver- 範本解析 SPIoutboxRepository- Outbox repository(應用宣告的具體型別)outboxFactory- Outbox entity 工廠(通常為具體類的建構子參考;ADR-017——jar 不 擁有具體 entity,無從new)dispatcher- Outbox 遞送器deepLinkProvider- 每收件人深連結 SPI(選用,可為 null;見NotificationDeepLinkProvider)preferenceFilter- 通知偏好過濾 SPI(選用,可為 null;null 視同全部啟用,見NotificationPreferenceFilter)defaultChannels-NotificationRequest未指定通道時的預設(通常{EMAIL})retryPolicyResolver- 依型別解析重試政策;建列時取RetryPolicy.maxAttempts寫入該列maxAttempts(無 per-type 差異者用RetryPolicyResolver.constant(RetryPolicy))clock- 建立 Outbox 時間點的應用時鐘
-
NotificationService
public <T extends NotificationOutboxBase> NotificationService(RecipientResolver recipientResolver, NotificationTemplateResolver templateResolver, NotificationOutboxRepositoryBase<T> outboxRepository, Supplier<T> outboxFactory, NotificationOutboxDispatcher dispatcher, NotificationDeepLinkProvider deepLinkProvider, NotificationPreferenceFilter preferenceFilter, Set<ChannelType> defaultChannels, RetryPolicyResolver retryPolicyResolver, Clock clock, TextCipher payloadCipher) 建立具持久化 payload 保護的通知門面。- Parameters:
payloadCipher- 已渲染 subject、body 與 deep link 的 purpose-scoped cipher
-
-
Method Details
-
notify
處理一則通知請求:解析 → 渲染 → 寫入 Outbox → 觸發 fast-path 遞送- Parameters:
request- 通知請求
-