Skip to content

Commit ca224b0

Browse files
committed
update SSEController
1 parent 0e6e1b1 commit ca224b0

File tree

3 files changed

+5
-2
lines changed

3 files changed

+5
-2
lines changed

help/test-sse.gif

77.7 KB
Loading

help/test-sse.png

-54.6 KB
Binary file not shown.

src/main/java/cn/netbuffer/springboot/demo/controller/SSEController.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@
1111
import java.util.HashMap;
1212
import java.util.Map;
1313

14+
/**
15+
* test page:https://github.com/netbuffer/UItest/blob/master/es/eventsource.html
16+
*/
1417
@Slf4j
1518
@RestController
1619
@RequestMapping("/sse")
@@ -52,12 +55,12 @@ public SseEmitter handle(String id) {
5255
return sseEmitter;
5356
}
5457

55-
@GetMapping("sendById")
58+
@RequestMapping("sendById")
5659
public void sendById(String id, String message) throws IOException {
5760
log.debug("send message with SseEmitter id={}", id);
5861
SseEmitter emitter = sseEmitterMap.get(id);
5962
if (emitter != null) {
60-
emitter.send(SseEmitter.event().data(message));
63+
emitter.send(SseEmitter.event().data(message,MediaType.TEXT_PLAIN));
6164
}
6265
}
6366

0 commit comments

Comments
 (0)