648540858
2021-01-21 2c47c8c86b0a685e92b0a605ae6f96901cf10555
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
package com.genersoft.iot.vmp.vmanager.SEEController;
 
import com.genersoft.iot.vmp.gb28181.event.alarm.AlarmEventListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.mvc.method.annotation.SseEmitter;
 
/**
 * @description: SSE推送
 * @author: lawrencehj
 * @data: 2021-01-20
 */
 
@Controller
@RequestMapping("/api")
public class SEEController {
    @Autowired 
    AlarmEventListener alarmEventListener;
    
       //设置响应
    @RequestMapping("/emit")
    public SseEmitter emit() {
        SseEmitter sseEmitter = new SseEmitter(0L);
        try {
            alarmEventListener.addSseEmitters(sseEmitter);
        }catch (Exception e){
            sseEmitter.completeWithError(e);
        }
        return sseEmitter;
    }
}