{"id":5956,"date":"2024-08-01T22:49:18","date_gmt":"2024-08-01T14:49:18","guid":{"rendered":"https:\/\/xinchewhd.com.cn\/?p=5956"},"modified":"2024-08-02T14:55:47","modified_gmt":"2024-08-02T06:55:47","slug":"%e4%bd%bf%e7%94%a8-spring-boot-sse-%e5%ae%9e%e7%8e%b0%e5%ae%9e%e6%97%b6%e6%b6%88%e6%81%af%e6%8e%a8%e9%80%81%e5%8a%9f%e8%83%bd","status":"publish","type":"post","link":"https:\/\/xinchewhd.com.cn\/index.php\/spring-boot\/%e4%bd%bf%e7%94%a8-spring-boot-sse-%e5%ae%9e%e7%8e%b0%e5%ae%9e%e6%97%b6%e6%b6%88%e6%81%af%e6%8e%a8%e9%80%81%e5%8a%9f%e8%83%bd\/","title":{"rendered":"\u4f7f\u7528 Spring Boot + SSE \u5b9e\u73b0\u5b9e\u65f6\u6d88\u606f\u63a8\u9001\u529f\u80fd"},"content":{"rendered":"<div class=\"wxsyncmain\">\n<h3 style=\"box-sizing: border-box; margin-top: 0px !important; margin-bottom: 1rem; font-weight: 600; line-height: 1.25; font-size: 1.25rem; color: #0595bf; font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Helvetica, Arial, sans-serif, 'Apple Color Emoji', 'Segoe UI Emoji'; font-style: normal; font-variant-caps: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-tap-highlight-color: rgba(26, 26, 26, 0.3); -webkit-text-stroke-width: 0px; text-decoration: none;\" data-sourcepos=\"1:1-1:59\"><\/h3>\n<section>\n<section style=\"display: inline-block;\"><img decoding=\"async\" class=\"lazyload\"data-src=\"https:\/\/wp-moto-1258805347.cos.ap-shanghai.myqcloud.com\/2024\/08\/20240801223221906.jpg\" src=\"https:\/\/s.nmxc.ltd\/sakurairo_vision\/@2.6\/load_svg\/inload.svg\" onerror=\"imgError(this)\" data-ratio=\"1.0591259640102828\" data-type=\"jpg\" data-w=\"778\" \/><noscript><img decoding=\"async\" src=\"https:\/\/wp-moto-1258805347.cos.ap-shanghai.myqcloud.com\/2024\/08\/20240801223221906.jpg\" data-ratio=\"1.0591259640102828\" data-type=\"jpg\" data-w=\"778\" \/><\/noscript><\/section>\n<\/section>\n<p style=\"box-sizing: border-box; margin-top: 0px; margin-bottom: 1rem; caret-color: #333333; color: #333333; font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Helvetica, Arial, sans-serif, 'Apple Color Emoji', 'Segoe UI Emoji'; font-size: 17px; font-style: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-tap-highlight-color: rgba(26, 26, 26, 0.3); -webkit-text-stroke-width: 0px; text-decoration: none;\" data-sourcepos=\"3:1-3:12\">\u4e00\u3001\u5f15\u8a00<\/p>\n<p style=\"box-sizing: border-box; margin-top: 0px; margin-bottom: 1rem; caret-color: #333333; color: #333333; font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Helvetica, Arial, sans-serif, 'Apple Color Emoji', 'Segoe UI Emoji'; font-size: 17px; font-style: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-tap-highlight-color: rgba(26, 26, 26, 0.3); -webkit-text-stroke-width: 0px; text-decoration: none;\" data-sourcepos=\"5:1-5:343\">\u5728\u5f53\u4eca\u7684\u4e92\u8054\u7f51\u5e94\u7528\u4e2d\uff0c\u5b9e\u65f6\u6d88\u606f\u63a8\u9001\u6210\u4e3a\u4e86\u63d0\u5347\u7528\u6237\u4f53\u9a8c\u548c\u589e\u5f3a\u7cfb\u7edf\u4ea4\u4e92\u6027\u7684\u5173\u952e\u6280\u672f\u3002\u672c\u6587\u5c06\u6df1\u5165\u63a2\u8ba8\u5982\u4f55\u4f7f\u7528 Spring Boot \u7ed3\u5408 Server-Sent Events\uff08SSE\uff09\u6765\u5b9e\u73b0\u5b9e\u65f6\u6d88\u606f\u63a8\u9001\u529f\u80fd\uff0c\u5305\u62ec SSE \u7684\u5b9e\u73b0\u539f\u7406\u3001\u7279\u70b9\u3001\u5e94\u7528\u573a\u666f\uff0c\u5e76\u901a\u8fc7\u8be6\u7ec6\u7684\u524d\u540e\u7aef\u4ee3\u7801\u793a\u4f8b\u8fdb\u884c\u5c55\u793a\u3002<\/p>\n<p style=\"box-sizing: border-box; margin-top: 0px; margin-bottom: 1rem; caret-color: #333333; color: #333333; font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Helvetica, Arial, sans-serif, 'Apple Color Emoji', 'Segoe UI Emoji'; font-size: 17px; font-style: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-tap-highlight-color: rgba(26, 26, 26, 0.3); -webkit-text-stroke-width: 0px; text-decoration: none;\" data-sourcepos=\"7:1-7:22\">\u4e8c\u3001SSE \u5b9e\u73b0\u539f\u7406<\/p>\n<p style=\"box-sizing: border-box; margin-top: 0px; margin-bottom: 1rem; caret-color: #333333; color: #333333; font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Helvetica, Arial, sans-serif, 'Apple Color Emoji', 'Segoe UI Emoji'; font-size: 17px; font-style: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-tap-highlight-color: rgba(26, 26, 26, 0.3); -webkit-text-stroke-width: 0px; text-decoration: none;\" data-sourcepos=\"9:1-9:442\">SSE \u57fa\u4e8e HTTP \u534f\u8bae\uff0c\u5ba2\u6237\u7aef\u5411\u670d\u52a1\u5668\u53d1\u8d77\u4e00\u4e2a\u8bf7\u6c42\uff0c\u670d\u52a1\u5668\u4fdd\u6301\u8be5\u8fde\u63a5\u6253\u5f00\u3002\u5f53\u6709\u65b0\u7684\u6d88\u606f\u4ea7\u751f\u65f6\uff0c\u670d\u52a1\u5668\u901a\u8fc7\u8fd9\u4e2a\u8fde\u63a5\u5c06\u6d88\u606f\u4ee5\u7279\u5b9a\u7684\u683c\u5f0f\u63a8\u9001\u7ed9\u5ba2\u6237\u7aef\u3002SSE \u5229\u7528\u4e86 HTTP \u534f\u8bae\u7684\u6d41\u7279\u6027\uff0c\u901a\u8fc7\u8bbe\u7f6e\u7279\u5b9a\u7684\u54cd\u5e94\u5934\uff0c\u5982Content-Type: text\/event-stream\uff0c\u6765\u6807\u8bc6\u8fd9\u662f\u4e00\u4e2a SSE \u8fde\u63a5\u3002\u670d\u52a1\u5668\u63a8\u9001\u7684\u6d88\u606f\u4ee5\u7279\u5b9a\u7684\u683c\u5f0f\u7ec4\u7ec7\uff0c\u6bcf\u884c\u4ee5data:\u5f00\u5934\u8868\u793a\u6570\u636e\u5185\u5bb9\u3002<\/p>\n<p style=\"box-sizing: border-box; margin-top: 0px; margin-bottom: 1rem; caret-color: #333333; color: #333333; font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Helvetica, Arial, sans-serif, 'Apple Color Emoji', 'Segoe UI Emoji'; font-size: 17px; font-style: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-tap-highlight-color: rgba(26, 26, 26, 0.3); -webkit-text-stroke-width: 0px; text-decoration: none;\" data-sourcepos=\"11:1-11:16\">\u4e09\u3001SSE \u7279\u70b9<\/p>\n<p style=\"box-sizing: border-box; margin-top: 0px; margin-bottom: 1rem; caret-color: #333333; color: #333333; font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Helvetica, Arial, sans-serif, 'Apple Color Emoji', 'Segoe UI Emoji'; font-size: 17px; font-style: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-tap-highlight-color: rgba(26, 26, 26, 0.3); -webkit-text-stroke-width: 0px; text-decoration: none;\" data-sourcepos=\"13:1-16:85\">\u5355\u5411\u901a\u4fe1\uff1aSSE \u662f\u670d\u52a1\u5668\u5411\u5ba2\u6237\u7aef\u7684\u5355\u5411\u63a8\u9001\uff0c\u5ba2\u6237\u7aef\u65e0\u6cd5\u4e3b\u52a8\u5411\u670d\u52a1\u5668\u53d1\u9001\u6570\u636e\u3002\u8f7b\u91cf\u7ea7\uff1a\u76f8\u8f83\u4e8e WebSocket \u7b49\u6280\u672f\uff0cSSE \u7684\u5b9e\u73b0\u76f8\u5bf9\u7b80\u5355\uff0c\u5f00\u9500\u8f83\u5c0f\u3002\u57fa\u4e8e HTTP\uff1a\u5229\u7528\u73b0\u6709\u7684 HTTP \u57fa\u7840\u8bbe\u65bd\uff0c\u6613\u4e8e\u90e8\u7f72\u548c\u96c6\u6210\u3002\u8de8\u5e73\u53f0\u652f\u6301\uff1a\u5927\u591a\u6570\u73b0\u4ee3\u6d4f\u89c8\u5668\u90fd\u652f\u6301 SSE\uff0c\u5177\u6709\u8f83\u597d\u7684\u517c\u5bb9\u6027\u3002<\/p>\n<p style=\"box-sizing: border-box; margin-top: 0px; margin-bottom: 1rem; caret-color: #333333; color: #333333; font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Helvetica, Arial, sans-serif, 'Apple Color Emoji', 'Segoe UI Emoji'; font-size: 17px; font-style: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-tap-highlight-color: rgba(26, 26, 26, 0.3); -webkit-text-stroke-width: 0px; text-decoration: none;\" data-sourcepos=\"18:1-18:22\">\u56db\u3001SSE \u5e94\u7528\u573a\u666f<\/p>\n<p style=\"box-sizing: border-box; margin-top: 0px; margin-bottom: 1rem; caret-color: #333333; color: #333333; font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Helvetica, Arial, sans-serif, 'Apple Color Emoji', 'Segoe UI Emoji'; font-size: 17px; font-style: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-tap-highlight-color: rgba(26, 26, 26, 0.3); -webkit-text-stroke-width: 0px; text-decoration: none;\" data-sourcepos=\"20:1-22:75\">\u5b9e\u65f6\u901a\u77e5\uff1a\u5982\u90ae\u4ef6\u5230\u8fbe\u901a\u77e5\u3001\u7cfb\u7edf\u544a\u8b66\u7b49\u3002\u6570\u636e\u5b9e\u65f6\u66f4\u65b0\uff1a\u80a1\u7968\u884c\u60c5\u3001\u5929\u6c14\u9884\u62a5\u7b49\u6570\u636e\u7684\u5b9e\u65f6\u63a8\u9001\u3002\u65e5\u5fd7\u5b9e\u65f6\u76d1\u63a7\uff1a\u5c06\u670d\u52a1\u5668\u7aef\u7684\u65e5\u5fd7\u5b9e\u65f6\u63a8\u9001\u5230\u524d\u7aef\u5c55\u793a\u3002<\/p>\n<p style=\"box-sizing: border-box; margin-top: 0px; margin-bottom: 1rem; caret-color: #333333; color: #333333; font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Helvetica, Arial, sans-serif, 'Apple Color Emoji', 'Segoe UI Emoji'; font-size: 17px; font-style: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-tap-highlight-color: rgba(26, 26, 26, 0.3); -webkit-text-stroke-width: 0px; text-decoration: none;\" data-sourcepos=\"24:1-24:41\">\u4e94\u3001\u540e\u7aef\u4ee3\u7801\u5b9e\u73b0\uff08Spring Boot\uff09<\/p>\n<div class=\"code-toolbar\" style=\"box-sizing: border-box; caret-color: #333333; color: #333333; font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Helvetica, Arial, sans-serif, 'Apple Color Emoji', 'Segoe UI Emoji'; font-size: 17px; font-style: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-tap-highlight-color: rgba(26, 26, 26, 0.3); -webkit-text-stroke-width: 0px; text-decoration: none;\">\n<pre class=\"language-java\" style=\"box-sizing: border-box; font-family: Consolas, Monaco, 'Andale Mono', 'Ubuntu Mono', monospace; font-size: 14.45px; margin: 0.5rem 0px; overflow-wrap: normal; padding: 1rem; overflow: auto; line-height: 1.45; background: #f7f8f8; border-radius: 0.1875rem; color: black; text-align: left; white-space: pre; word-spacing: normal; word-break: normal; tab-size: 4; hyphens: none;\" tabindex=\"0\" data-sourcepos=\"26:1-83:3\"><code class=\"language-java\" style=\"box-sizing: border-box; font-family: Consolas, Monaco, 'Andale Mono', 'Ubuntu Mono', monospace; font-size: 14.45px; padding: 0px; margin: 0px; background-color: initial; color: #09844f; border-radius: 0.1875rem; background-image: none; background-position: 0% 0%; background-size: auto; background-repeat: repeat; background-attachment: scroll; background-origin: padding-box; background-clip: border-box; text-align: left; white-space: pre; word-spacing: normal; word-break: normal; overflow-wrap: normal; tab-size: 4; hyphens: none; display: inline; overflow: visible; line-height: inherit; border: 0px none currentcolor;\"><span class=\"token keyword\" style=\"box-sizing: border-box; color: #bc319c;\">import<\/span> <span class=\"token import\" style=\"box-sizing: border-box;\"><span class=\"token namespace\" style=\"box-sizing: border-box; opacity: 0.7;\">org<span class=\"token punctuation\" style=\"box-sizing: border-box; color: #2834ce;\">.<\/span>springframework<span class=\"token punctuation\" style=\"box-sizing: border-box; color: #2834ce;\">.<\/span>http<span class=\"token punctuation\" style=\"box-sizing: border-box; color: #2834ce;\">.<\/span><\/span><span class=\"token class-name\" style=\"box-sizing: border-box; color: #967d41;\">MediaType<\/span><\/span><span class=\"token punctuation\" style=\"box-sizing: border-box; color: #2834ce;\">;<\/span><span class=\"token keyword\" style=\"box-sizing: border-box; color: #bc319c;\">import<\/span> <span class=\"token import\" style=\"box-sizing: border-box;\"><span class=\"token namespace\" style=\"box-sizing: border-box; opacity: 0.7;\">org<span class=\"token punctuation\" style=\"box-sizing: border-box; color: #2834ce;\">.<\/span>springframework<span class=\"token punctuation\" style=\"box-sizing: border-box; color: #2834ce;\">.<\/span>web<span class=\"token punctuation\" style=\"box-sizing: border-box; color: #2834ce;\">.<\/span>bind<span class=\"token punctuation\" style=\"box-sizing: border-box; color: #2834ce;\">.<\/span>annotation<span class=\"token punctuation\" style=\"box-sizing: border-box; color: #2834ce;\">.<\/span><\/span><span class=\"token class-name\" style=\"box-sizing: border-box; color: #967d41;\">GetMapping<\/span><\/span><span class=\"token punctuation\" style=\"box-sizing: border-box; color: #2834ce;\">;<\/span><span class=\"token keyword\" style=\"box-sizing: border-box; color: #bc319c;\">import<\/span> <span class=\"token import\" style=\"box-sizing: border-box;\"><span class=\"token namespace\" style=\"box-sizing: border-box; opacity: 0.7;\">org<span class=\"token punctuation\" style=\"box-sizing: border-box; color: #2834ce;\">.<\/span>springframework<span class=\"token punctuation\" style=\"box-sizing: border-box; color: #2834ce;\">.<\/span>web<span class=\"token punctuation\" style=\"box-sizing: border-box; color: #2834ce;\">.<\/span>bind<span class=\"token punctuation\" style=\"box-sizing: border-box; color: #2834ce;\">.<\/span>annotation<span class=\"token punctuation\" style=\"box-sizing: border-box; color: #2834ce;\">.<\/span><\/span><span class=\"token class-name\" style=\"box-sizing: border-box; color: #967d41;\">RestController<\/span><\/span><span class=\"token punctuation\" style=\"box-sizing: border-box; color: #2834ce;\">;<\/span><span class=\"token keyword\" style=\"box-sizing: border-box; color: #bc319c;\">import<\/span> <span class=\"token import\" style=\"box-sizing: border-box;\"><span class=\"token namespace\" style=\"box-sizing: border-box; opacity: 0.7;\">org<span class=\"token punctuation\" style=\"box-sizing: border-box; color: #2834ce;\">.<\/span>springframework<span class=\"token punctuation\" style=\"box-sizing: border-box; color: #2834ce;\">.<\/span>web<span class=\"token punctuation\" style=\"box-sizing: border-box; color: #2834ce;\">.<\/span>servlet<span class=\"token punctuation\" style=\"box-sizing: border-box; color: #2834ce;\">.<\/span>mvc<span class=\"token punctuation\" style=\"box-sizing: border-box; color: #2834ce;\">.<\/span>method<span class=\"token punctuation\" style=\"box-sizing: border-box; color: #2834ce;\">.<\/span>annotation<span class=\"token punctuation\" style=\"box-sizing: border-box; color: #2834ce;\">.<\/span><\/span><span class=\"token class-name\" style=\"box-sizing: border-box; color: #967d41;\">SseEmitter<\/span><\/span><span class=\"token punctuation\" style=\"box-sizing: border-box; color: #2834ce;\">;<\/span><span class=\"token keyword\" style=\"box-sizing: border-box; color: #bc319c;\">import<\/span> <span class=\"token import\" style=\"box-sizing: border-box;\"><span class=\"token namespace\" style=\"box-sizing: border-box; opacity: 0.7;\">java<span class=\"token punctuation\" style=\"box-sizing: border-box; color: #2834ce;\">.<\/span>util<span class=\"token punctuation\" style=\"box-sizing: border-box; color: #2834ce;\">.<\/span>concurrent<span class=\"token punctuation\" style=\"box-sizing: border-box; color: #2834ce;\">.<\/span>atomic<span class=\"token punctuation\" style=\"box-sizing: border-box; color: #2834ce;\">.<\/span><\/span><span class=\"token class-name\" style=\"box-sizing: border-box; color: #967d41;\">AtomicInteger<\/span><\/span><span class=\"token punctuation\" style=\"box-sizing: border-box; color: #2834ce;\">;<\/span><span class=\"token annotation punctuation\" style=\"box-sizing: border-box; color: #2834ce;\">@RestController<\/span><span class=\"token keyword\" style=\"box-sizing: border-box; color: #bc319c;\">public<\/span> <span class=\"token keyword\" style=\"box-sizing: border-box; color: #bc319c;\">class<\/span> <span class=\"token class-name\" style=\"box-sizing: border-box; color: #967d41;\">SseController<\/span> <span class=\"token punctuation\" style=\"box-sizing: border-box; color: #2834ce;\">{<\/span>    <span class=\"token keyword\" style=\"box-sizing: border-box; color: #bc319c;\">private<\/span> <span class=\"token class-name\" style=\"box-sizing: border-box; color: #967d41;\">AtomicInteger<\/span> counter <span class=\"token operator\" style=\"box-sizing: border-box;\">=<\/span> <span class=\"token keyword\" style=\"box-sizing: border-box; color: #bc319c;\">new<\/span> <span class=\"token class-name\" style=\"box-sizing: border-box; color: #967d41;\">AtomicInteger<\/span><span class=\"token punctuation\" style=\"box-sizing: border-box; color: #2834ce;\">(<\/span><span class=\"token number\" style=\"box-sizing: border-box; color: #2834ce;\">0<\/span><span class=\"token punctuation\" style=\"box-sizing: border-box; color: #2834ce;\">)<\/span><span class=\"token punctuation\" style=\"box-sizing: border-box; color: #2834ce;\">;<\/span>    <span class=\"token annotation punctuation\" style=\"box-sizing: border-box; color: #2834ce;\">@GetMapping<\/span><span class=\"token punctuation\" style=\"box-sizing: border-box; color: #2834ce;\">(<\/span>value <span class=\"token operator\" style=\"box-sizing: border-box;\">=<\/span> \u201d<span class=\"token operator\" style=\"box-sizing: border-box;\">\/<\/span>stream\u201c<span class=\"token punctuation\" style=\"box-sizing: border-box; color: #2834ce;\">,<\/span> produces <span class=\"token operator\" style=\"box-sizing: border-box;\">=<\/span> <span class=\"token class-name\" style=\"box-sizing: border-box; color: #967d41;\">MediaType<\/span><span class=\"token punctuation\" style=\"box-sizing: border-box; color: #2834ce;\">.<\/span><span class=\"token constant\" style=\"box-sizing: border-box; color: #2834ce;\">TEXT_EVENT_STREAM_VALUE<\/span><span class=\"token punctuation\" style=\"box-sizing: border-box; color: #2834ce;\">)<\/span>    <span class=\"token keyword\" style=\"box-sizing: border-box; color: #bc319c;\">public<\/span> <span class=\"token class-name\" style=\"box-sizing: border-box; color: #967d41;\">SseEmitter<\/span> <span class=\"token function\" style=\"box-sizing: border-box; color: #967d41;\">streamMessages<\/span><span class=\"token punctuation\" style=\"box-sizing: border-box; color: #2834ce;\">(<\/span><span class=\"token punctuation\" style=\"box-sizing: border-box; color: #2834ce;\">)<\/span> <span class=\"token punctuation\" style=\"box-sizing: border-box; color: #2834ce;\">{<\/span>        <span class=\"token class-name\" style=\"box-sizing: border-box; color: #967d41;\">SseEmitter<\/span> emitter <span class=\"token operator\" style=\"box-sizing: border-box;\">=<\/span> <span class=\"token keyword\" style=\"box-sizing: border-box; color: #bc319c;\">new<\/span> <span class=\"token class-name\" style=\"box-sizing: border-box; color: #967d41;\">SseEmitter<\/span><span class=\"token punctuation\" style=\"box-sizing: border-box; color: #2834ce;\">(<\/span><span class=\"token punctuation\" style=\"box-sizing: border-box; color: #2834ce;\">)<\/span><span class=\"token punctuation\" style=\"box-sizing: border-box; color: #2834ce;\">;<\/span>        <span class=\"token keyword\" style=\"box-sizing: border-box; color: #bc319c;\">new<\/span> <span class=\"token class-name\" style=\"box-sizing: border-box; color: #967d41;\">Thread<\/span><span class=\"token punctuation\" style=\"box-sizing: border-box; color: #2834ce;\">(<\/span><span class=\"token punctuation\" style=\"box-sizing: border-box; color: #2834ce;\">(<\/span><span class=\"token punctuation\" style=\"box-sizing: border-box; color: #2834ce;\">)<\/span> <span class=\"token operator\" style=\"box-sizing: border-box;\">-&gt;<\/span> <span class=\"token punctuation\" style=\"box-sizing: border-box; color: #2834ce;\">{<\/span>            <span class=\"token keyword\" style=\"box-sizing: border-box; color: #bc319c;\">try<\/span> <span class=\"token punctuation\" style=\"box-sizing: border-box; color: #2834ce;\">{<\/span>                <span class=\"token keyword\" style=\"box-sizing: border-box; color: #bc319c;\">while<\/span> <span class=\"token punctuation\" style=\"box-sizing: border-box; color: #2834ce;\">(<\/span><span class=\"token boolean\" style=\"box-sizing: border-box; color: #2834ce;\">true<\/span><span class=\"token punctuation\" style=\"box-sizing: border-box; color: #2834ce;\">)<\/span> <span class=\"token punctuation\" style=\"box-sizing: border-box; color: #2834ce;\">{<\/span>                    <span class=\"token class-name\" style=\"box-sizing: border-box; color: #967d41;\">String<\/span> message <span class=\"token operator\" style=\"box-sizing: border-box;\">=<\/span> \u201d\u6d88\u606f \u201c <span class=\"token operator\" style=\"box-sizing: border-box;\">+<\/span> counter<span class=\"token punctuation\" style=\"box-sizing: border-box; color: #2834ce;\">.<\/span><span class=\"token function\" style=\"box-sizing: border-box; color: #967d41;\">incrementAndGet<\/span><span class=\"token punctuation\" style=\"box-sizing: border-box; color: #2834ce;\">(<\/span><span class=\"token punctuation\" style=\"box-sizing: border-box; color: #2834ce;\">)<\/span><span class=\"token punctuation\" style=\"box-sizing: border-box; color: #2834ce;\">;<\/span>                    <span class=\"token comment\" style=\"box-sizing: border-box; color: #8e9c92;\">\/\/ send(SseEvent event) \u793a\u4f8b<\/span>                    <span class=\"token class-name\" style=\"box-sizing: border-box; color: #967d41;\">SseEvent<\/span> event <span class=\"token operator\" style=\"box-sizing: border-box;\">=<\/span> <span class=\"token keyword\" style=\"box-sizing: border-box; color: #bc319c;\">new<\/span> <span class=\"token class-name\" style=\"box-sizing: border-box; color: #967d41;\">SseEventBuilder<\/span><span class=\"token punctuation\" style=\"box-sizing: border-box; color: #2834ce;\">(<\/span><span class=\"token punctuation\" style=\"box-sizing: border-box; color: #2834ce;\">)<\/span>                      <span class=\"token punctuation\" style=\"box-sizing: border-box; color: #2834ce;\">.<\/span><span class=\"token function\" style=\"box-sizing: border-box; color: #967d41;\">data<\/span><span class=\"token punctuation\" style=\"box-sizing: border-box; color: #2834ce;\">(<\/span>message<span class=\"token punctuation\" style=\"box-sizing: border-box; color: #2834ce;\">)<\/span>                      <span class=\"token punctuation\" style=\"box-sizing: border-box; color: #2834ce;\">.<\/span><span class=\"token function\" style=\"box-sizing: border-box; color: #967d41;\">name<\/span><span class=\"token punctuation\" style=\"box-sizing: border-box; color: #2834ce;\">(<\/span>\u201dcustomEvent\u201c<span class=\"token punctuation\" style=\"box-sizing: border-box; color: #2834ce;\">)<\/span>                      <span class=\"token punctuation\" style=\"box-sizing: border-box; color: #2834ce;\">.<\/span><span class=\"token function\" style=\"box-sizing: border-box; color: #967d41;\">build<\/span><span class=\"token punctuation\" style=\"box-sizing: border-box; color: #2834ce;\">(<\/span><span class=\"token punctuation\" style=\"box-sizing: border-box; color: #2834ce;\">)<\/span><span class=\"token punctuation\" style=\"box-sizing: border-box; color: #2834ce;\">;<\/span>                    emitter<span class=\"token punctuation\" style=\"box-sizing: border-box; color: #2834ce;\">.<\/span><span class=\"token function\" style=\"box-sizing: border-box; color: #967d41;\">send<\/span><span class=\"token punctuation\" style=\"box-sizing: border-box; color: #2834ce;\">(<\/span>event<span class=\"token punctuation\" style=\"box-sizing: border-box; color: #2834ce;\">)<\/span><span class=\"token punctuation\" style=\"box-sizing: border-box; color: #2834ce;\">;<\/span>                    <span class=\"token comment\" style=\"box-sizing: border-box; color: #8e9c92;\">\/\/ send(Object data) \u793a\u4f8b<\/span>                    emitter<span class=\"token punctuation\" style=\"box-sizing: border-box; color: #2834ce;\">.<\/span><span class=\"token function\" style=\"box-sizing: border-box; color: #967d41;\">send<\/span><span class=\"token punctuation\" style=\"box-sizing: border-box; color: #2834ce;\">(<\/span>message<span class=\"token punctuation\" style=\"box-sizing: border-box; color: #2834ce;\">)<\/span><span class=\"token punctuation\" style=\"box-sizing: border-box; color: #2834ce;\">;<\/span>                    <span class=\"token class-name\" style=\"box-sizing: border-box; color: #967d41;\">Thread<\/span><span class=\"token punctuation\" style=\"box-sizing: border-box; color: #2834ce;\">.<\/span><span class=\"token function\" style=\"box-sizing: border-box; color: #967d41;\">sleep<\/span><span class=\"token punctuation\" style=\"box-sizing: border-box; color: #2834ce;\">(<\/span><span class=\"token number\" style=\"box-sizing: border-box; color: #2834ce;\">5000<\/span><span class=\"token punctuation\" style=\"box-sizing: border-box; color: #2834ce;\">)<\/span><span class=\"token punctuation\" style=\"box-sizing: border-box; color: #2834ce;\">;<\/span>                <span class=\"token punctuation\" style=\"box-sizing: border-box; color: #2834ce;\">}<\/span>            <span class=\"token punctuation\" style=\"box-sizing: border-box; color: #2834ce;\">}<\/span> <span class=\"token keyword\" style=\"box-sizing: border-box; color: #bc319c;\">catch<\/span> <span class=\"token punctuation\" style=\"box-sizing: border-box; color: #2834ce;\">(<\/span><span class=\"token class-name\" style=\"box-sizing: border-box; color: #967d41;\">Exception<\/span> e<span class=\"token punctuation\" style=\"box-sizing: border-box; color: #2834ce;\">)<\/span> <span class=\"token punctuation\" style=\"box-sizing: border-box; color: #2834ce;\">{<\/span>                emitter<span class=\"token punctuation\" style=\"box-sizing: border-box; color: #2834ce;\">.<\/span><span class=\"token function\" style=\"box-sizing: border-box; color: #967d41;\">completeWithError<\/span><span class=\"token punctuation\" style=\"box-sizing: border-box; color: #2834ce;\">(<\/span>e<span class=\"token punctuation\" style=\"box-sizing: border-box; color: #2834ce;\">)<\/span><span class=\"token punctuation\" style=\"box-sizing: border-box; color: #2834ce;\">;<\/span>            <span class=\"token punctuation\" style=\"box-sizing: border-box; color: #2834ce;\">}<\/span>        <span class=\"token punctuation\" style=\"box-sizing: border-box; color: #2834ce;\">}<\/span><span class=\"token punctuation\" style=\"box-sizing: border-box; color: #2834ce;\">)<\/span><span class=\"token punctuation\" style=\"box-sizing: border-box; color: #2834ce;\">.<\/span><span class=\"token function\" style=\"box-sizing: border-box; color: #967d41;\">start<\/span><span class=\"token punctuation\" style=\"box-sizing: border-box; color: #2834ce;\">(<\/span><span class=\"token punctuation\" style=\"box-sizing: border-box; color: #2834ce;\">)<\/span><span class=\"token punctuation\" style=\"box-sizing: border-box; color: #2834ce;\">;<\/span>        <span class=\"token comment\" style=\"box-sizing: border-box; color: #8e9c92;\">\/\/ complete() \u793a\u4f8b<\/span>        emitter<span class=\"token punctuation\" style=\"box-sizing: border-box; color: #2834ce;\">.<\/span><span class=\"token function\" style=\"box-sizing: border-box; color: #967d41;\">onCompletion<\/span><span class=\"token punctuation\" style=\"box-sizing: border-box; color: #2834ce;\">(<\/span><span class=\"token punctuation\" style=\"box-sizing: border-box; color: #2834ce;\">(<\/span><span class=\"token punctuation\" style=\"box-sizing: border-box; color: #2834ce;\">)<\/span> <span class=\"token operator\" style=\"box-sizing: border-box;\">-&gt;<\/span> <span class=\"token punctuation\" style=\"box-sizing: border-box; color: #2834ce;\">{<\/span>            <span class=\"token class-name\" style=\"box-sizing: border-box; color: #967d41;\">System<\/span><span class=\"token punctuation\" style=\"box-sizing: border-box; color: #2834ce;\">.<\/span>out<span class=\"token punctuation\" style=\"box-sizing: border-box; color: #2834ce;\">.<\/span><span class=\"token function\" style=\"box-sizing: border-box; color: #967d41;\">println<\/span><span class=\"token punctuation\" style=\"box-sizing: border-box; color: #2834ce;\">(<\/span>\u201d\u8fde\u63a5\u6b63\u5e38\u5b8c\u6210\u201c<span class=\"token punctuation\" style=\"box-sizing: border-box; color: #2834ce;\">)<\/span><span class=\"token punctuation\" style=\"box-sizing: border-box; color: #2834ce;\">;<\/span>        <span class=\"token punctuation\" style=\"box-sizing: border-box; color: #2834ce;\">}<\/span><span class=\"token punctuation\" style=\"box-sizing: border-box; color: #2834ce;\">)<\/span><span class=\"token punctuation\" style=\"box-sizing: border-box; color: #2834ce;\">;<\/span>        <span class=\"token comment\" style=\"box-sizing: border-box; color: #8e9c92;\">\/\/ timeout(long timeoutMillis) \u793a\u4f8b<\/span>        emitter<span class=\"token punctuation\" style=\"box-sizing: border-box; color: #2834ce;\">.<\/span><span class=\"token function\" style=\"box-sizing: border-box; color: #967d41;\">timeout<\/span><span class=\"token punctuation\" style=\"box-sizing: border-box; color: #2834ce;\">(<\/span><span class=\"token number\" style=\"box-sizing: border-box; color: #2834ce;\">10000<\/span><span class=\"token punctuation\" style=\"box-sizing: border-box; color: #2834ce;\">)<\/span><span class=\"token punctuation\" style=\"box-sizing: border-box; color: #2834ce;\">;<\/span>        <span class=\"token comment\" style=\"box-sizing: border-box; color: #8e9c92;\">\/\/ onTimeout(Runnable callback) \u793a\u4f8b<\/span>        emitter<span class=\"token punctuation\" style=\"box-sizing: border-box; color: #2834ce;\">.<\/span><span class=\"token function\" style=\"box-sizing: border-box; color: #967d41;\">onTimeout<\/span><span class=\"token punctuation\" style=\"box-sizing: border-box; color: #2834ce;\">(<\/span><span class=\"token punctuation\" style=\"box-sizing: border-box; color: #2834ce;\">(<\/span><span class=\"token punctuation\" style=\"box-sizing: border-box; color: #2834ce;\">)<\/span> <span class=\"token operator\" style=\"box-sizing: border-box;\">-&gt;<\/span> <span class=\"token punctuation\" style=\"box-sizing: border-box; color: #2834ce;\">{<\/span>            <span class=\"token class-name\" style=\"box-sizing: border-box; color: #967d41;\">System<\/span><span class=\"token punctuation\" style=\"box-sizing: border-box; color: #2834ce;\">.<\/span>out<span class=\"token punctuation\" style=\"box-sizing: border-box; color: #2834ce;\">.<\/span><span class=\"token function\" style=\"box-sizing: border-box; color: #967d41;\">println<\/span><span class=\"token punctuation\" style=\"box-sizing: border-box; color: #2834ce;\">(<\/span>\u201d\u8fde\u63a5\u8d85\u65f6\u201c<span class=\"token punctuation\" style=\"box-sizing: border-box; color: #2834ce;\">)<\/span><span class=\"token punctuation\" style=\"box-sizing: border-box; color: #2834ce;\">;<\/span>        <span class=\"token punctuation\" style=\"box-sizing: border-box; color: #2834ce;\">}<\/span><span class=\"token punctuation\" style=\"box-sizing: border-box; color: #2834ce;\">)<\/span><span class=\"token punctuation\" style=\"box-sizing: border-box; color: #2834ce;\">;<\/span>        <span class=\"token comment\" style=\"box-sizing: border-box; color: #8e9c92;\">\/\/ onError(ErrorCallback callback) \u793a\u4f8b<\/span>        emitter<span class=\"token punctuation\" style=\"box-sizing: border-box; color: #2834ce;\">.<\/span><span class=\"token function\" style=\"box-sizing: border-box; color: #967d41;\">onError<\/span><span class=\"token punctuation\" style=\"box-sizing: border-box; color: #2834ce;\">(<\/span><span class=\"token punctuation\" style=\"box-sizing: border-box; color: #2834ce;\">(<\/span><span class=\"token class-name\" style=\"box-sizing: border-box; color: #967d41;\">Throwable<\/span> t<span class=\"token punctuation\" style=\"box-sizing: border-box; color: #2834ce;\">)<\/span> <span class=\"token operator\" style=\"box-sizing: border-box;\">-&gt;<\/span> <span class=\"token punctuation\" style=\"box-sizing: border-box; color: #2834ce;\">{<\/span>            <span class=\"token class-name\" style=\"box-sizing: border-box; color: #967d41;\">System<\/span><span class=\"token punctuation\" style=\"box-sizing: border-box; color: #2834ce;\">.<\/span>out<span class=\"token punctuation\" style=\"box-sizing: border-box; color: #2834ce;\">.<\/span><span class=\"token function\" style=\"box-sizing: border-box; color: #967d41;\">println<\/span><span class=\"token punctuation\" style=\"box-sizing: border-box; color: #2834ce;\">(<\/span>\u201d\u53d1\u751f\u9519\u8bef<span class=\"token operator\" style=\"box-sizing: border-box;\">:<\/span> \u201c <span class=\"token operator\" style=\"box-sizing: border-box;\">+<\/span> t<span class=\"token punctuation\" style=\"box-sizing: border-box; color: #2834ce;\">.<\/span><span class=\"token function\" style=\"box-sizing: border-box; color: #967d41;\">getMessage<\/span><span class=\"token punctuation\" style=\"box-sizing: border-box; color: #2834ce;\">(<\/span><span class=\"token punctuation\" style=\"box-sizing: border-box; color: #2834ce;\">)<\/span><span class=\"token punctuation\" style=\"box-sizing: border-box; color: #2834ce;\">)<\/span><span class=\"token punctuation\" style=\"box-sizing: border-box; color: #2834ce;\">;<\/span>        <span class=\"token punctuation\" style=\"box-sizing: border-box; color: #2834ce;\">}<\/span><span class=\"token punctuation\" style=\"box-sizing: border-box; color: #2834ce;\">)<\/span><span class=\"token punctuation\" style=\"box-sizing: border-box; color: #2834ce;\">;<\/span>        <span class=\"token keyword\" style=\"box-sizing: border-box; color: #bc319c;\">return<\/span> emitter<span class=\"token punctuation\" style=\"box-sizing: border-box; color: #2834ce;\">;<\/span>    <span class=\"token punctuation\" style=\"box-sizing: border-box; color: #2834ce;\">}<\/span><span class=\"token punctuation\" style=\"box-sizing: border-box; color: #2834ce;\">}<\/span><\/code><\/pre>\n<div class=\"toolbar\" style=\"box-sizing: border-box; z-index: 10; top: 0.3em; right: 0.2em; transition: opacity 0.3s ease-in-out 0s; opacity: 0;\">\n<div class=\"toolbar-item\" style=\"box-sizing: border-box; display: inline-block;\"><\/div>\n<\/div>\n<\/div>\n<p style=\"box-sizing: border-box; margin-top: 0px; margin-bottom: 1rem; caret-color: #333333; color: #333333; font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Helvetica, Arial, sans-serif, 'Apple Color Emoji', 'Segoe UI Emoji'; font-size: 17px; font-style: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-tap-highlight-color: rgba(26, 26, 26, 0.3); -webkit-text-stroke-width: 0px; text-decoration: none;\" data-sourcepos=\"85:1-85:143\">\u5728\u4e0a\u8ff0\u540e\u7aef\u4ee3\u7801\u4e2d\uff0c\u5b9a\u4e49\u4e86\u4e00\u4e2a\/stream\u7684\u63a5\u53e3\u3002\u521b\u5efa\u4e86SseEmitter\u5bf9\u8c61\uff0c\u5e76\u5728\u65b0\u7684\u7ebf\u7a0b\u4e2d\u6bcf\u9694 5 \u79d2\u53d1\u9001\u4e00\u6761\u6d88\u606f\u3002<\/p>\n<p style=\"box-sizing: border-box; margin-top: 0px; margin-bottom: 1rem; caret-color: #333333; color: #333333; font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Helvetica, Arial, sans-serif, 'Apple Color Emoji', 'Segoe UI Emoji'; font-size: 17px; font-style: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-tap-highlight-color: rgba(26, 26, 26, 0.3); -webkit-text-stroke-width: 0px; text-decoration: none;\" data-sourcepos=\"87:1-87:47\">\u516d\u3001\u524d\u7aef\u4ee3\u7801\u5b9e\u73b0\uff08HTML + JavaScript\uff09<\/p>\n<div class=\"code-toolbar\" style=\"box-sizing: border-box; caret-color: #333333; color: #333333; font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Helvetica, Arial, sans-serif, 'Apple Color Emoji', 'Segoe UI Emoji'; font-size: 17px; font-style: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-tap-highlight-color: rgba(26, 26, 26, 0.3); -webkit-text-stroke-width: 0px; text-decoration: none;\">\n<pre class=\"language-html\" style=\"box-sizing: border-box; font-family: Consolas, Monaco, 'Andale Mono', 'Ubuntu Mono', monospace; font-size: 14.45px; margin: 0.5rem 0px; overflow-wrap: normal; padding: 1rem; overflow: auto; line-height: 1.45; background: #f7f8f8; border-radius: 0.1875rem; color: black; text-align: left; white-space: pre; word-spacing: normal; word-break: normal; tab-size: 4; hyphens: none;\" tabindex=\"0\" data-sourcepos=\"89:1-123:3\"><code class=\"language-html\" style=\"box-sizing: border-box; font-family: Consolas, Monaco, 'Andale Mono', 'Ubuntu Mono', monospace; font-size: 14.45px; padding: 0px; margin: 0px; background-color: initial; color: #09844f; border-radius: 0.1875rem; background-image: none; background-position: 0% 0%; background-size: auto; background-repeat: repeat; background-attachment: scroll; background-origin: padding-box; background-clip: border-box; text-align: left; white-space: pre; word-spacing: normal; word-break: normal; overflow-wrap: normal; tab-size: 4; hyphens: none; display: inline; overflow: visible; line-height: inherit; border: 0px none currentcolor;\"><span class=\"token doctype\" style=\"box-sizing: border-box; color: #8e9c92;\"><span class=\"token punctuation\" style=\"box-sizing: border-box; color: #2834ce;\">&lt;!<\/span><span class=\"token doctype-tag\" style=\"box-sizing: border-box;\">DOCTYPE<\/span> <span class=\"token name\" style=\"box-sizing: border-box;\">html<\/span><span class=\"token punctuation\" style=\"box-sizing: border-box; color: #2834ce;\">&gt;<\/span><\/span><span class=\"token tag\" style=\"box-sizing: border-box; color: #2834ce;\"><span class=\"token tag\" style=\"box-sizing: border-box; color: #2834ce;\"><span class=\"token punctuation\" style=\"box-sizing: border-box; color: #2834ce;\">&lt;<\/span>html<\/span> <span class=\"token attr-name\" style=\"box-sizing: border-box; color: #d32d26;\">lang<\/span><span class=\"token attr-value\" style=\"box-sizing: border-box; color: #bc319c;\"><span class=\"token punctuation attr-equals\" style=\"box-sizing: border-box; color: #2834ce;\">=<\/span>\u201den\u201c<\/span><span class=\"token punctuation\" style=\"box-sizing: border-box; color: #2834ce;\">&gt;<\/span><\/span><span class=\"token tag\" style=\"box-sizing: border-box; color: #2834ce;\"><span class=\"token tag\" style=\"box-sizing: border-box; color: #2834ce;\"><span class=\"token punctuation\" style=\"box-sizing: border-box; color: #2834ce;\">&lt;<\/span>head<\/span><span class=\"token punctuation\" style=\"box-sizing: border-box; color: #2834ce;\">&gt;<\/span><\/span>  <span class=\"token tag\" style=\"box-sizing: border-box; color: #2834ce;\"><span class=\"token tag\" style=\"box-sizing: border-box; color: #2834ce;\"><span class=\"token punctuation\" style=\"box-sizing: border-box; color: #2834ce;\">&lt;<\/span>meta<\/span> <span class=\"token attr-name\" style=\"box-sizing: border-box; color: #d32d26;\">charset<\/span><span class=\"token attr-value\" style=\"box-sizing: border-box; color: #bc319c;\"><span class=\"token punctuation attr-equals\" style=\"box-sizing: border-box; color: #2834ce;\">=<\/span>\u201dUTF-8\u201c<\/span><span class=\"token punctuation\" style=\"box-sizing: border-box; color: #2834ce;\">&gt;<\/span><\/span>  &lt;meta http-equiv=\u201dX-UA-Compatible\u201c content=\u201dIE=edge\u201c&gt;  &lt;meta name=\u201dviewport\u201c content=\u201dwidth=device-width, initial-scale=1.0\u201c&gt;  <span class=\"token tag\" style=\"box-sizing: border-box; color: #2834ce;\"><span class=\"token tag\" style=\"box-sizing: border-box; color: #2834ce;\"><span class=\"token punctuation\" style=\"box-sizing: border-box; color: #2834ce;\">&lt;<\/span>title<\/span><span class=\"token punctuation\" style=\"box-sizing: border-box; color: #2834ce;\">&gt;<\/span><\/span>SSE \u5b9e\u65f6\u6d88\u606f\u63a8\u9001\u793a\u4f8b<span class=\"token tag\" style=\"box-sizing: border-box; color: #2834ce;\"><span class=\"token tag\" style=\"box-sizing: border-box; color: #2834ce;\"><span class=\"token punctuation\" style=\"box-sizing: border-box; color: #2834ce;\">&lt;\/<\/span>title<\/span><span class=\"token punctuation\" style=\"box-sizing: border-box; color: #2834ce;\">&gt;<\/span><\/span><span class=\"token tag\" style=\"box-sizing: border-box; color: #2834ce;\"><span class=\"token tag\" style=\"box-sizing: border-box; color: #2834ce;\"><span class=\"token punctuation\" style=\"box-sizing: border-box; color: #2834ce;\">&lt;\/<\/span>head<\/span><span class=\"token punctuation\" style=\"box-sizing: border-box; color: #2834ce;\">&gt;<\/span><\/span><span class=\"token tag\" style=\"box-sizing: border-box; color: #2834ce;\"><span class=\"token tag\" style=\"box-sizing: border-box; color: #2834ce;\"><span class=\"token punctuation\" style=\"box-sizing: border-box; color: #2834ce;\">&lt;<\/span>body<\/span><span class=\"token punctuation\" style=\"box-sizing: border-box; color: #2834ce;\">&gt;<\/span><\/span>  <span class=\"token tag\" style=\"box-sizing: border-box; color: #2834ce;\"><span class=\"token tag\" style=\"box-sizing: border-box; color: #2834ce;\"><span class=\"token punctuation\" style=\"box-sizing: border-box; color: #2834ce;\">&lt;<\/span>script<\/span><span class=\"token punctuation\" style=\"box-sizing: border-box; color: #2834ce;\">&gt;<\/span><\/span><span class=\"token script\" style=\"box-sizing: border-box;\"><span class=\"token language-javascript\" style=\"box-sizing: border-box;\">    <span class=\"token comment\" style=\"box-sizing: border-box; color: #8e9c92;\">\/\/ \u521b\u5efa EventSource \u5bf9\u8c61\u8fde\u63a5\u540e\u7aef<\/span>    <span class=\"token keyword\" style=\"box-sizing: border-box; color: #bc319c;\">var<\/span> source <span class=\"token operator\" style=\"box-sizing: border-box;\">=<\/span> <span class=\"token keyword\" style=\"box-sizing: border-box; color: #bc319c;\">new<\/span> <span class=\"token class-name\" style=\"box-sizing: border-box; color: #967d41;\">EventSource<\/span><span class=\"token punctuation\" style=\"box-sizing: border-box; color: #2834ce;\">(<\/span>\u2019<span class=\"token operator\" style=\"box-sizing: border-box;\">\/<\/span>stream\u2018<span class=\"token punctuation\" style=\"box-sizing: border-box; color: #2834ce;\">)<\/span><span class=\"token punctuation\" style=\"box-sizing: border-box; color: #2834ce;\">;<\/span>    <span class=\"token comment\" style=\"box-sizing: border-box; color: #8e9c92;\">\/\/ \u5904\u7406\u63a5\u6536\u5230\u7684\u6d88\u606f<\/span>    source<span class=\"token punctuation\" style=\"box-sizing: border-box; color: #2834ce;\">.<\/span><span class=\"token method-variable function-variable method function property-access\" style=\"box-sizing: border-box; color: #967d41;\">onmessage<\/span> <span class=\"token operator\" style=\"box-sizing: border-box;\">=<\/span> <span class=\"token keyword\" style=\"box-sizing: border-box; color: #bc319c;\">function<\/span> <span class=\"token punctuation\" style=\"box-sizing: border-box; color: #2834ce;\">(<\/span><span class=\"token parameter\" style=\"box-sizing: border-box;\">event<\/span><span class=\"token punctuation\" style=\"box-sizing: border-box; color: #2834ce;\">)<\/span> <span class=\"token punctuation\" style=\"box-sizing: border-box; color: #2834ce;\">{<\/span>      <span class=\"token console class-name\" style=\"box-sizing: border-box; color: #967d41;\">console<\/span><span class=\"token punctuation\" style=\"box-sizing: border-box; color: #2834ce;\">.<\/span><span class=\"token method function property-access\" style=\"box-sizing: border-box; color: #967d41;\">log<\/span><span class=\"token punctuation\" style=\"box-sizing: border-box; color: #2834ce;\">(<\/span>event<span class=\"token punctuation\" style=\"box-sizing: border-box; color: #2834ce;\">.<\/span><span class=\"token property-access\" style=\"box-sizing: border-box;\">data<\/span><span class=\"token punctuation\" style=\"box-sizing: border-box; color: #2834ce;\">)<\/span><span class=\"token punctuation\" style=\"box-sizing: border-box; color: #2834ce;\">;<\/span>      <span class=\"token keyword\" style=\"box-sizing: border-box; color: #bc319c;\">var<\/span> div <span class=\"token operator\" style=\"box-sizing: border-box;\">=<\/span> <span class=\"token dom variable\" style=\"box-sizing: border-box; color: #784830;\">document<\/span><span class=\"token punctuation\" style=\"box-sizing: border-box; color: #2834ce;\">.<\/span><span class=\"token method function property-access\" style=\"box-sizing: border-box; color: #967d41;\">createElement<\/span><span class=\"token punctuation\" style=\"box-sizing: border-box; color: #2834ce;\">(<\/span>\u2019div\u2018<span class=\"token punctuation\" style=\"box-sizing: border-box; color: #2834ce;\">)<\/span><span class=\"token punctuation\" style=\"box-sizing: border-box; color: #2834ce;\">;<\/span>      div<span class=\"token punctuation\" style=\"box-sizing: border-box; color: #2834ce;\">.<\/span><span class=\"token property-access\" style=\"box-sizing: border-box;\">innerHTML<\/span> <span class=\"token operator\" style=\"box-sizing: border-box;\">=<\/span> event<span class=\"token punctuation\" style=\"box-sizing: border-box; color: #2834ce;\">.<\/span><span class=\"token property-access\" style=\"box-sizing: border-box;\">data<\/span><span class=\"token punctuation\" style=\"box-sizing: border-box; color: #2834ce;\">;<\/span>      <span class=\"token dom variable\" style=\"box-sizing: border-box; color: #784830;\">document<\/span><span class=\"token punctuation\" style=\"box-sizing: border-box; color: #2834ce;\">.<\/span><span class=\"token property-access\" style=\"box-sizing: border-box;\">body<\/span><span class=\"token punctuation\" style=\"box-sizing: border-box; color: #2834ce;\">.<\/span><span class=\"token method function property-access\" style=\"box-sizing: border-box; color: #967d41;\">appendChild<\/span><span class=\"token punctuation\" style=\"box-sizing: border-box; color: #2834ce;\">(<\/span>div<span class=\"token punctuation\" style=\"box-sizing: border-box; color: #2834ce;\">)<\/span><span class=\"token punctuation\" style=\"box-sizing: border-box; color: #2834ce;\">;<\/span>    <span class=\"token punctuation\" style=\"box-sizing: border-box; color: #2834ce;\">}<\/span><span class=\"token punctuation\" style=\"box-sizing: border-box; color: #2834ce;\">;<\/span>    <span class=\"token comment\" style=\"box-sizing: border-box; color: #8e9c92;\">\/\/ \u5904\u7406\u8fde\u63a5\u9519\u8bef<\/span>    source<span class=\"token punctuation\" style=\"box-sizing: border-box; color: #2834ce;\">.<\/span><span class=\"token method-variable function-variable method function property-access\" style=\"box-sizing: border-box; color: #967d41;\">onerror<\/span> <span class=\"token operator\" style=\"box-sizing: border-box;\">=<\/span> <span class=\"token keyword\" style=\"box-sizing: border-box; color: #bc319c;\">function<\/span> <span class=\"token punctuation\" style=\"box-sizing: border-box; color: #2834ce;\">(<\/span><span class=\"token parameter\" style=\"box-sizing: border-box;\">error<\/span><span class=\"token punctuation\" style=\"box-sizing: border-box; color: #2834ce;\">)<\/span> <span class=\"token punctuation\" style=\"box-sizing: border-box; color: #2834ce;\">{<\/span>      <span class=\"token console class-name\" style=\"box-sizing: border-box; color: #967d41;\">console<\/span><span class=\"token punctuation\" style=\"box-sizing: border-box; color: #2834ce;\">.<\/span><span class=\"token method function property-access\" style=\"box-sizing: border-box; color: #967d41;\">error<\/span><span class=\"token punctuation\" style=\"box-sizing: border-box; color: #2834ce;\">(<\/span>\u2019<span class=\"token constant\" style=\"box-sizing: border-box; color: #2834ce;\">SSE<\/span> <span class=\"token literal-property property\" style=\"box-sizing: border-box; color: #2834ce;\">\u8fde\u63a5\u9519\u8bef<\/span><span class=\"token operator\" style=\"box-sizing: border-box;\">:<\/span>\u2018<span class=\"token punctuation\" style=\"box-sizing: border-box; color: #2834ce;\">,<\/span> error<span class=\"token punctuation\" style=\"box-sizing: border-box; color: #2834ce;\">)<\/span><span class=\"token punctuation\" style=\"box-sizing: border-box; color: #2834ce;\">;<\/span>    <span class=\"token punctuation\" style=\"box-sizing: border-box; color: #2834ce;\">}<\/span><span class=\"token punctuation\" style=\"box-sizing: border-box; color: #2834ce;\">;<\/span>  <\/span><\/span><span class=\"token tag\" style=\"box-sizing: border-box; color: #2834ce;\"><span class=\"token tag\" style=\"box-sizing: border-box; color: #2834ce;\"><span class=\"token punctuation\" style=\"box-sizing: border-box; color: #2834ce;\">&lt;\/<\/span>script<\/span><span class=\"token punctuation\" style=\"box-sizing: border-box; color: #2834ce;\">&gt;<\/span><\/span><span class=\"token tag\" style=\"box-sizing: border-box; color: #2834ce;\"><span class=\"token tag\" style=\"box-sizing: border-box; color: #2834ce;\"><span class=\"token punctuation\" style=\"box-sizing: border-box; color: #2834ce;\">&lt;\/<\/span>body<\/span><span class=\"token punctuation\" style=\"box-sizing: border-box; color: #2834ce;\">&gt;<\/span><\/span><span class=\"token tag\" style=\"box-sizing: border-box; color: #2834ce;\"><span class=\"token tag\" style=\"box-sizing: border-box; color: #2834ce;\"><span class=\"token punctuation\" style=\"box-sizing: border-box; color: #2834ce;\">&lt;\/<\/span>html<\/span><span class=\"token punctuation\" style=\"box-sizing: border-box; color: #2834ce;\">&gt;<\/span><\/span><\/code><\/pre>\n<div class=\"toolbar\" style=\"box-sizing: border-box; z-index: 10; top: 0.3em; right: 0.2em; transition: opacity 0.3s ease-in-out 0s; opacity: 0;\">\n<div class=\"toolbar-item\" style=\"box-sizing: border-box; display: inline-block;\"><\/div>\n<\/div>\n<\/div>\n<p style=\"box-sizing: border-box; margin-top: 0px; margin-bottom: 1rem; caret-color: #333333; color: #333333; font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Helvetica, Arial, sans-serif, 'Apple Color Emoji', 'Segoe UI Emoji'; font-size: 17px; font-style: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-tap-highlight-color: rgba(26, 26, 26, 0.3); -webkit-text-stroke-width: 0px; text-decoration: none;\" data-sourcepos=\"125:1-125:120\">\u524d\u7aef\u901a\u8fc7\u521b\u5efaEventSource\u5bf9\u8c61\u4e0e\u540e\u7aef\u7684\/stream\u63a5\u53e3\u5efa\u7acb\u8fde\u63a5\uff0c\u5e76\u5904\u7406\u63a5\u6536\u5230\u7684\u6d88\u606f\u548c\u8fde\u63a5\u9519\u8bef\u3002<\/p>\n<p style=\"box-sizing: border-box; margin-top: 0px; margin-bottom: 1rem; caret-color: #333333; color: #333333; font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Helvetica, Arial, sans-serif, 'Apple Color Emoji', 'Segoe UI Emoji'; font-size: 17px; font-style: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-tap-highlight-color: rgba(26, 26, 26, 0.3); -webkit-text-stroke-width: 0px; text-decoration: none;\" data-sourcepos=\"127:1-127:12\">\u4e03\u3001\u603b\u7ed3<\/p>\n<p style=\"box-sizing: border-box; margin-top: 0px; margin-bottom: 1rem; caret-color: #333333; color: #333333; font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Helvetica, Arial, sans-serif, 'Apple Color Emoji', 'Segoe UI Emoji'; font-size: 17px; font-style: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-tap-highlight-color: rgba(26, 26, 26, 0.3); -webkit-text-stroke-width: 0px; text-decoration: none;\" data-sourcepos=\"129:1-129:247\">\u901a\u8fc7\u4e0a\u8ff0\u7684\u524d\u540e\u7aef\u4ee3\u7801\u793a\u4f8b\uff0c\u6211\u4eec\u6210\u529f\u5730\u5b9e\u73b0\u4e86\u57fa\u4e8e Spring Boot \u548c SSE \u7684\u5b9e\u65f6\u6d88\u606f\u63a8\u9001\u529f\u80fd\u3002SSE \u5728\u4e00\u4e9b\u7279\u5b9a\u573a\u666f\u4e0b\u5177\u6709\u72ec\u7279\u7684\u4f18\u52bf\uff0c\u80fd\u591f\u4e3a\u5e94\u7528\u63d0\u4f9b\u9ad8\u6548\u3001\u8f7b\u91cf\u7ea7\u7684\u5b9e\u65f6\u6570\u636e\u63a8\u9001\u89e3\u51b3\u65b9\u6848\u3002<\/p>\n<p style=\"box-sizing: border-box; margin-top: 0px; margin-bottom: 0px !important; caret-color: #333333; color: #333333; font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Helvetica, Arial, sans-serif, 'Apple Color Emoji', 'Segoe UI Emoji'; font-size: 17px; font-style: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-tap-highlight-color: rgba(26, 26, 26, 0.3); -webkit-text-stroke-width: 0px; text-decoration: none;\" data-sourcepos=\"131:1-131:86\">\u5e0c\u671b\u672c\u6587\u80fd\u591f\u5e2e\u52a9\u60a8\u6df1\u5165\u7406\u89e3\u5e76\u6210\u529f\u8fd0\u7528 SSE \u5b9e\u73b0\u5b9e\u65f6\u6d88\u606f\u63a8\u9001\u3002<\/p>\n<p style=\"display: none;\">\n<blockquote><p>\u672c\u7bc7\u6587\u7ae0\u6765\u6e90\u4e8e\u5fae\u4fe1\u516c\u4f17\u53f7: \u8def\u6761\u7f16\u7a0b<\/p><\/blockquote>\n<\/div>\n","raw":"","protected":false},"excerpt":{"rendered":"<p>\u4e00\u3001\u5f15\u8a00 \u5728\u5f53\u4eca\u7684\u4e92\u8054\u7f51\u5e94\u7528\u4e2d\uff0c\u5b9e\u65f6\u6d88\u606f\u63a8\u9001\u6210\u4e3a\u4e86\u63d0\u5347\u7528\u6237\u4f53\u9a8c\u548c\u589e\u5f3a\u7cfb\u7edf\u4ea4\u4e92\u6027\u7684\u5173\u952e\u6280\u672f\u3002\u672c\u6587\u5c06\u6df1\u5165\u63a2\u8ba8\u5982\u4f55\u4f7f\u7528 Spring B &#8230;<\/p>\n","protected":false},"author":1,"featured_media":5943,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"emotion":"","emotion_color":"","title_style":"","license":"","footnotes":""},"categories":[7],"tags":[],"class_list":["post-5956","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-spring-boot"],"post_thumbnail_image":"https:\/\/wp-moto-1258805347.cos.ap-shanghai.myqcloud.com\/2024\/08\/20240801223204195-150x150.jpeg","content_first_image":"https:\/\/wp-moto-1258805347.cos.ap-shanghai.myqcloud.com\/2024\/08\/20240801223221906.jpg","post_medium_image_300":"https:\/\/wp-moto-1258805347.cos.ap-shanghai.myqcloud.com\/2024\/08\/20240801223204195-300x127.jpeg","post_thumbnail_image_624":"https:\/\/wp-moto-1258805347.cos.ap-shanghai.myqcloud.com\/2024\/08\/20240801223204195.jpeg","post_frist_image":"https:\/\/wp-moto-1258805347.cos.ap-shanghai.myqcloud.com\/2024\/08\/20240801223221906.jpg","post_medium_image":"https:\/\/wp-moto-1258805347.cos.ap-shanghai.myqcloud.com\/2024\/08\/20240801223204195-300x127.jpeg","post_large_image":"https:\/\/wp-moto-1258805347.cos.ap-shanghai.myqcloud.com\/2024\/08\/20240801223204195.jpeg","post_full_image":"https:\/\/wp-moto-1258805347.cos.ap-shanghai.myqcloud.com\/2024\/08\/20240801223204195.jpeg","post_all_images":[{"imagesurl":"https:\/\/wp-moto-1258805347.cos.ap-shanghai.myqcloud.com\/2024\/08\/20240801223221906.jpg","id":"image0"},{"imagesurl":"https:\/\/wp-moto-1258805347.cos.ap-shanghai.myqcloud.com\/2024\/08\/20240801223221906.jpg","id":"image1"}],"videoAdId":"","listAd":"0","listAdId":"","listAdEvery":6,"total_comments":0,"category_name":"Spring Boot","post_date":"2024-08-01","like_count":"0","praiseWord":"\u9f13\u52b1","copyright_state":"","excitationAd":"0","rewardedVideoAdId":"","detailAdId":"","detailAd":"0","enterpriseMinapp":"0","audios":[],"postImageUrl":"https:\/\/wp-moto-1258805347.cos.ap-shanghai.myqcloud.com\/2023\/05\/20230519082947553.jpg","avatarurls":[],"related_posts":null,"pageviews":1851,"next_post_id":6169,"next_post_title":"\u5355\u72ec\u5bf9 websocket \u62bd\u8c61\u5c01\u88c5\uff0c\u652f\u6491\u4e86\u516c\u53f8\u4e0d\u540c\u4e1a\u52a1\u7684\u6d88\u606f\u5373\u65f6\u901a\u8baf\uff01","previous_post_id":5899,"previous_post_title":"SpringBoot Maven\u9879\u76eepom\u4e2d\u7684dependency\u4f9d\u8d56\u6807\u7b7e\u7684\u7528\u6cd5\u6574\u7406","_links":{"self":[{"href":"https:\/\/xinchewhd.com.cn\/index.php\/wp-json\/wp\/v2\/posts\/5956","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/xinchewhd.com.cn\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/xinchewhd.com.cn\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/xinchewhd.com.cn\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/xinchewhd.com.cn\/index.php\/wp-json\/wp\/v2\/comments?post=5956"}],"version-history":[{"count":2,"href":"https:\/\/xinchewhd.com.cn\/index.php\/wp-json\/wp\/v2\/posts\/5956\/revisions"}],"predecessor-version":[{"id":6383,"href":"https:\/\/xinchewhd.com.cn\/index.php\/wp-json\/wp\/v2\/posts\/5956\/revisions\/6383"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/xinchewhd.com.cn\/index.php\/wp-json\/wp\/v2\/media\/5943"}],"wp:attachment":[{"href":"https:\/\/xinchewhd.com.cn\/index.php\/wp-json\/wp\/v2\/media?parent=5956"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/xinchewhd.com.cn\/index.php\/wp-json\/wp\/v2\/categories?post=5956"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/xinchewhd.com.cn\/index.php\/wp-json\/wp\/v2\/tags?post=5956"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}