SchemaRegistryApacheAvroSerializerBuilder Class

  • java.lang.Object
    • com.azure.data.schemaregistry.apacheavro.SchemaRegistryApacheAvroSerializerBuilder

public final class SchemaRegistryApacheAvroSerializerBuilder

The builder for instantiating a SchemaRegistryApacheAvroSerializer. Additional code samples are in SchemaRegistryApacheAvroSerializer.

Sample: Creating a SchemaRegistryApacheAvroSerializer

The following code sample demonstrates the creation of the serializer and SchemaRegistryAsyncClient. The credential used to create the async client is DefaultAzureCredential because it combines commonly used credentials in deployment and development and chooses the credential to used based on its running environment.

TokenCredential tokenCredential = new DefaultAzureCredentialBuilder().build();
 SchemaRegistryAsyncClient schemaRegistryAsyncClient = new SchemaRegistryClientBuilder()
     .credential(tokenCredential)
     .fullyQualifiedNamespace("{schema-registry-endpoint}")
     .buildAsyncClient();

 SchemaRegistryApacheAvroSerializer serializer = new SchemaRegistryApacheAvroSerializerBuilder()
     .schemaRegistryClient(schemaRegistryAsyncClient)
     .schemaGroup("{schema-group}")
     .buildSerializer();

Constructor Summary

Constructor Description
SchemaRegistryApacheAvroSerializerBuilder()

Instantiates instance of this class.

Method Summary

Modifier and Type Method and Description
SchemaRegistryApacheAvroSerializerBuilder autoRegisterSchemas(boolean autoRegisterSchemas)

If true, the serializer will register schemas against Azure Schema Registry service under the specified group if it fails to find an existing schema to serialize.

SchemaRegistryApacheAvroSerializerBuilder avroSpecificReader(boolean avroSpecificReader)

Specifies if objects should be deserialized into Avro SpecificRecord via Avro's SpecificDatumReader.

SchemaRegistryApacheAvroSerializer buildSerializer()

Creates a new instance of Schema Registry serializer.

SchemaRegistryApacheAvroSerializerBuilder schemaGroup(String schemaGroup)

Specifies schema group for interacting with Azure Schema Registry service.

SchemaRegistryApacheAvroSerializerBuilder schemaRegistryClient(SchemaRegistryAsyncClient schemaRegistryAsyncClient)

The SchemaRegistryAsyncClient to use to interact with the Schema Registry service.

Methods inherited from java.lang.Object

Constructor Details

SchemaRegistryApacheAvroSerializerBuilder

public SchemaRegistryApacheAvroSerializerBuilder()

Instantiates instance of this class. By default, autoRegisterSchemas(boolean autoRegisterSchemas) is false and avroSpecificReader(boolean avroSpecificReader) is false.

Method Details

autoRegisterSchemas

public SchemaRegistryApacheAvroSerializerBuilder autoRegisterSchemas(boolean autoRegisterSchemas)

If true, the serializer will register schemas against Azure Schema Registry service under the specified group if it fails to find an existing schema to serialize. See Azure Schema Registry documentation for a description of schema registration behavior.

If specified false, serializer will query the service for an existing ID given schema content. Serialization will fail if the schema has not been pre-created.

Auto-registration is NOT RECOMMENDED for production scenarios.

Parameters:

autoRegisterSchemas - flag for schema auto-registration

Returns:

avroSpecificReader

public SchemaRegistryApacheAvroSerializerBuilder avroSpecificReader(boolean avroSpecificReader)

Specifies if objects should be deserialized into Avro SpecificRecord via Avro's SpecificDatumReader. If false then GenericDatumReader is used.

Parameters:

avroSpecificReader - true to deserialize into SpecificRecord via SpecificDatumReader; false otherwise.

Returns:

buildSerializer

public SchemaRegistryApacheAvroSerializer buildSerializer()

Creates a new instance of Schema Registry serializer.

Returns:

schemaGroup

public SchemaRegistryApacheAvroSerializerBuilder schemaGroup(String schemaGroup)

Specifies schema group for interacting with Azure Schema Registry service. This is optional unless autoRegisterSchemas(boolean autoRegisterSchemas) is set to true.

If auto-registering schemas, schema will be stored under this group. If not auto-registering, serializer will request schema ID for matching data schema under specified group.

Parameters:

schemaGroup - Schema Registry group name.

Returns:

schemaRegistryClient

public SchemaRegistryApacheAvroSerializerBuilder schemaRegistryClient(SchemaRegistryAsyncClient schemaRegistryAsyncClient)

The SchemaRegistryAsyncClient to use to interact with the Schema Registry service.

Parameters:

schemaRegistryAsyncClient - The SchemaRegistryAsyncClient.

Returns:

Applies to