Implementation:A616567126 GPT WEB JAVA NotifyServiceImpl
| 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) orAsyncService.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
- Principle:A616567126_GPT_WEB_JAVA_Async_Notification
- Principle:A616567126_GPT_WEB_JAVA_Multi_Channel_Message_Delivery