spring-projects / spring-boot

Spring Boot
https://spring.io/projects/spring-boot
Apache License 2.0
74.92k stars 40.63k forks source link

Custom Actuator Endpoint with MediaType as text/event-stream is not working #42470

Closed talasila-sairam closed 2 weeks ago

talasila-sairam commented 2 weeks ago

Versions That i have used Java:- OpenJDK-11 Spring boot: 2.7.0 reactor-core: 3.4.28 netty: 1.0.30

Problem: I created a custom actuator endpoint to expose a data stream, however despite events being triggered, requests are taking a long time to complete and no data is being released.

This is my simple controller

image

I noticed that, while the same configuration functions perfectly when using the restController, it does not function when using the endpoint and readOperation annotation.

image
bclozel commented 2 weeks ago

Sorry but Spring Boot 2.7.x is out of open source support. We can reopen this issue if you provide a minimal sample that reproduces the problem on a supported version (3.2.x+). See https://spring.io/projects/spring-boot#support

Thanks!

talasila-sairam commented 2 weeks ago

resilience4j-spring-boot3-demo.zip Hey @bclozel and @wilkinsona I've attached a zip file including all of my project files. Please let me know if you require anything else.

wilkinsona commented 2 weeks ago

Thanks, @talasila-sairam. Unfortunately, there are really too many moving parts in that code for us to start looking at it. As I said on #42475, please reduce it to the bare minimum that's required to reproduce the problem. As I understand the problem, that should be dependencies on only the actuator and webflux starters and a single custom endpoint that uses text/event-stream.

wilkinsona commented 2 weeks ago

Actually, on second look, I'm not surprised that this doesn't work. You're using ServerSentEvent that is, quoting from its javadoc, "for use with Spring's reactive Web support". You're not (directly) using Spring's reactive web support here, you're using the Actuator's endpoint infrastructure which is an abstraction on top of Spring MVC, Spring WebFlux, and Jersey. As such, you should not expect features for use with WebFlux to work.

You may be able to use @RestControllerEndpoint instead. This couples your endpoint to Spring MVC or Spring WebFlux. Note that it has been deprecated since Spring Boot 3.3.x as we intend to tighten up Actuator's endpoint infrastructure in Spring Boot 4 and only support higher-level concepts that can be mapped to all three web frameworks that we support.

talasila-sairam commented 2 weeks ago
wilkinsona commented 2 weeks ago

Is there any way to obtain the events using the actuator endpoint in this scenario?similar to produces for an actuator endpoint should be text/event-stream

You may be able to use @RestControllerEndpoint as I mentioned above.

What is being obsoleted in this instance? I did't get that point.

Please see https://github.com/spring-projects/spring-boot/issues/31768.

If you have any further questions, please follow up on Stack Overflow. As mentioned in the guidelines for contributing, we prefer to use GitHub issues only for bugs and enhancements.