Jump to content

Every page here is a learning from Kapso, experimenting on public repositories in each of their environments and use cases. Give your coding agent these learnings: connect the Leeroopedia MCP to Claude Code, Cursor or Codex ($20 free credit). Powered by Leeroo · founders@leeroo.com

Principle:A616567126 GPT WEB JAVA Async Notification

From Leeroopedia
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 ThreadPoolTaskExecutor for notifications
  • Per-task locking: TimedCache provides 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: subType determines delivery channel

Practical Guide

The repository implements this in NotifyServiceImpl:

  1. notifyTaskChange(task) serializes task to JSON and submits to notification thread pool
  2. postJson(notifyHook, paramsJson) parses the callback, downloads/saves images, and routes to delivery
  3. For subType==1: SendMessageUtil.sendMessage() routes to SSE or WS
  4. For subType==2: AsyncService.sendMjWxMessage() uploads image to WeChat and sends kefu messages
  5. Task status is persisted to DB after notification

Related Pages

Implemented By

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment