14 строки
5.7 KiB
YAML
14 строки
5.7 KiB
YAML
### YamlMime:JavaPackage
|
|
uid: "com.azure.data.schemaregistry.apacheavro"
|
|
fullName: "com.azure.data.schemaregistry.apacheavro"
|
|
name: "com.azure.data.schemaregistry.apacheavro"
|
|
summary: "Microsoft Azure client library for Schema Registry Apache Avro Serializer provides support for serializing and deserializing Apache Avro objects with schemas stored in [Azure Schema Registry][].\n\n\n[Azure Schema Registry]: https://learn.microsoft.com/azure/event-hubs/schema-registry-overview"
|
|
classes:
|
|
- "com.azure.data.schemaregistry.apacheavro.SchemaRegistryApacheAvroException"
|
|
- "com.azure.data.schemaregistry.apacheavro.SchemaRegistryApacheAvroSerializer"
|
|
- "com.azure.data.schemaregistry.apacheavro.SchemaRegistryApacheAvroSerializerBuilder"
|
|
desc: "Microsoft Azure client library for Schema Registry Apache Avro Serializer provides support for serializing and deserializing Apache Avro objects with schemas stored in [Azure Schema Registry][].\n\n## Key Concepts ##\n\n * **Schema:** Text describing the how to deserialize and serialize an object.\n * **Schema Registry:** Centralized location for event producers and consumers to fetch schemas used to serialize and deserialized structured data.\n * **[Apache Avro][]:** Serialization format for data.\n\n## Getting Started ##\n\nThe starting point for creating clients is via builders. The examples shown in this document use a credential object named DefaultAzureCredential for authentication, which is appropriate for most scenarios, including local development and production environments. Additionally, we recommend using [managed identity][] for authentication in production environments. You can find more information on different ways of authenticating and their corresponding credential types in the [Azure Identity documentation\"][Azure Identity documentation].\n\n**Sample: Construct the serializer**\n\nThe following code demonstrates the creation of <xref uid=\"com.azure.data.schemaregistry.apacheavro.SchemaRegistryApacheAvroSerializer\" data-throw-if-not-resolved=\"false\" data-raw-source=\"com.azure.data.schemaregistry.apacheavro.SchemaRegistryApacheAvroSerializer\"></xref>. The credential used is `DefaultAzureCredential` because it combines commonly used credentials in deployment and development and chooses the credential to used based on its running environment.\n\n```java\nTokenCredential tokenCredential = new DefaultAzureCredentialBuilder().build();\n SchemaRegistryAsyncClient schemaRegistryAsyncClient = new SchemaRegistryClientBuilder()\n .credential(tokenCredential)\n .fullyQualifiedNamespace(\"{schema-registry-endpoint}\")\n .buildAsyncClient();\n\n SchemaRegistryApacheAvroSerializer serializer = new SchemaRegistryApacheAvroSerializerBuilder()\n .schemaRegistryClient(schemaRegistryAsyncClient)\n .schemaGroup(\"{schema-group}\")\n .buildSerializer();\n```\n\n**Sample: Serialize an object**\n\nThe serializer can serialize objects into any class extending from <xref uid=\"com.azure.core.models.MessageContent\" data-throw-if-not-resolved=\"false\" data-raw-source=\"com.azure.core.models.MessageContent\"></xref>. `EventData` extends from <xref uid=\"com.azure.core.models.MessageContent\" data-throw-if-not-resolved=\"false\" data-raw-source=\"com.azure.core.models.MessageContent\"></xref>, so the object can be serialized seamlessly.\n\nThe serializer assumes there is a no argument constructor used to instantiate the <xref uid=\"com.azure.core.models.MessageContent\" data-throw-if-not-resolved=\"false\" data-raw-source=\"com.azure.core.models.MessageContent\"></xref> type. If there is a different way to instantiate the concrete type, use the overload which takes a message factory function, <xref uid=\"com.azure.data.schemaregistry.apacheavro.SchemaRegistryApacheAvroSerializer.serialize*\" data-throw-if-not-resolved=\"false\" data-raw-source=\"com.azure.data.schemaregistry.apacheavro.SchemaRegistryApacheAvroSerializer#serialize(java.lang.Object, com.azure.core.util.serializer.TypeReference, java.util.function.Function)\"></xref>.\n\n```java\n// The object to encode. The Avro schema is:\n // {\n // \"namespace\": \"com.azure.data.schemaregistry.apacheavro.generatedtestsources\",\n // \"type\": \"record\",\n // \"name\": \"Person\",\n // \"fields\": [\n // {\"name\":\"name\", \"type\": \"string\"},\n // {\"name\":\"favourite_number\", \"type\": [\"int\", \"null\"]},\n // {\"name\":\"favourite_colour\", \"type\": [\"string\", \"null\"]}\n // ]\n // }\n Person person = Person.newBuilder()\n .setName(\"Chase\")\n .setFavouriteColour(\"Turquoise\")\n .setFavouriteNumber(3)\n .build();\n\n EventData eventData = serializer.serialize(person, TypeReference.createInstance(EventData.class));\n```\n\n**Sample: Deserialize an object**\n\nThe serializer can deserialize messages that were created using any of the serialize methods. In the sample, `EventData` is created by serializing the Avro-generated object, Person.\n\n```java\n// EventData created from the Avro generated object, person.\n EventData eventData = serializer.serialize(person, TypeReference.createInstance(EventData.class));\n\n Person deserialized = serializer.deserialize(eventData, TypeReference.createInstance(Person.class));\n\n System.out.printf(\"Name: %s, Number: %s%n\", deserialized.getName(), deserialized.getFavouriteNumber());\n```\n\n\n[Azure Schema Registry]: https://learn.microsoft.com/azure/event-hubs/schema-registry-overview\n[Apache Avro]: https://avro.apache.org/\n[managed identity]: https://learn.microsoft.com/azure/active-directory/managed-identities-azure-resources/\n[Azure Identity documentation]: https://learn.microsoft.com/java/api/overview/azure/identity-readme"
|
|
metadata: {}
|
|
package: "com.azure.data.schemaregistry.apacheavro"
|
|
artifact: com.azure:azure-data-schemaregistry-apacheavro:1.1.22
|