yangys
2024-05-07 ec2552d891e163bd9054e0554188afc575bcdb70
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
package com.qianwen.smartman.modules.sync.controller;
 
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import com.qianwen.core.tool.api.R;
import com.qianwen.smartman.modules.sync.message.sse.SseEmitterServer;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.mvc.method.annotation.SseEmitter;
 
@RequestMapping({"/sse"})
@Api(tags = {"SSE"})
@RestController
public class SseEmitterController {
    private final SseEmitterServer sseEmitterServer;
 
    public SseEmitterController(final SseEmitterServer sseEmitterServer) {
        this.sseEmitterServer = sseEmitterServer;
    }
 
    @GetMapping({"/createSseConnect"})
    @CrossOrigin
    @ApiOperation("sse创建连接")
    public SseEmitter createSseConnect(@RequestParam(value = "clientId", required = false) String clientId) {
        return this.sseEmitterServer.createSseConnect(clientId);
    }
 
    @GetMapping({"/closeSseConnect"})
    @CrossOrigin
    @ApiOperation("sse关闭连接")
    public R<Void> closeSseConnect(@RequestParam("clientId") String clientId) {
        this.sseEmitterServer.close(clientId);
        return R.status(Boolean.TRUE.booleanValue());
    }
}