spring-cloud / spring-cloud-stream

Framework for building Event-Driven Microservices
http://cloud.spring.io/spring-cloud-stream
Apache License 2.0
1.01k stars 614 forks source link

StreamBridge does not forward headers when sending a Message<?> object #1931

Closed jorgebsa closed 4 years ago

jorgebsa commented 4 years ago

Versions

Spring Boot 2.2.5 Spring Cloud Hoxton.SR3

Description

Basically, there isn't a simple way of sending a message with custom headers through StreamBridge.send(..) because it doesn't care if the data is of type message, even though the documentation leads a developer to believe that a Message<?> would have its content preserved. What happens is that the send method ignores all the headers of the data object, constructing a new GenericMessage instance that gets sent to the output binding. This message instance only has 3 headers: id, timestamp and contentType.

This is better detailed in the README.md of the example project.

Example code

https://github.com/jorgebsa/stream-bridge-header-error

asood100 commented 3 years ago

https://github.com/jorgebsa/stream-bridge-header-error

Hi Olegz Did you get it working? I am unable to make StreamBridge work with Message<> argument in SpringBoot: 2.4.1 and SpringCloud: 2020.0.1 Is it correct when you define spring.cloud.stream.source: test then framework will create necessary function bean and its bindings so I dont need to create my Supplier<> bean. But when I did it at runtime it throws error saying the bean 'test' not found. Any clue?

olegz commented 3 years ago

We are in 3.1.3 version which is SpringCloud: 2020.0.3. Try that as the issue has been fixed on on Mar 23, 2020

asood100 commented 3 years ago

Thanks I will do that. Please clarify few things for me. I am writing a producer-only microservice that:

This is implemented:

Btw, if you dont provide "spring.cloud.stream.function.definition: sendMessage" and are using Swagger2 jars then the framework try to bind to output topic of Swagger because the jar has the Supplier<> bean in it. This is known issue.

olegz commented 3 years ago

I am not sure what version you are using, but streamBridge.send("blahblah", msg) will always work regardless of blahblah bean being there. That is to support dynamic destinations.

Anyway, if you believe you still have an issue please submit a small sample that reproduces it so we can take a look