问题
I am using spring-cloud-stream kafka binder to consume messages from a kafka topic. The source system is sending the json message in ascii. When My consumer listens to the topic it throws
o.s.c.s.b.k.KafkaMessageChannelBinder : Could not convert message: 7B22736..
Is there any property that I can set in my .yml file to deserialize it? or is there an example that I can look into?
回答1:
I am not sure what you mean by json in hexadecimal-binary data
if you mean it's ascii data in a byte[]
, try adding spring.cloud.stream.bindings.input.content-type=text/plain
(or application/json
).
回答2:
You can look for the configuration property here: http://docs.spring.io/spring-cloud-stream/docs/Brooklyn.SR2/reference/htmlsingle/#_kafka_consumer_properties
In your case, you can set this by doing the following:
spring.cloud.stream.kafka.bindings.<channelName>.consumer.configuration.value.deserializer=<Deserialzier class>
Kafka binder takes all properties from the configuration map. Thus you can use any generic Kafka consumer properties and pass them this way.
回答3:
When I added content-type:plain/text
and spring.cloud.stream.bindings.<subscriptionChannel>.consumer.headerMode:raw
it worked.
Thank you!
来源:https://stackoverflow.com/questions/42653913/what-is-the-property-to-accept-binary-json-message-in-spring-cloud-stream-kafka