Spring Kafka JsonSerializer 用法

Spring Kafka JsonSerializer usage

我正在尝试按照此处的说明进行操作:

http://docs.spring.io/spring-kafka/docs/1.1.1.RELEASE/reference/htmlsingle/#_serialization_deserialization_and_message_conversion

设置一个 KafkaTemplate,它可以序列化并发送我拥有的一些简单的 Java POJO。但是我发现文档含糊不清,尤其是这一部分:

For this purpose Spring for Apache Kafka also provides JsonSerializer/JsonDeserializer implementations based on the Jackson JSON processor. When JsonSerializer is pretty simple and just lets to write any Java object as a JSON byte[]

...

Although Serializer/Deserializer API is pretty simple and flexible from the low-level Kafka Consumer and Producer perspective, it is not enough on the Messaging level, where KafkaTemplate and @KafkaListener are present.

...

The MessageConverter can be injected into KafkaTemplate instance directly and via AbstractKafkaListenerContainerFactory bean definition for the @KafkaListener.containerFactory() property

所以我的问题是:

如果这些是愚蠢的问题,我深表歉意 - 我正在尝试了解正确的设置方式,而不是 "hacking it till it kinda works"。

  1. <String, Object>

  2. JsonSerializer

  3. 消息转换器仅在使用带有 Message<?> 的发送时使用,而对于 JsonSerializer 您应该使用默认的。