Open KarthikRIyer opened 1 year ago
Update:
The exception while using spring.cloud.stream.function.definition
from a Function<>
does not depend if I use a separate output-binding, or the output binding of the function. It works as long as the Function<>
's bean name is specified in spring.cloud.function.definition
.
Many thanks @KarthikRIyer your last comment save me hours of debug
@KarthikRIyer Is the original issue still there? Or can we close this issue?
Yeah, the original issue is still there.
I am confused. What does it have to do with routing function? I see you have a Rest Controller from which you are using StreamBridge
to always send to planeEventProducer
, which itself always routes to flightEventProducer
etc,
RouterFunction has nothing to do with spring.cloud.stream.sendto.destination
I am confused
But, instead of using one of the bindings specified in spring.cloud.stream.output-bindings when I try to use the function's output binding PlaneEvent-out-0, and add PlaneEvent to spring.cloud.stream.function.definition, it works as expected.
You have multiple functions. None of them will turn into a binding by default. We only auto-bind if user has a single function, so specifying all these functions in function.definition property is the correct and the expected behaviour
Also, you seem to using all three routing techniques s-c -stream has to offer. . . seems a bit too much
If you are using StreamBridge to effectively connect REST call with stream, why not determine right there where exactly do you want yo send the message and just do it with bridge.send(..)
. You would save tons of configuration and the app would be much more readable and performant.
If you still insist on using routing function, then make sure it has all the information to route message to proper function
So i really do no see a case where spring.cloud.stream.sendto.destination
would make any sense in your application.
Keep in mind that spring.cloud.stream.sendto.destination
will send the message to a destination. This means that an extra queue and an extra binding must be there. So it's a network call. And all that your are calling is in the same application. So you are leaving your app just to come back to it. Why?
Describe the issue Publishing messages using
.setHeader("spring.cloud.stream.sendto.destination", "output binding name here")
gives me the following exception:More details:
I have a functionRouter that routes messages to different functions based on header. These functions in turn process the message and return a result which I need to publish to another topic.
application.properties
AirplaneApplication.java
ApplicationController.java
On calling the GET endpoint (publish plane) I get a ClassCastException when planeEventProcessor tries to publish to the flightEventProducer binding:
Publishing messages using output-bindings and streamBridge works as expected, but using the same output-binding with
.setHeader("spring.cloud.stream.sendto.destination", "output binding name here")
doesn't.But, instead of using one of the bindings specified in
spring.cloud.stream.output-bindings
when I try to use the function's output bindingPlaneEvent-out-0
, and add PlaneEvent tospring.cloud.stream.function.definition
, it works as expected.On debugging a little I can see that streamBridge sets the
outputContentType
correctly (application/json
).But, this doesn't seem to be happening with spring.cloud.stream.sendto.destination for bindings which are not specified in
spring.cloud.stream.function.definition
. The correct outputContentType is present in theBindingPropeties
, but it isn't getting used.To Reproduce Steps to reproduce the behavior:
spring.cloud.stream.kafka.binder.brokers
localhost:8095/publishPlane
. The sample app has swagger for convenience.Version of the framework SpringBoot 3.0.4 Java 17 Spring Cloud 2022.0.1
Expected behavior Publishing messages with the
spring.cloud.stream.function.definition
header and value as an output-binding specified in the properties inspring.cloud.stream.output-bindings
should take into consideration the output content type fromBindingProperties
.Screenshots
When publishing with Stream Bridge (Debug point here):
When publishing with
spring.cloud.stream.function.definition
(Same debug point mentioned above):