【问题标题】:what is the property to accept binary json message in spring-cloud-stream kafka binder在 spring-cloud-stream kafka binder 中接受二进制 json 消息的属性是什么
【发布时间】:2017-07-27 23:49:24
【问题描述】:

我正在使用 spring-cloud-stream kafka binder 来使用来自 kafka 主题的消息。源系统正在以 ascii 格式发送 json 消息。当我的消费者听到它抛出的主题时

o.s.c.s.b.k.KafkaMessageChannelBinder    : Could not convert message: 7B22736..

我可以在我的 .yml 文件中设置任何属性来反序列化它吗?或者有没有我可以研究的例子?

【问题讨论】:

  • @ka2 我在link 看到了您的评论,您找到解决问题的方法了吗?

标签: spring-boot apache-kafka spring-cloud-stream


【解决方案1】:

如果您的意思是 byte[] 中的 ascii 数据,我不确定您所说的 json in hexadecimal-binary data 是什么意思,请尝试添加 spring.cloud.stream.bindings.input.content-type=text/plain(或 application/json)。

【讨论】:

  • 编辑了我的问题,当我使用 content-type:application/json 时抛出错误。
  • 你试过 text/plain 吗?或者您可以将spring.kafka.consumer.valueDerserializer 设置为org.apache.kafka.common.serialization.StringDeserializer
  • 当我使用 text/plain 时,它能够转换为 json,但是在控制台中它仍然会抛出相同的错误。我在我正在使用的 spring cloud stream kafka binder 中找不到 spring.kafka.consumer.valueDerserializer 属性。
  • 哦,对了,对不起;昨天刚刚添加的(Boot 1.5 支持)commit here。我不确定如何用早期的绑定器覆盖键/值反序列化器。
【解决方案2】:

您可以在此处查找配置属性:http://docs.spring.io/spring-cloud-stream/docs/Brooklyn.SR2/reference/htmlsingle/#_kafka_consumer_properties

在您的情况下,您可以通过执行以下操作来设置:

spring.cloud.stream.kafka.bindings.<channelName>.consumer.configuration.value.deserializer=<Deserialzier class>

Kafka binder 从配置映射中获取所有属性。因此,您可以使用任何通用的 Kafka 消费者属性并以这种方式传递它们。

【讨论】:

    【解决方案3】:

    当我添加 content-type:plain/textspring.cloud.stream.bindings.&lt;subscriptionChannel&gt;.consumer.‌​headerMode:raw 时,它起作用了。

    谢谢!

    【讨论】:

      猜你喜欢
      • 2018-03-09
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-01-22
      • 2018-12-16
      • 2021-02-17
      • 1970-01-01
      相关资源
      最近更新 更多