package cn.gistack.alerts.sse.controller;
|
|
import cn.gistack.alerts.sse.server.SSEServer;
|
import cn.gistack.alerts.sse.vo.SseVO;
|
import lombok.extern.slf4j.Slf4j;
|
import org.springframework.web.bind.annotation.*;
|
import org.springframework.web.servlet.mvc.method.annotation.SseEmitter;
|
|
@Slf4j
|
@RestController
|
@CrossOrigin
|
@RequestMapping("/sse/sse")
|
public class SSEController {
|
|
/**
|
* 建立连接
|
* @param sse
|
* @return
|
*/
|
@GetMapping("/connect")
|
public SseEmitter connect(SseVO sse){
|
return SSEServer.connect(sse.getType() + ":" + sse.getUserId());
|
}
|
|
/**
|
* 发送消息
|
* @throws InterruptedException
|
*/
|
@GetMapping("/process")
|
public void sendMessage() throws InterruptedException {
|
SSEServer.sendMessage("web:123","hello!");
|
// for(int i=0; i<=100; i++){
|
// if(i>50&&i<70){
|
// Thread.sleep(500L);
|
// }else{
|
// Thread.sleep(100L);
|
// }
|
// SSEServer.batchSendMessage(String.valueOf(i));
|
// }
|
}
|
}
|