Search code examples
spring-cloud-stream

StreamBridge is overriding headers set for Kafka using CloudEventMessageBuilder


I am using spring-cloud-stream, version - 2022.0.0 along with spring boot version3.0.1, to publish a Cloud Event message to a kafka topic. I am using CloudEventMessageBuilderto build a message and headers, and usingStreamBridge` to send it to topic.

    Message<String> message = CloudEventMessageBuilder.withData(payload)
            .setType("CustomType")
            .setSource("CustomSource")
            .setSubject("CustomSubject")
            .build();

    streamBridge.send("channel-out-0", message);

Though I am able to publish the message on kafka topic, the headers I have set has been removed or overridden by StreamBridge.

Here is the behaviour I am seeing -

Header Set Value Value Sent to Kafka
ce_type CustomType java.lang.String
ce_source CustomSource http://spring.io/
ce_subject CustomSubject (Absent)

Sample Code https://github.com/moazzamkhan/stream-bridge-test

How can i set headers?

Thanks


Solution

  • Thank you for reporting it. It's a bug, so I just filed it. Will be fixed by 4.0.1 and released in few weeks - https://github.com/spring-cloud/spring-cloud-function/issues/985