Class SchemaRegistryClient

java.lang.Object
com.azure.data.schemaregistry.SchemaRegistryClient

public final class SchemaRegistryClient extends Object
HTTP-based client that interacts with Azure Schema Registry service to store and retrieve schemas on demand.

Register a schema

Registering a schema returns a unique schema id that can be used to quickly associate payloads with that schema.
 String schema = "{\"type\":\"enum\",\"name\":\"TEST\",\"symbols\":[\"UNIT\",\"INTEGRATION\"]}";
 SchemaProperties properties = client.registerSchema("{schema-group}", "{schema-name}", schema,
     SchemaFormat.AVRO);

 System.out.printf("Schema id: %s, schema format: %s%n", properties.getId(), properties.getFormat());
 

Get a schema

 SchemaRegistrySchema schema = client.getSchema("{schema-id}");

 System.out.printf("Schema id: %s, schema format: %s%n", schema.getProperties().getId(),
     schema.getProperties().getFormat());
 System.out.println("Schema contents: " + schema.getDefinition());
 

Get a schema's properties

 String schema = "{\"type\":\"enum\",\"name\":\"TEST\",\"symbols\":[\"UNIT\",\"INTEGRATION\"]}";
 SchemaProperties properties = client.getSchemaProperties("{schema-group}", "{schema-name}", schema,
     SchemaFormat.AVRO);

 System.out.println("The schema id: " + properties.getId());
 
See Also:
  • Method Details

    • getFullyQualifiedNamespace

      public String getFullyQualifiedNamespace()
      Gets the fully qualified namespace of the Schema Registry instance.
      Returns:
      The fully qualified namespace of the Schema Registry instance.
    • registerSchema

      public SchemaProperties registerSchema(String groupName, String name, String schemaDefinition, SchemaFormat format)
      Registers a new schema in the specified schema group with the given schema name. If a schema does not existdoes not exist with the same groupName, name, format, and schemaDefinition, it is added to the Schema Registry Instance and assigned a schema id. If a schema exists with a matching groupName, name, format, and schemaDefinition, the id of that schema is returned. If the Schema Registry instance contains an existing groupName, name, and format but the schemaDefinition is different, it is considered a new version, and schema id is assigned to it.
      Parameters:
      groupName - The schema group.
      name - The schema name.
      schemaDefinition - The string representation of the schema.
      format - The serialization type of this schema.
      Returns:
      The schema properties on successful registration of the schema.
      Throws:
      NullPointerException - if groupName, name, format, or schemaDefinition are null.
      HttpResponseException - if an issue was encountered while registering the schema.
    • registerSchemaWithResponse

      public Response<SchemaProperties> registerSchemaWithResponse(String groupName, String name, String schemaDefinition, SchemaFormat format, Context context)
      Registers a new schema in the specified schema group with the given schema name. If a schema does not existdoes not exist with the same groupName, name, format, and schemaDefinition, it is added to the Schema Registry Instance and assigned a schema id. If a schema exists with a matching groupName, name, format, and schemaDefinition, the id of that schema is returned. If the Schema Registry instance contains an existing groupName, name, and format but the schemaDefinition is different, it is considered a new version, and schema id is assigned to it.
      Parameters:
      groupName - The schema group.
      name - The schema name.
      schemaDefinition - The string representation of the schema.
      format - The serialization type of this schema.
      context - The context to pass to the Http pipeline.
      Returns:
      The schema properties on successful registration of the schema.
      Throws:
      NullPointerException - if groupName, name, format, or schemaDefinition are null.
      HttpResponseException - if an issue was encountered while registering the schema.
    • getSchema

      public SchemaRegistrySchema getSchema(String schemaId)
      Gets the schema properties of the schema associated with the unique schema id.
      Parameters:
      schemaId - The unique identifier of the schema.
      Returns:
      The SchemaProperties associated with the given schemaId.
      Throws:
      NullPointerException - if schemaId is null.
      ResourceNotFoundException - if a schema with the matching schemaId could not be found.
      HttpResponseException - if an issue was encountered while fetching the schema.
    • getSchemaWithResponse

      public Response<SchemaRegistrySchema> getSchemaWithResponse(String schemaId, Context context)
      Gets the schema properties of the schema associated with the unique schema id.
      Parameters:
      schemaId - The unique identifier of the schema.
      context - The context to pass to the Http pipeline.
      Returns:
      The SchemaProperties associated with the given schemaId and its HTTP response.
      Throws:
      NullPointerException - if schemaId is null.
      ResourceNotFoundException - if a schema with the matching schemaId could not be found.
      HttpResponseException - if an issue was encountered while fetching the schema.
    • getSchemaProperties

      public SchemaProperties getSchemaProperties(String groupName, String name, String schemaDefinition, SchemaFormat format)
      Gets schema properties for a schema with matching groupName, name, schemaDefinition, and format.
      Parameters:
      groupName - The schema group.
      name - The schema name.
      schemaDefinition - The string representation of the schema.
      format - The serialization type of this schema.
      Returns:
      The properties for a matching schema.
      Throws:
      NullPointerException - if groupName, name, schemaDefinition, or format is null.
      ResourceNotFoundException - if a schema with matching parameters could not be located.
      HttpResponseException - if an issue was encountered while finding a matching schema.
    • getSchemaPropertiesWithResponse

      public Response<SchemaProperties> getSchemaPropertiesWithResponse(String groupName, String name, String schemaDefinition, SchemaFormat format, Context context)
      Gets schema properties for a schema with matching groupName, name, schemaDefinition, and format along with its HTTP response.
      Parameters:
      groupName - The schema group.
      name - The schema name.
      schemaDefinition - The string representation of the schema.
      format - The serialization type of this schema.
      context - The context to pass to the Http pipeline.
      Returns:
      A mono that completes with the properties for a matching schema.
      Throws:
      NullPointerException - if groupName, name, schemaDefinition, or format is null.
      ResourceNotFoundException - if a schema with matching parameters could not be located.
      HttpResponseException - if an issue was encountered while finding a matching schema.