Publish null/tombstone message with raw headers

为君一笑 提交于 2019-12-12 05:12:38

问题


I am building a Spring Cloud Stream Kafka processor app that will consume raw data with a String key and sometimes a null payload from a Kafka topic. I want to produce to another topic a String key and the null payload (known as a tombstone within Kafka). In order to use raw headers on the message, I need to output a byte[], but if I encode KafkaNull.INSTANCE into a byte[] it will literally output a String of the object hashcode.

If I try to send anything other than a byte[], I can't use raw headers.

What is the correct way to do this? Where would the headers even be if the payload is null? I set producer.headerMode=embeddedHeaders on deploy and that didn't seem to make a difference, still have the hashcode as the payload.


回答1:


You can use the latter introduced useNativeEncoding property (which overlaps the raw headerMode in that it skips headers) but allows you use a native Kafka serializer.

See http://docs.spring.io/autorepo/docs/spring-cloud-stream-docs/Brooklyn.BUILD-SNAPSHOT/reference/htmlsingle/#_producer_properties or http://docs.spring.io/autorepo/docs/spring-cloud-stream-docs/Chelsea.BUILD-SNAPSHOT/reference/htmlsingle/#_producer_properties



来源:https://stackoverflow.com/questions/42960237/publish-null-tombstone-message-with-raw-headers

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!