You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
36 lines
1.1 KiB
36 lines
1.1 KiB
package xyz.wbsite.mcp.basic;
|
|
|
|
import jakarta.annotation.Resource;
|
|
import org.slf4j.Logger;
|
|
import org.slf4j.LoggerFactory;
|
|
import org.springframework.http.MediaType;
|
|
import org.springframework.web.bind.annotation.GetMapping;
|
|
import org.springframework.web.bind.annotation.RequestMapping;
|
|
import org.springframework.web.bind.annotation.RestController;
|
|
import org.springframework.web.servlet.mvc.method.annotation.SseEmitter;
|
|
|
|
/**
|
|
* SSE控制器类
|
|
* 用于处理SSE连接请求和事件发送
|
|
*
|
|
* @author wangbing
|
|
*/
|
|
@RestController
|
|
@RequestMapping("/mcp/sse")
|
|
public class SseController {
|
|
|
|
private static final Logger log = LoggerFactory.getLogger(SseController.class);
|
|
|
|
@Resource
|
|
private SseBroadcaster broadcaster;
|
|
|
|
@GetMapping(produces = MediaType.TEXT_EVENT_STREAM_VALUE)
|
|
public SseEmitter connectSse() {
|
|
log.info("Client requesting SSE connection...");
|
|
SseEmitter emitter = new SseEmitter(Long.MAX_VALUE);
|
|
broadcaster.registerEmitter(emitter);
|
|
broadcaster.sendEndpointEvent(emitter);
|
|
return emitter;
|
|
}
|
|
}
|