Principle:A616567126 GPT WEB JAVA Async Notification
| Knowledge Sources | |
|---|---|
| Domains | Event_Driven_Architecture, Notifications |
| Last Updated | 2026-10-13 00:00 GMT |
Overview
Pattern that asynchronously delivers task status changes to interested parties via webhook callbacks, SSE/WS push, or WeChat kefu messages, depending on the delivery channel.
Description
Async notification is an event-driven pattern where task state changes (START → IN_PROGRESS → SUCCESS/FAILURE) trigger notifications to the requesting client. The notification mechanism is selected based on the task's subType:
subType=1(web client): Push via SSE (SseEmitterServer) or WebSocket (WebSocketServer)subType=2(WeChat bot): Push via WeChat kefu message (WxMpKefuMessage)
The notification is dispatched asynchronously via a dedicated thread pool to avoid blocking the WSS event processing thread.
Usage
Use this principle when:
- Delivering asynchronous task results to different client types
- Needing channel-specific delivery (web vs. WeChat vs. webhook)
- Requiring non-blocking notification dispatch
Theoretical Basis
Event-Driven Notification:
# Abstract algorithm (NOT real implementation)
def notify_task_change(task):
if task.notify_hook is blank:
return
# Serialize task to JSON
params = serialize(task)
# Dispatch asynchronously
async_execute(lambda: post_and_deliver(task.notify_hook, params))
def post_and_deliver(hook, params_json):
task = parse(params_json)
if task.status == SUCCESS:
if task.sub_type == 2: # WeChat
send_wechat_kefu_image(task)
send_wechat_kefu_text(task)
else: # Web
push_sse_or_ws(task.user_id, task)
update_db(task)
Key Properties:
- Thread pool isolation: Separate
ThreadPoolTaskExecutorfor notifications - Per-task locking:
TimedCacheprovides per-task locks to serialize notifications for the same task - Image processing: On success, image is downloaded from Discord URL, base64-decoded, and saved locally
- Channel routing:
subTypedetermines delivery channel
Practical Guide
The repository implements this in NotifyServiceImpl:
notifyTaskChange(task)serializes task to JSON and submits to notification thread poolpostJson(notifyHook, paramsJson)parses the callback, downloads/saves images, and routes to delivery- For
subType==1:SendMessageUtil.sendMessage()routes to SSE or WS - For
subType==2:AsyncService.sendMjWxMessage()uploads image to WeChat and sends kefu messages - Task status is persisted to DB after notification