spring.cloud.stream.function.autodetect=true (default setting) for spring-webflux app with server.forward-headers-strategy=FRAMEWORK can't work
Los mantenedores suelen responder en 1 día
Nadie ha tomado este issue todavía.
Evaluación
- Dificultad
- 4/5
- Tiempo estimado
- 3-5 días
- Aptitud para principiantes
- 22/100
- Tipo de issue
- Error
- Claridad
- Bastante claro
- Estado de actividad
- Activo
- Stack tecnológico
- java, spring, spring-boot
- Área
- backend
Línea de trabajo
The problem sits in the autodetection logic of spring-cloud-stream's function binding and in the ForwardedHeaderTransformer bean that webflux autoconfiguration registers when server.forward-headers-strategy=FRAMEWORK. Start by reproducing with a minimal webflux app that has one output binding, then check which functional beans the registry picks up. Done means autodetection ignores framework-provided beans such as forwardedHeaderTransformer, and the reported ClassCastException and multiple-functions warning no longer occur.
Escrito por el modelo de indexación a partir del texto del issue.
Descripción
Describe the issue
Using a spring-webflux app with server.forward-headers-strategy=FRAMEWORK, autoconfiguration provides a ForwardedHeaderTransformer bean which breaks all use cases of spring.cloud.stream.function.autodetect :
- if you have only output-bindings, a queue is createded and a consumer is registered on this queue which noone ever wants. If you send a message to this queue, you get
java.lang.ClassCastException: class [B cannot be cast to class org.springframework.http.server.reactive.ServerHttpRequest ([B is in module java.base of loader 'bootstrap'; org.springframework.http.server.reactive.ServerHttpRequest is in unnamed module of loader 'app')
- if you had a single java.util.function.* bean and relied on autodetection, it doesn't work.:
17:59:09.253 [main] WARN org.springframework.cloud.function.context.catalog.BeanFactoryAwareFunctionRegistry - Multiple functional beans were found [forwardedHeaderTransformer, myConsumer], thus can't determine default function definition. Please use 'spring.cloud.function.definition' property to explicitly define it.
To Reproduce
Steps to reproduce the behavior:
see above
all versions
Additional context
In the docs there is the following note:
In the event you only have single bean of type java.util.function.[Supplier/Function/Consumer], you can skip the spring.cloud.function.definition property, since such functional bean will be auto-discovered. However, it is considered best practice to use such property to avoid any confusion. Some time this auto-discovery can get in the way, since single bean of type java.util.function.[Supplier/Function/Consumer] could be there for purposes other then handling messages, yet being single it is auto-discovered and auto-bound. For these rare scenarios you can disable auto-discovery by providing spring.cloud.stream.function.autodetect property with value set to false.
To me, this would have been a good idea if there were really no easy cases where autodection breaks down. It depends on what "rare" means of course, but just a plain webflux springboot app with a single nonexotic property "server.forward-headers-strategy" doesn't seem to be that rare.
So maybe just make autodetection opt-in ? But then it doesn't make much sense, autodetection is for zero config (onboarding), so it's not interesting to add explicit autodetection=true configuration just to avoid some other configuration..
So maybe just delete autodetection entirely? You would lose the easy zero config onboarding.
Or make the autodection really reliable:
- maybe the autodetection should only happen when there is zero spring.cloud.stream.bindings or output-bindings configuration ? zeroconfig onboarding would still work (unless the user chose webflux+forward-headers-strategy=FRAMEWORK to try it out) and normal applications with only output-bindings wouldn't get the spurious consumer
- maybe find a way to exclude all "standard" beans. Based on the package ? Based on the function Signature (who would use Function<HttpServletRequest, HttpServletRequest>) ? Based on something else ?
- another idea ?
Cheers,
Jon
- Lenguaje dominante
- Java
- Estrellas
- 1.1k
- Forks
- 658
- Merge medio
- 4 h 54 min
- PR fusionados (30 d)
- 10
Preparar el entorno
- Sin Dockerfile ni archivo de Docker Compose
- Sin plantilla de pull request
- Leer la guía de contribución
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Más de spring-cloud/spring-cloud-function
-
5.0.x backport bug
Dificultad 1/5 Menos de una hora Aptitud para principiantes 68/100
spring-cloud/spring-cloud-function#1569 ·
Los mantenedores suelen responder en 1 día
-
Document that securing exposed function endpoints is the application's responsibilityPosiblemente ocupada @ruthst00 la tomó hace 2 días. Abierto5.0.x backport documentation
Dificultad 3/5 Medio día Aptitud para principiantes 66/100
spring-cloud/spring-cloud-function#1559 ·
Los mantenedores suelen responder en 1 día
-
Dificultad 3/5 1-2 días Aptitud para principiantes 55/100
spring-cloud/spring-cloud-function#1538 · 2 comentarios ·
Los mantenedores suelen responder en 1 día
Todos los issues de spring-cloud/spring-cloud-function
Issues similares
-
enhancement infra
Dificultad 2/5 1-3 horas Aptitud para principiantes 67/100
Los mantenedores suelen responder en 1 día
-
Move the spring-cloud-commons version and BOM import from the bus parent to the stream parentPosiblemente ocupada @olegz la tomó hoy. Abiertotask
Dificultad 2/5 1-3 horas Aptitud para principiantes 74/100
spring-cloud/spring-cloud-stream#3355 ·
Los mantenedores suelen responder en 1 día
-
NoSuchMethodError in the circuit breaker since 3.103.0 when resilience4j 2.x is on the classpathAbierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 76/100
oracle/oci-java-sdk#803 ·
-
area:cpan-port area:performance bug
Dificultad 2/5 1-3 horas Aptitud para principiantes 72/100
fglock/PerlOnJava#2230 ·
Los mantenedores suelen responder en 1 día
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 76/100