Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support Flux<ServerSentEvent<Fragment>> in WebFlux #33975

Closed
dsyer opened this issue Nov 27, 2024 · 1 comment
Closed

Support Flux<ServerSentEvent<Fragment>> in WebFlux #33975

dsyer opened this issue Nov 27, 2024 · 1 comment
Assignees
Labels
in: web Issues in web modules (web, webmvc, webflux, websocket) type: enhancement A general enhancement
Milestone

Comments

@dsyer
Copy link
Member

dsyer commented Nov 27, 2024

In Spring 6.2 we got a new WebFlux feature with Fragment and you can render an SSE like this:

@GetMapping(path = "/stream", produces = MediaType.TEXT_EVENT_STREAM_VALUE)
public Flux<Fragment> stream() {
	return Flux.interval(Duration.ofSeconds(5))
			.map(value -> Fragment.create("time", Map.of("value", value, "time", System.currentTimeMillis())));
}

The only potential problem is that it doen't give you control over the SSE fields (in particular the "event" name which is unconditionaly rendered as the view name). If we could send Flux<ServerSentEvent<Fragment>> it would give us more control.

Same for MVC, but I think that might already be supported (Flux<ServerSentEvent<ModelAndView>>)?

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged or decided on label Nov 27, 2024
@rstoyanchev rstoyanchev self-assigned this Nov 27, 2024
@rstoyanchev rstoyanchev added in: web Issues in web modules (web, webmvc, webflux, websocket) type: enhancement A general enhancement and removed status: waiting-for-triage An issue we've not yet triaged or decided on labels Nov 27, 2024
@rstoyanchev rstoyanchev added this to the 6.2.1 milestone Nov 27, 2024
@rstoyanchev
Copy link
Contributor

rstoyanchev commented Nov 27, 2024

In Spring MVC, the equivalent is SseEmitter<ModelAndView> and that is already supported. It makes sense to add the same for WebFlux in order to allow control over SSE fields with Fragment rendering.

rstoyanchev added a commit that referenced this issue Dec 11, 2024
Extract re-usable method to serialize SSE fields.

See gh-33975
@rstoyanchev rstoyanchev changed the title Support for SSE rendering with Flux<ServerSentEvent<Fragment>> Support Flux<ServerSentEvent<Fragment>> in WebFlux Dec 11, 2024
rstoyanchev added a commit that referenced this issue Dec 11, 2024
Extract re-usable method to serialize SSE fields.

See gh-33975
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in: web Issues in web modules (web, webmvc, webflux, websocket) type: enhancement A general enhancement
Projects
None yet
Development

No branches or pull requests

3 participants