Package com.azure.data.schemaregistry
Class SchemaRegistryClient
java.lang.Object
com.azure.data.schemaregistry.SchemaRegistryClient
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());
-
Method Summary
Modifier and TypeMethodDescriptionGets the fully qualified namespace of the Schema Registry instance.Gets the schema properties of the schema associated with the unique schema id.getSchemaProperties
(String groupName, String name, String schemaDefinition, SchemaFormat format) Gets schema properties for a schema with matchinggroupName
,name
,schemaDefinition
, andformat
.getSchemaPropertiesWithResponse
(String groupName, String name, String schemaDefinition, SchemaFormat format, Context context) Gets schema properties for a schema with matchinggroupName
,name
,schemaDefinition
, andformat
along with its HTTP response.getSchemaWithResponse
(String schemaId, Context context) Gets the schema properties of the schema associated with the unique schema id.registerSchema
(String groupName, String name, String schemaDefinition, SchemaFormat format) Registers a new schema in the specified schema group with the given schema name.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.
-
Method Details
-
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 samegroupName
,name
,format
, andschemaDefinition
, it is added to the Schema Registry Instance and assigned a schema id. If a schema exists with a matchinggroupName
,name
,format
, andschemaDefinition
, the id of that schema is returned. If the Schema Registry instance contains an existinggroupName
,name
, andformat
but theschemaDefinition
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
- ifgroupName
,name
,format
, orschemaDefinition
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 samegroupName
,name
,format
, andschemaDefinition
, it is added to the Schema Registry Instance and assigned a schema id. If a schema exists with a matchinggroupName
,name
,format
, andschemaDefinition
, the id of that schema is returned. If the Schema Registry instance contains an existinggroupName
,name
, andformat
but theschemaDefinition
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
- ifgroupName
,name
,format
, orschemaDefinition
are null.HttpResponseException
- if an issue was encountered while registering the schema.
-
getSchema
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 givenschemaId
. - Throws:
NullPointerException
- ifschemaId
is null.ResourceNotFoundException
- if a schema with the matchingschemaId
could not be found.HttpResponseException
- if an issue was encountered while fetching the schema.
-
getSchemaWithResponse
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 givenschemaId
and its HTTP response. - Throws:
NullPointerException
- ifschemaId
is null.ResourceNotFoundException
- if a schema with the matchingschemaId
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 matchinggroupName
,name
,schemaDefinition
, andformat
.- 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
- ifgroupName
,name
,schemaDefinition
, orformat
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 matchinggroupName
,name
,schemaDefinition
, andformat
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
- ifgroupName
,name
,schemaDefinition
, orformat
is null.ResourceNotFoundException
- if a schema with matching parameters could not be located.HttpResponseException
- if an issue was encountered while finding a matching schema.
-