|
1 | | -# Azure Schema Registry client library for Java |
| 1 | +# Azure SchemaRegistry client library for Java |
2 | 2 |
|
3 | | -Azure Schema Registry is a schema repository service hosted by Azure Event Hubs, providing schema storage, versioning, |
4 | | -and management. The registry is leveraged by applications to reduce payload size while describing payload structure with |
5 | | -schema identifiers rather than full schemas. |
| 3 | +Azure SchemaRegistry client library for Java. |
6 | 4 |
|
7 | | -[Source code][source_code] | [Package (Maven)][package_maven] | [API reference documentation][api_reference_doc] | [Product Documentation][product_documentation] | [Samples][sample_readme] |
| 5 | +This package contains Microsoft Azure SchemaRegistry client library. |
8 | 6 |
|
9 | | -## Getting started |
10 | | - |
11 | | -### Prerequisites |
| 7 | +## Documentation |
12 | 8 |
|
13 | | -- A [Java Development Kit (JDK)][jdk_link], version 8 or later. |
14 | | -- [Azure Subscription][azure_subscription] |
15 | | -- An [Event Hubs schema registry][event_hubs_namespace] |
16 | | - |
17 | | -### Include the package |
| 9 | +Various documentation is available to help you get started |
18 | 10 |
|
19 | | -#### Include the BOM file |
| 11 | +- [API reference documentation][docs] |
| 12 | +- [Product documentation][product_documentation] |
20 | 13 |
|
21 | | -Please include the azure-sdk-bom to your project to take dependency on the General Availability (GA) version of the library. In the following snippet, replace the {bom_version_to_target} placeholder with the version number. |
22 | | -To learn more about the BOM, see the [AZURE SDK BOM README](https://github.com/Azure/azure-sdk-for-java/blob/main/sdk/boms/azure-sdk-bom/README.md). |
| 14 | +## Getting started |
23 | 15 |
|
24 | | -```xml |
25 | | -<dependencyManagement> |
26 | | - <dependencies> |
27 | | - <dependency> |
28 | | - <groupId>com.azure</groupId> |
29 | | - <artifactId>azure-sdk-bom</artifactId> |
30 | | - <version>{bom_version_to_target}</version> |
31 | | - <type>pom</type> |
32 | | - <scope>import</scope> |
33 | | - </dependency> |
34 | | - </dependencies> |
35 | | -</dependencyManagement> |
36 | | -``` |
37 | | -and then include the direct dependency in the dependencies section without the version tag as shown below. |
| 16 | +### Prerequisites |
38 | 17 |
|
39 | | -```xml |
40 | | -<dependencies> |
41 | | - <dependency> |
42 | | - <groupId>com.azure</groupId> |
43 | | - <artifactId>azure-data-schemaregistry</artifactId> |
44 | | - </dependency> |
45 | | -</dependencies> |
46 | | -``` |
| 18 | +- [Java Development Kit (JDK)][jdk] with version 8 or above |
| 19 | +- [Azure Subscription][azure_subscription] |
47 | 20 |
|
48 | | -#### Include direct dependency |
49 | | -If you want to take dependency on a particular version of the library that is not present in the BOM, |
50 | | -add the direct dependency to your project as follows. |
| 21 | +### Adding the package to your product |
51 | 22 |
|
52 | 23 | [//]: # ({x-version-update-start;com.azure:azure-data-schemaregistry;current}) |
53 | 24 | ```xml |
54 | | -<dependency> |
55 | | - <groupId>com.azure</groupId> |
56 | | - <artifactId>azure-data-schemaregistry</artifactId> |
57 | | - <version>1.6.0-beta.1</version> |
58 | | -</dependency> |
59 | | -``` |
60 | | -[//]: # ({x-version-update-end}) |
61 | | - |
62 | | -### Authenticate the client |
63 | | -In order to interact with the Azure Schema Registry service, you'll need to create an instance of the |
64 | | -`SchemaRegistryClient` class through the `SchemaRegistryClientBuilder`. You will need an **endpoint** and an |
65 | | -**API key** to instantiate a client object. |
66 | | - |
67 | | -#### Create SchemaRegistryClient with Azure Active Directory Credential |
68 | | - |
69 | | -You can authenticate with Azure Active Directory using the [Azure Identity library][azure_identity]. Note that regional endpoints do not support AAD authentication. Create a [custom subdomain][custom_subdomain] for your resource in order to use this type of authentication. |
70 | | - |
71 | | -To use the [DefaultAzureCredential][DefaultAzureCredential] provider shown below, or other credential providers provided with the Azure SDK, please include the `azure-identity` package: |
72 | | - |
73 | | -[//]: # ({x-version-update-start;com.azure:azure-identity;dependency}) |
74 | | -```xml |
75 | 25 | <dependency> |
76 | 26 | <groupId>com.azure</groupId> |
77 | | - <artifactId>azure-identity</artifactId> |
78 | | - <version>1.15.3</version> |
| 27 | + <artifactId>azure-data-schemaregistry</artifactId> |
| 28 | + <version>1.0.0-beta.1</version> |
79 | 29 | </dependency> |
80 | 30 | ``` |
| 31 | +[//]: # ({x-version-update-end}) |
81 | 32 |
|
82 | | -You will also need to [register a new AAD application][register_aad_app] and [grant access][aad_grant_access] to |
83 | | - Schema Registry service. |
84 | | - |
85 | | -Set the values of the client ID, tenant ID, and client secret of the AAD application as environment variables: AZURE_CLIENT_ID, AZURE_TENANT_ID, AZURE_CLIENT_SECRET. |
86 | | - |
87 | | -##### Async client |
88 | | - |
89 | | -```java com.azure.data.schemaregistry.schemaregistryasyncclient.construct |
90 | | -DefaultAzureCredential azureCredential = new DefaultAzureCredentialBuilder() |
91 | | - .build(); |
92 | | -SchemaRegistryAsyncClient client = new SchemaRegistryClientBuilder() |
93 | | - .fullyQualifiedNamespace("https://<your-schema-registry-endpoint>.servicebus.windows.net") |
94 | | - .credential(azureCredential) |
95 | | - .buildAsyncClient(); |
96 | | -``` |
97 | | - |
98 | | -##### Sync client |
| 33 | +### Authentication |
99 | 34 |
|
100 | | -```java com.azure.data.schemaregistry.schemaregistryclient.construct |
101 | | -DefaultAzureCredential azureCredential = new DefaultAzureCredentialBuilder() |
102 | | - .build(); |
103 | | -SchemaRegistryClient client = new SchemaRegistryClientBuilder() |
104 | | - .fullyQualifiedNamespace("https://<your-schema-registry-endpoint>.servicebus.windows.net") |
105 | | - .credential(azureCredential) |
106 | | - .buildClient(); |
107 | | -``` |
| 35 | +[Azure Identity][azure_identity] package provides the default implementation for authenticating the client. |
108 | 36 |
|
109 | 37 | ## Key concepts |
110 | | -### Schemas |
111 | | - |
112 | | -A schema has 6 components: |
113 | | -- Group Name: The name of the group of schemas in the Schema Registry instance. |
114 | | -- Schema Name: The name of the schema. |
115 | | -- Schema ID: The ID assigned by the Schema Registry instance for the schema. |
116 | | -- Serialization Type: The format used for serialization of the schema. For example, Avro. |
117 | | -- Schema Content: The string representation of the schema. |
118 | | -- Schema Version: The version assigned to the schema in the Schema Registry instance. |
119 | | - |
120 | | -These components play different roles. Some are used as input into the operations and some are outputs. Currently, |
121 | | -[SchemaProperties][schema_properties] only exposes those properties that are potential outputs that are used in |
122 | | -SchemaRegistry operations. Those exposed properties are `Content` and `Id`. |
123 | 38 |
|
124 | 39 | ## Examples |
125 | 40 |
|
126 | | -* [Register a schema](#register-a-schema) |
127 | | -* [Retrieve a schema's properties](#retrieve-a-schemas-properties) |
128 | | -* [Retrieve a schema](#retrieve-a-schema) |
129 | | - |
130 | | -### Register a schema |
131 | | -Register a schema to be stored in the Azure Schema Registry. |
132 | | - |
133 | | -```java com.azure.data.schemaregistry.schemaregistryclient.registerschema-avro |
134 | | -String schema = "{\"type\":\"enum\",\"name\":\"TEST\",\"symbols\":[\"UNIT\",\"INTEGRATION\"]}"; |
135 | | -SchemaProperties properties = client.registerSchema("{schema-group}", "{schema-name}", schema, |
136 | | - SchemaFormat.AVRO); |
137 | | - |
138 | | -System.out.printf("Schema id: %s, schema format: %s%n", properties.getId(), properties.getFormat()); |
| 41 | +```java com.azure.data.schemaregistry.readme |
139 | 42 | ``` |
140 | 43 |
|
141 | | -### Retrieve a schema's properties |
142 | | -Retrieve a previously registered schema's properties from the Azure Schema Registry. |
| 44 | +### Service API versions |
143 | 45 |
|
144 | | -```java com.azure.data.schemaregistry.schemaregistryclient.getschema |
145 | | -SchemaRegistrySchema schema = client.getSchema("{schema-id}"); |
| 46 | +The client library targets the latest service API version by default. |
| 47 | +The service client builder accepts an optional service API version parameter to specify which API version to communicate. |
146 | 48 |
|
147 | | -System.out.printf("Schema id: %s, schema format: %s%n", schema.getProperties().getId(), |
148 | | - schema.getProperties().getFormat()); |
149 | | -System.out.println("Schema contents: " + schema.getDefinition()); |
150 | | -``` |
| 49 | +#### Select a service API version |
151 | 50 |
|
152 | | -### Retrieve a schema |
153 | | -Retrieve a previously registered schema's content and properties from the Azure Schema Registry. |
154 | | - |
155 | | -```java com.azure.data.schemaregistry.schemaregistryclient.getschemaproperties |
156 | | -String schemaContent = "{\n" |
157 | | - + " \"type\" : \"record\", \n" |
158 | | - + " \"namespace\" : \"SampleSchemaNameSpace\", \n" |
159 | | - + " \"name\" : \"Person\", \n" |
160 | | - + " \"fields\" : [\n" |
161 | | - + " { \n" |
162 | | - + " \"name\" : \"FirstName\" , \"type\" : \"string\" \n" |
163 | | - + " }, \n" |
164 | | - + " { \n" |
165 | | - + " \"name\" : \"LastName\", \"type\" : \"string\" \n" |
166 | | - + " }\n" |
167 | | - + " ]\n" |
168 | | - + "}"; |
169 | | -SchemaProperties properties = client.getSchemaProperties("{schema-group}", "{schema-name}", |
170 | | - schemaContent, SchemaFormat.AVRO); |
171 | | - |
172 | | -System.out.println("Schema id: " + properties.getId()); |
173 | | -System.out.println("Format: " + properties.getFormat()); |
174 | | -System.out.println("Version: " + properties.getVersion()); |
175 | | -``` |
| 51 | +You have the flexibility to explicitly select a supported service API version when initializing a service client via the service client builder. |
| 52 | +This ensures that the client can communicate with services using the specified API version. |
176 | 53 |
|
177 | | -## Troubleshooting |
| 54 | +When selecting an API version, it is important to verify that there are no breaking changes compared to the latest API version. |
| 55 | +If there are significant differences, API calls may fail due to incompatibility. |
178 | 56 |
|
179 | | -### Enabling Logging |
| 57 | +Always ensure that the chosen API version is fully supported and operational for your specific use case and that it aligns with the service's versioning policy. |
180 | 58 |
|
181 | | -Azure SDKs for Java offer a consistent logging story to help aid in troubleshooting application errors and expedite |
182 | | -their resolution. The logs produced will capture the flow of an application before reaching the terminal state to help |
183 | | -locate the root issue. View the [logging][logging] wiki for guidance about enabling logging. |
| 59 | +## Troubleshooting |
184 | 60 |
|
185 | 61 | ## Next steps |
186 | | -More samples can be found [here][samples]. |
187 | 62 |
|
188 | 63 | ## Contributing |
189 | 64 |
|
190 | | -This project welcomes contributions and suggestions. Most contributions require you to agree to a [Contributor License Agreement (CLA)][cla] declaring that you have the right to, and actually do, grant us the rights to use your contribution. |
191 | | - |
192 | | -When you submit a pull request, a CLA-bot will automatically determine whether you need to provide a CLA and decorate the PR appropriately (e.g., label, comment). Simply follow the instructions provided by the bot. You will only need to do this once across all repos using our CLA. |
| 65 | +For details on contributing to this repository, see the [contributing guide](https://github.com/Azure/azure-sdk-for-java/blob/main/CONTRIBUTING.md). |
193 | 66 |
|
194 | | -This project has adopted the [Microsoft Open Source Code of Conduct ][coc]. For more information see the [Code of Conduct FAQ ][coc_faq] or contact [[email protected]][coc_contact] with any additional questions or comments. |
| 67 | +1. Fork it |
| 68 | +1. Create your feature branch (`git checkout -b my-new-feature`) |
| 69 | +1. Commit your changes (`git commit -am 'Add some feature'`) |
| 70 | +1. Push to the branch (`git push origin my-new-feature`) |
| 71 | +1. Create new Pull Request |
195 | 72 |
|
196 | 73 | <!-- LINKS --> |
197 | | -[package_maven]: https://central.sonatype.com/artifact/com.azure/azure-data-schemaregistry |
198 | | -[sample_readme]: https://github.com/Azure/azure-sdk-for-java/tree/main/sdk/schemaregistry/azure-data-schemaregistry/src/samples |
199 | | -[samples]: https://github.com/Azure/azure-sdk-for-java/blob/main/sdk/schemaregistry/azure-data-schemaregistry/src/samples/java/com/azure/data/schemaregistry |
200 | | -[source_code]: https://github.com/Azure/azure-sdk-for-java/blob/main/sdk/schemaregistry/azure-data-schemaregistry/src |
201 | | -[samples_code]: src/samples/ |
| 74 | +[product_documentation]: https://azure.microsoft.com/services/ |
| 75 | +[docs]: https://azure.github.io/azure-sdk-for-java/ |
| 76 | +[jdk]: https://learn.microsoft.com/azure/developer/java/fundamentals/ |
202 | 77 | [azure_subscription]: https://azure.microsoft.com/free/ |
203 | | -[api_reference_doc]: https://azure.github.io/azure-sdk-for-java/ |
204 | | -[azure_cli]: https://learn.microsoft.com/cli/azure |
205 | | -[azure_portal]: https://portal.azure.com |
206 | | -[azure_identity]: https://github.com/Azure/azure-sdk-for-java/tree/main/sdk/identity/azure-identity |
207 | | -[DefaultAzureCredential]: https://github.com/Azure/azure-sdk-for-java/blob/main/sdk/identity/azure-identity/README.md#defaultazurecredential |
208 | | -[event_hubs_namespace]: https://learn.microsoft.com/azure/event-hubs/create-schema-registry |
209 | | -[jdk_link]: https://learn.microsoft.com/java/azure/jdk/?view=azure-java-stable |
210 | | -[product_documentation]: https://aka.ms/schemaregistry |
211 | | -[custom_subdomain]: https://learn.microsoft.com/azure/cognitive-services/authentication#create-a-resource-with-a-custom-subdomain |
212 | | -[register_aad_app]: https://learn.microsoft.com/azure/cognitive-services/authentication#assign-a-role-to-a-service-principal |
213 | | -[aad_grant_access]: https://learn.microsoft.com/azure/cognitive-services/authentication#assign-a-role-to-a-service-principal |
214 | | -[schema_properties]: https://github.com/Azure/azure-sdk-for-java/blob/main/sdk/schemaregistry/azure-data-schemaregistry/src/main/java/com/azure/data/schemaregistry/models/SchemaProperties.java |
215 | | -[logging]: https://github.com/Azure/azure-sdk-for-java/wiki/Logging-in-Azure-SDK |
216 | | -[cla]: https://cla.microsoft.com |
217 | | -[coc]: https://opensource.microsoft.com/codeofconduct/ |
218 | | -[coc_faq]: https://opensource.microsoft.com/codeofconduct/faq/ |
219 | | -[coc_contact]: mailto:[email protected] |
220 | | - |
221 | | - |
| 78 | +[azure_identity]: https://github.com/Azure/azure-sdk-for-java/blob/main/sdk/identity/azure-identity |
0 commit comments