I want to setup a spring-cloud-stream-kafka producer with spring boot.
The producer is working and I can consume the messages from the kafka broker but the messages also contain some header information like the following:
If you want to avoid embedding the headers (so you can receive messages in some non-Spring Cloud Stream app), set the producer's headerMode
to raw
.
See Producer Properties.
headerMode
When set to raw, disables header embedding on output. Effective only for messaging middleware that does not support message headers natively and requires header embedding. Useful when producing data for non-Spring Cloud Stream applications.
Default: embeddedHeaders.
The contentType
and originalContentType
headers are used by Spring Cloud Stream when deserializing the message by the consumer application and perform message conversion based on the content-type set.
The contentType
header is explicitly set only when you configure the bindings's content-type as you did it here spring.cloud.stream.bindings.consumer.content-type=application/json
.
When the contentType
header is set, Spring Cloud Stream preserves this header using the originalContentType
flag during serialization/de-serialization process of producing/consuming messages to/from the broker (via binder).
In your case, I guess you may not need to set the contentType
at all.
For the examples apart from the samples in that spring-cloud-stream-samples github repo, you can also refer out of the box app starters which cover wide range of applications that could run against any of the supported binders (including Kafka).