Class ValueAsBytesSerializer
- java.lang.Object
-
- cz.o2.proxima.direct.io.kafka.serializer.ValueAsBytesSerializer
-
- All Implemented Interfaces:
ElementSerializer<byte[],byte[]>
,java.io.Serializable
public class ValueAsBytesSerializer extends java.lang.Object implements ElementSerializer<byte[],byte[]>
AElementSerializer
that reads values from kafka (discards keys) and returns values as byte arrays.You must subclass this class to create zero-parameter constructor.
- See Also:
- Serialized Form
-
-
Constructor Summary
Constructors Modifier Constructor Description protected
ValueAsBytesSerializer(UnaryFunction<EntityDescriptor,AttributeDescriptor<byte[]>> readAttributeFn)
protected
ValueAsBytesSerializer(java.lang.String attrName)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description org.apache.kafka.common.serialization.Serde<byte[]>
keySerde()
RetrieveSerde
for type K.StreamElement
read(org.apache.kafka.clients.consumer.ConsumerRecord<byte[],byte[]> consumerRecord, EntityDescriptor entityDescriptor)
Parse the raw bytes from Kafka and return aStreamElement
.void
setup(EntityDescriptor entityDescriptor)
Life-cycle method called after being instantiated to be able to parameterize itself from the givenEntityDescriptor
.org.apache.kafka.common.serialization.Serde<byte[]>
valueSerde()
RetrieveSerde
for type V.org.apache.kafka.clients.producer.ProducerRecord<byte[],byte[]>
write(java.lang.String topic, int partition, StreamElement streamElement)
ConvertStreamElement
intoProducerRecord
.-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface cz.o2.proxima.direct.io.kafka.ElementSerializer
storesSequentialId
-
-
-
-
Constructor Detail
-
ValueAsBytesSerializer
protected ValueAsBytesSerializer(java.lang.String attrName)
-
ValueAsBytesSerializer
protected ValueAsBytesSerializer(UnaryFunction<EntityDescriptor,AttributeDescriptor<byte[]>> readAttributeFn)
-
-
Method Detail
-
setup
public void setup(EntityDescriptor entityDescriptor)
Description copied from interface:ElementSerializer
Life-cycle method called after being instantiated to be able to parameterize itself from the givenEntityDescriptor
.- Specified by:
setup
in interfaceElementSerializer<byte[],byte[]>
- Parameters:
entityDescriptor
- the entity that this serializer will be used for
-
read
@Nullable public StreamElement read(org.apache.kafka.clients.consumer.ConsumerRecord<byte[],byte[]> consumerRecord, EntityDescriptor entityDescriptor)
Description copied from interface:ElementSerializer
Parse the raw bytes from Kafka and return aStreamElement
.- Specified by:
read
in interfaceElementSerializer<byte[],byte[]>
- Parameters:
consumerRecord
- aConsumerRecord
to be parsedentityDescriptor
- descriptor of entity being read- Returns:
- the
StreamElement
or null on parse error
-
write
public org.apache.kafka.clients.producer.ProducerRecord<byte[],byte[]> write(java.lang.String topic, int partition, StreamElement streamElement)
Description copied from interface:ElementSerializer
ConvertStreamElement
intoProducerRecord
.- Specified by:
write
in interfaceElementSerializer<byte[],byte[]>
- Parameters:
topic
- the target topicpartition
- the target partitionstreamElement
- theStreamElement
to convert- Returns:
- the
ProducerRecord
to write to Kafka
-
keySerde
public org.apache.kafka.common.serialization.Serde<byte[]> keySerde()
Description copied from interface:ElementSerializer
RetrieveSerde
for type K.- Specified by:
keySerde
in interfaceElementSerializer<byte[],byte[]>
- Returns:
Serde
for key
-
valueSerde
public org.apache.kafka.common.serialization.Serde<byte[]> valueSerde()
Description copied from interface:ElementSerializer
RetrieveSerde
for type V.- Specified by:
valueSerde
in interfaceElementSerializer<byte[],byte[]>
- Returns:
Serde
for value
-
-