一、序列化器剖析
### --- 序列化器
~~~ 由于Kafka中的数据都是字节数组,在将消息发送到Kafka之前需要先将数据序列化为字节数组。
~~~ 序列化器的作用就是用于序列化要发送的消息的。
~~~ Kafka使用org.apache.kafka.common.serialization.Serializer 接口用于定义序列化器,
~~~ 将泛型指定类型的数据转换为字节数组。
二、序列化器官方实现
### --- serialization实现序列化器
~~~ org.apache.kafka.common.serialization
package org.apache.kafka.common.serialization;
import java.io.Closeable;
import java.util.Map;
/**
* An interface for converting objects to bytes.
*
* A class that implements this interface is expected to have a constructor with no parameter.
* <p>
* Implement {@link org.apache.kafka.common.ClusterResourceListener} to receive cluster metadata once it's available. Please see the class documentation for ClusterResourceListener for more information.
*
* @param <T> Type to be serialized from.
*/
public interface Serializer<T> extends Closeable {
/**
* Configure this class.
* @param conf

最低0.47元/天 解锁文章

被折叠的 条评论
为什么被折叠?



