Create

Sign in to ReadmeX

or

How we handle your data: Privacy Policy

ReadmeX

Your AI reading companion

What would you like to catch up on?

Pick a briefing, or ask your own question.

Your community and people briefings stay personal to you.

Story

A Practical Guide to Spring AI Streaming with SSE

AI summary

A Juejin author recounts converting an AI interface from call() to stream() in Spring AI, requiring 20 lines of code changes, three configuration adjustments and six implementation pitfalls. The tutorial covers SseEmitter and WebFlux implementations, proxy buffering, timeouts, cancellation, SSE frame parsing and Spring AI Advisor behavior. In the author’s test, both approaches took 3.2 seconds overall, while streaming displayed the first token after 0.4 seconds instead of waiting for the complete response.

In-depth insight

The account gives builders practical checks for preserving token-by-token delivery through Spring, browsers and reverse proxies, which the Juejin author says are common sources of apparently non-streaming responses.

上一篇《同一个问题写了 4 遍》里,四种接入方式我都跑了一遍,但全都是 call() —— 问完,等,然后一整段话砸下来。

那时候我没觉得有问题。直到我把这个接口给朋友试,他说了一句:

「点了发送之后,它到底是在思考,还是卡死了?」

这句话把我点醒了。用户看不到「正在发生」,就会认为「坏了」。

于是我花了一个周末把 call() 改成 stream()。原以为只是换个方法名,结果是:代码改了 20 行,配置调了 3 处,踩了 6 个坑,其中 2 个在本地完全测不出来。


一、先把「快」这件事拆开

大多数人以为流式是为了「更快」。不是。

#Spring AI#Spring MVC#Spring WebFlux#Server-Sent Events#Nginx#SseEmitter

Original · 11 min readRead the original
Group chat

No comments yet. Start the conversation.