From 9789c55ef944ffdbfd7b2bdaf9d2a210f6572a32 Mon Sep 17 00:00:00 2001 From: Lawrence <1934378145@qq.com> Date: Wed, 20 Jan 2021 20:42:58 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0SSE=E5=89=8D=E7=AB=AF?= =?UTF-8?q?=E6=8E=A8=E9=80=81=E6=94=AF=E6=8C=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../vmanager/SEEController/SEEController.java | 32 +++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 src/main/java/com/genersoft/iot/vmp/vmanager/SEEController/SEEController.java diff --git a/src/main/java/com/genersoft/iot/vmp/vmanager/SEEController/SEEController.java b/src/main/java/com/genersoft/iot/vmp/vmanager/SEEController/SEEController.java new file mode 100644 index 00000000..689b967b --- /dev/null +++ b/src/main/java/com/genersoft/iot/vmp/vmanager/SEEController/SEEController.java @@ -0,0 +1,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; + } +}