WebFlux系列 Server-Sent Events
Posted JAVA微编程
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了WebFlux系列 Server-Sent Events相关的知识,希望对你有一定的参考价值。
#编程#入门#java#spring#webflux#SSE#reactor#
SSE和Websocket区别
视频讲解: https://www.bilibili.com/video/av82133200/
WebfluxServerApplication.java
package com.example.webfluxserver; import lombok.extern.log4j.Log4j2; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.http.MediaType; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RestController; import reactor.core.publisher.Flux; import java.time.Duration; @Log4j2 @SpringBootApplication public class WebfluxServerApplication extends BaseApplication{ public static void main(String[] args) { SpringApplication.run(WebfluxServerApplication.class, args); } @RestController class EmployeeController{ @GetMapping(value = "sse",produces = MediaType.TEXT_EVENT_STREAM_VALUE) public Flux<String> sse1(){ return Flux.interval(Duration.ofMillis(1000)).map(val ->val.toString()); } } }
公众号,坚持每天3分钟视频学习
以上是关于WebFlux系列 Server-Sent Events的主要内容,如果未能解决你的问题,请参考以下文章