[英]Why is there a "topic" parameter in the overridden serialize() method from Serializer<> interface in org.apache.kafka.common.serialization
I have observed that implementations of the method serialize() of the Serializer<> interface has two parameters:我观察到 Serializer<> 接口的方法 serialize() 的实现有两个参数:
byte[] serialize(String topic, T data) byte[] 序列化(字符串主题,T 数据)
but the method body does not require String topic parameter at all.但方法体根本不需要字符串主题参数。 So why does it exist?
那么它为什么存在呢?
Sample Implementation available in the package org.apache.kafka.common.serialization: package org.apache.kafka.common.serialization 中提供的示例实现:
@Override
public byte[] serialize(String topic, String data) {
try {
if (data == null)
return null;
else
return data.getBytes(encoding);
} catch (UnsupportedEncodingException e) {
throw new SerializationException("Error when serializing string to byte[] due to unsupported encoding " + encoding);
}
}
In this specific implementation, indeed there's no usage.在这个具体的实现中,确实没有什么用处。 Yet, this parameter may be used by different / advanced Serializers.
然而,这个参数可能被不同的/高级的序列化器使用。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.