SSE(Server Sent Event) 踩坑留念

在这里插入图片描述
整条链路是

客户端A --> 服务端 A —> 服务端 B

我负责服务端 A
此时要注意 @Client 中的 processes 的写法

@Post(value = “/v2/xx”, processes = MediaType.TEXT_EVENT_STREAM)
这样写是一直报错的

改成下面的写法才可以

@Post(value = “/v2/xx”, processes = MediaType.APPLICATION_JSON_STREAM)

原因如下

text/event-stream is the official media type for Server Sent Events (SSE); it will prefix data bits with a data: prefix and you can also choose your prefix to change the meaning of that piece of data for the client. This media type is for browsers, as they support that using the EventSource JavaScript API.

application/stream+json is for server to server/http client (anything that’s not a browser) communications. It won’t prefix the data and will just use CRLF to split the pieces of data. Note that the Spring team is reconsidering that media type, because SPR-16742 (don’t hesitate to comment there!).

译文如下

text/event-stream 是服务器发送事件(SSE)的官方媒体类型;它会在数据位前加上 data: 前缀,你也可以选择你的前缀来改变该数据对客户端的意义。这种媒体类型适用于浏览器,因为它们使用 EventSource JavaScript API 支持这种类型。

application/stream+json 用于服务器到服务器/http 客户端(非浏览器的任何设备)的通信。它不会在数据前加前缀,只会使用 CRLF 分割数据块。请注意,由于 SPR-16742 的原因,Spring 团队正在重新考虑这种媒体类型(请随时发表评论!)。

  • 2
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值