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

Implementation:A616567126 GPT WEB JAVA NotifyServiceImpl

From Leeroopedia
Knowledge Sources
Domains Notifications, Event_Driven_Architecture
Last Updated 2026-10-13 00:00 GMT

Overview

Concrete tool for asynchronously notifying clients of Midjourney task status changes via SSE/WS push or WeChat kefu messages, provided by the Spring framework.

Description

The NotifyServiceImpl class implements the NotifyService interface. When a task changes status (START, IN_PROGRESS, SUCCESS, FAILURE), notifyTaskChange() serializes the task to JSON and submits it to a dedicated thread pool. The async postJson() method:

  • Parses the callback as MjCallBack
  • On SUCCESS: downloads the image from Discord, saves it locally via FileUtil.base64ToImage()
  • Routes to SendMessageUtil.sendMessage() (subType=1, web client) or AsyncService.sendMjWxMessage() (subType=2, WeChat)
  • Updates the task's imageUrl and status in the database

Per-task locks (via TimedCache) serialize notifications for the same task ID.

Usage

Import this service when you need to:

  • Notify clients of MJ task progress/completion
  • Route task results to web vs WeChat delivery channels
  • Download and save Discord images locally

Code Reference

Source Location

  • Repository: GPT-WEB-JAVA
  • File: src/main/java/com/intelligent/bot/service/mj/impl/NotifyServiceImpl.java

Signature

@Service
public class NotifyServiceImpl implements NotifyService {
    @Override
    public void notifyTaskChange(Task task);

    private void postJson(String notifyHook, String paramsJson) throws WxErrorException, IOException;
}

Import

import com.intelligent.bot.service.mj.NotifyService;

I/O Contract

Inputs

Name Type Required Description
task Task Yes Task with status, imageUrl, userId, subType, action

Outputs

Name Type Description
(side effect) void Image saved locally; message pushed to client; task updated in DB

Usage Examples

Task Status Notification

// Called by DiscordInstanceImpl.saveAndNotify()
notifyService.notifyTaskChange(task);
// Serializes task, submits to thread pool
// postJson downloads image, routes by subType

Delivery Routing

// In postJson():
if (mjTask.getSubType() == 2) {
    // WeChat delivery
    asyncService.sendMjWxMessage(task);  // IMAGE + TEXT kefu messages
} else {
    // Web delivery
    SendMessageUtil.sendMessage(mjTask.getUserId(), mjTask);  // SSE or WS
}
// Task imageUrl updated to local path, saved to DB

Related Pages

Implements Principle

Requires Environment

Page Connections

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