Class GenericAvroSerde
java.lang.Object
io.confluent.kafka.streams.serdes.avro.GenericAvroSerde
- All Implemented Interfaces:
Closeable,AutoCloseable,org.apache.kafka.common.serialization.Serde<org.apache.avro.generic.GenericRecord>
public class GenericAvroSerde
extends Object
implements org.apache.kafka.common.serialization.Serde<org.apache.avro.generic.GenericRecord>
A schema-registry aware serde (serializer/deserializer) for Apache Kafka's Streams API that can
be used for reading and writing data in "generic Avro" format. This serde's "specific Avro"
counterpart is
SpecificAvroSerde.
This serde reads and writes data according to the wire format defined at
http://docs.confluent.io/current/schema-registry/docs/serializer-formatter.html#wire-format.
It requires access to a Confluent Schema Registry endpoint, which you must
GenericAvroDeserializer.configure(Map, boolean) via the parameter
"schema.registry.url".
Usage
Example for configuring this serde as a Kafka Streams application's default serde for both record keys and record values:
Properties streamsConfiguration = new Properties();
streamsConfiguration.put(StreamsConfig.KEY_SERDE_CLASS_CONFIG, GenericAvroSerde.class);
streamsConfiguration.put(StreamsConfig.VALUE_SERDE_CLASS_CONFIG, GenericAvroSerde.class);
streamsConfiguration.put(
AbstractKafkaSchemaSerDeConfig.SCHEMA_REGISTRY_URL_CONFIG,
"http://confluent-schema-registry-server:8081/");
Example for explicitly overriding the application's default serdes (whatever they were
configured to) so that only specific operations such as KStream#to() use this serde:
Serde<GenericRecord> genericAvroSerde = new GenericAvroSerde();
boolean isKeySerde = false;
genericAvroSerde.configure(
Collections.singletonMap(
AbstractKafkaSchemaSerDeConfig.SCHEMA_REGISTRY_URL_CONFIG,
"http://confluent-schema-registry-server:8081/"),
isKeySerde);
KStream<String, GenericRecord> stream = ...;
stream.to(Serdes.String(), genericAvroSerde, "my-output-topic");
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidclose()voidorg.apache.kafka.common.serialization.Deserializer<org.apache.avro.generic.GenericRecord>org.apache.kafka.common.serialization.Serializer<org.apache.avro.generic.GenericRecord>
-
Constructor Details
-
GenericAvroSerde
public GenericAvroSerde() -
GenericAvroSerde
For testing purposes only.
-
-
Method Details
-
serializer
public org.apache.kafka.common.serialization.Serializer<org.apache.avro.generic.GenericRecord> serializer()- Specified by:
serializerin interfaceorg.apache.kafka.common.serialization.Serde<org.apache.avro.generic.GenericRecord>
-
deserializer
public org.apache.kafka.common.serialization.Deserializer<org.apache.avro.generic.GenericRecord> deserializer()- Specified by:
deserializerin interfaceorg.apache.kafka.common.serialization.Serde<org.apache.avro.generic.GenericRecord>
-
configure
- Specified by:
configurein interfaceorg.apache.kafka.common.serialization.Serde<org.apache.avro.generic.GenericRecord>
-
close
public void close()- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable- Specified by:
closein interfaceorg.apache.kafka.common.serialization.Serde<org.apache.avro.generic.GenericRecord>
-