Is this you? As a journalist, you can create a free Muck Rack account to customize your profile, list your contact preferences, and upload a portfolio of your best work.
Claim your profile
Articles by SSE Example
实时数据流无忧:用 SpringBoot 和 SSE 打造动态前端更新的终极指南
你知道什么是开发者的梦魇吗?慢!慢!慢!在一个需要实时数据更新的应用中,如果数据像乌龟一样慢吞吞地爬行,那用户体验就会像坐过山车一样直线下降。所以今天,我们要化身为数据传输的超级英雄,用 SpringBoot 和 SSE(服务器发送事件)打造一个超酷、超快、而且超实时的数据流! 在开始我们的冒险之前,先让我们来谈谈为什么要选择 SSE(服务器发送事件)。简单来说,SSE 就像是那个总是知道你需要什么并且在你还没说之前就把它送到你面前的超级服务员。它允许服务器主动将信息“推送”到客户端,而不是等待客户端来“询问”。想象一下,你正在看一场激动人心的球赛直播,而不是每五秒刷新一次页面,SSE 可以帮你实时看到每一个进球。是不是很酷? 好的,现在让我们开始编写一些代码。首先,我们需要创建一个 SpringBoot 控制器。这个控制器就像是魔法世界的大门,让所有神奇的事情开始发生。 @RestController @RequestMapping("/user") public class UserController { private final...
【流式传输】使用Spring Boot实现ChatGpt流式传输
在ChatGpt火了这么久,他的那种单字单字返回的格式可能让很多朋友感到好奇,在之前我用c#写了一个版本的,同时支持IAsyncEnumerable以及SSE,今天把之前写的Java版本的也发出来,和大家一起学习,有不对的地方,欢迎各位大佬指正。 我这边用的是JDK21版本,可以看到下面,我们实现了两种方式一种是WebFlux实现响应式返回,另外一种就是SSE的标准写法,有关SSE,大家可以百度去看看他的一些规则,需要设置一些Header,以及返回的数据格式都有特别的讲究。第一种,我们需要在Pom.xml里面引入WebFlux的包,然后才能在代码使用, <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-webflux</artifactId> </dependency> <dependency> @RestController @RequestMapping("Hello") public class HelloController {...
Introduction to Real-Time Communication in PHP Laravel
Real-time communication has become a crucial aspect of modern web applications, allowing users to interact with each other and receive immediate updates without the need for manual refreshes. In PHP Laravel, real-time communication can be achieved through various tools and technologies, including Long Polling, WebSockets, and Server-Sent Events. This opens many possibilities for building dynamic and interactive web applications.
【分段传输】c#使用IAsyncEnumerable实现流式分段传输 - 四处观察 - 博客园
在使用SSE的时候,前端可以实现流式传输,但是有个问题就是这是一个独占的连接,相当于如果你不手动关闭连接,就会一直请求,一直连接调用接口,而且发送的数据格式也是按照定义好的协议来,而使用c#自带的IAsyncEnumerable也可以实现流式传输,不过返回的数据是在之前返回的基础上进行累加,需要自己做处理,我的例子是使用的是ajax来实现,群友有提供了fetch的实现代码,接下来我们看看c#IAsyncEnumerable实现传输的ajax方案和fetch的代码吧。 下面是源码和gif效果展示,可以看到我们返回的是一个IAsyncEnumerable<int>类型的结果,在第二段代码,我们都知道ajax是根据xhrhttprequest封装的,所以自然也可以用一些它的一些事件,所以我们在此处用了onprogress来监听我们请求的进度,在这里我们就可以获取到每一次写了哪些东西,从而实现一个流传输,因为后端写也是一个字节一个字节去写的,前端接收也是如此。 [HttpGet("Postb")] public async IAsyncEnumerable<int> PostB() {...
Show More
loading
Actions
Is this you?
As a journalist, you can create a free Muck Rack account to customize your profile, list your contact preferences, and upload a portfolio of your best work.Get in touch with SSE
Contact SSE, search articles and posts on X, monitor coverage, and track replies from one place.
Learn more about Muck Rack