Skip to content

Commit 7188fbd

Browse files
authored
Documentation and Sample Fixes for Schema Registry (Azure#26703)
* Adding SchemaId sync file. Renaming old file to GetSchemaIdSampleAsync. * Renaming GetSchemaSample.java to GetSchemaSampleAsync. * Fix documentation on getSchemaId. * Fixing documentation on samples. * Adding RegisterSchemaSample and renaming async sample to RegisterSchemaSampleAsync. * Updating README links. * Update README and readme samples. * Updating documentation for Client and clientbuilder.
1 parent 510491a commit 7188fbd

File tree

12 files changed

+188
-60
lines changed

12 files changed

+188
-60
lines changed

sdk/schemaregistry/azure-data-schemaregistry-apacheavro/README.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ with the Azure SDK, please include the `azure-identity` package:
5252
<dependency>
5353
<groupId>com.azure</groupId>
5454
<artifactId>azure-identity</artifactId>
55-
<version>1.4.1</version>
55+
<version>1.4.3</version>
5656
</dependency>
5757
```
5858

@@ -62,8 +62,10 @@ You will also need to [register a new AAD application][register_aad_app] and [gr
6262
```java readme-sample-createSchemaRegistryAsyncClient
6363
TokenCredential tokenCredential = new DefaultAzureCredentialBuilder().build();
6464

65+
// {schema-registry-endpoint} is the fully qualified namespace of the Event Hubs instance. It is usually
66+
// of the form "{your-namespace}.servicebus.windows.net"
6567
SchemaRegistryAsyncClient schemaRegistryAsyncClient = new SchemaRegistryClientBuilder()
66-
.fullyQualifiedNamespace("{schema-registry-endpoint")
68+
.fullyQualifiedNamespace("{your-event-hubs-namespace}.servicebus.windows.net")
6769
.credential(tokenCredential)
6870
.buildAsyncClient();
6971
```

sdk/schemaregistry/azure-data-schemaregistry-apacheavro/src/samples/java/com/azure/data/schemaregistry/apacheavro/ReadmeSamples.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,10 @@ public SchemaRegistryApacheAvroSerializer createAvroSchemaRegistrySerializer() {
2828
// BEGIN: readme-sample-createSchemaRegistryAsyncClient
2929
TokenCredential tokenCredential = new DefaultAzureCredentialBuilder().build();
3030

31+
// {schema-registry-endpoint} is the fully qualified namespace of the Event Hubs instance. It is usually
32+
// of the form "{your-namespace}.servicebus.windows.net"
3133
SchemaRegistryAsyncClient schemaRegistryAsyncClient = new SchemaRegistryClientBuilder()
32-
.fullyQualifiedNamespace("{schema-registry-endpoint")
34+
.fullyQualifiedNamespace("{your-event-hubs-namespace}.servicebus.windows.net")
3335
.credential(tokenCredential)
3436
.buildAsyncClient();
3537
// END: readme-sample-createSchemaRegistryAsyncClient

sdk/schemaregistry/azure-data-schemaregistry/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ To use the [DefaultAzureCredential][DefaultAzureCredential] provider shown below
4242
<dependency>
4343
<groupId>com.azure</groupId>
4444
<artifactId>azure-identity</artifactId>
45-
<version>1.4.1</version>
45+
<version>1.4.3</version>
4646
</dependency>
4747
```
4848

sdk/schemaregistry/azure-data-schemaregistry/src/main/java/com/azure/data/schemaregistry/SchemaRegistryClient.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,8 @@ public Response<SchemaRegistrySchema> getSchemaWithResponse(String schemaId, Con
148148
}
149149

150150
/**
151-
* Gets the schema properties associated with the given schema id.
151+
* Gets schema properties for a schema with matching {@code groupName}, {@code name}, {@code schemaDefinition}, and
152+
* {@code format}.
152153
*
153154
* @param groupName The schema group.
154155
* @param name The schema name.
@@ -169,7 +170,8 @@ public SchemaProperties getSchemaProperties(String groupName, String name, Strin
169170
}
170171

171172
/**
172-
* Gets the schema identifier associated with the given schema.
173+
* Gets schema properties for a schema with matching {@code groupName}, {@code name}, {@code schemaDefinition}, and
174+
* {@code format} along with its HTTP response.
173175
*
174176
* @param groupName The schema group.
175177
* @param name The schema name.

sdk/schemaregistry/azure-data-schemaregistry/src/main/java/com/azure/data/schemaregistry/SchemaRegistryClientBuilder.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ public class SchemaRegistryClientBuilder {
118118
private ServiceVersion serviceVersion;
119119

120120
/**
121-
* Constructor for CachedSchemaRegistryClientBuilder. Supplies client defaults.
121+
* Constructor for SchemaRegistryClientBuilder. Supplies client defaults.
122122
*/
123123
public SchemaRegistryClientBuilder() {
124124
this.httpLogOptions = new HttpLogOptions();

sdk/schemaregistry/azure-data-schemaregistry/src/samples/README.md

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,12 @@ Please refer to the [Getting Started][sdk_readme_getting_started] section.
2222

2323
## Examples
2424

25-
- [Serialize an object into avro schema bytes][sample_avro_serialization]
26-
- [Deserialize avro serialized bytes into a strongly-typed object][sample_avro_deserialization]
25+
- [Register a schema][sample_register_schema]
26+
- [Register a schema using async client][sample_register_schema_async]
27+
- [Get schema][sample_get_schema]
28+
- [Get schema using async client][sample_get_schema_async]
29+
- [Get schema id][sample_get_schema_id]
30+
- [Get schema id using async client][sample_get_schema_id_async]
2731

2832
## Troubleshooting
2933
See [Troubleshooting][sdk_readme_troubleshooting].
@@ -40,8 +44,11 @@ This project welcomes contributions and suggestions. See [Contributing][sdk_read
4044
[sdk_readme_troubleshooting]: https://github.com/Azure/azure-sdk-for-java/blob/main/sdk/schemaregistry/azure-data-schemaregistry/README.md#troubleshooting
4145
[sdk_readme_next_steps]: https://github.com/Azure/azure-sdk-for-java/blob/main/sdk/schemaregistry/azure-data-schemaregistry/README.md#next-steps
4246
[sdk_readme_contributing]: https://github.com/Azure/azure-sdk-for-java/blob/main/sdk/schemaregistry/azure-data-schemaregistry/README.md#contributing
43-
[sample_register_schema]: ./java/com/azure/data/schemaregistry/RegisterSchemaSample.java
44-
[sample_get_schema]: ./java/com/azure/data/schemaregistry/GetSchemaSample.java
45-
[sample_get_schema_id]: ./java/com/azure/data/schemaregistry/GetSchemaIdSample.java
47+
[sample_register_schema]: https://github.com/Azure/azure-sdk-for-java/tree/main/sdk/schemaregistry/azure-data-schemaregistry/src/samples/java/com/azure/data/schemaregistry/RegisterSchemaSample.java
48+
[sample_register_schema_async]: https://github.com/Azure/azure-sdk-for-java/tree/main/sdk/schemaregistry/azure-data-schemaregistry/src/samples/java/com/azure/data/schemaregistry/RegisterSchemaSampleAsync.java
49+
[sample_get_schema]: https://github.com/Azure/azure-sdk-for-java/tree/main/sdk/schemaregistry/azure-data-schemaregistry/src/samples/java/com/azure/data/schemaregistry/GetSchemaSample.java
50+
[sample_get_schema_async]: https://github.com/Azure/azure-sdk-for-java/tree/main/sdk/schemaregistry/azure-data-schemaregistry/src/samples/java/com/azure/data/schemaregistry/GetSchemaSampleAsync.java
51+
[sample_get_schema_id]: https://github.com/Azure/azure-sdk-for-java/tree/main/sdk/schemaregistry/azure-data-schemaregistry/src/samples/java/com/azure/data/schemaregistry/GetSchemaIdSample.java
52+
[sample_get_schema_id_async]: https://github.com/Azure/azure-sdk-for-java/tree/main/sdk/schemaregistry/azure-data-schemaregistry/src/samples/java/com/azure/data/schemaregistry/GetSchemaIdSampleAsync.java
4653

4754
![Impressions](https://azure-sdk-impressions.azurewebsites.net/api/impressions/azure-sdk-for-java%2Fsdk%schemaregistry%2Fazure-data-schemaregistry%2Fsrc%2Fsamples%2README.png)

sdk/schemaregistry/azure-data-schemaregistry/src/samples/java/com/azure/data/schemaregistry/GetSchemaIdSample.java

Lines changed: 11 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -5,38 +5,32 @@
55

66
import com.azure.core.credential.TokenCredential;
77
import com.azure.data.schemaregistry.models.SchemaFormat;
8+
import com.azure.data.schemaregistry.models.SchemaProperties;
89
import com.azure.identity.DefaultAzureCredentialBuilder;
910

10-
import java.util.concurrent.CountDownLatch;
11-
1211
/**
13-
* Sample to demonstrate retrieving the schema id of a schema from Schema Registry.
12+
* Sample to demonstrate retrieving properties of a schema from Schema Registry.
13+
*
14+
* @see GetSchemaIdSampleAsync for the async sample.
1415
*/
1516
public class GetSchemaIdSample {
1617

1718
/**
1819
* The main method to run this program.
1920
* @param args Ignored args.
2021
*/
21-
public static void main(String[] args) throws InterruptedException {
22+
public static void main(String[] args) {
2223
TokenCredential tokenCredential = new DefaultAzureCredentialBuilder().build();
2324

24-
SchemaRegistryAsyncClient schemaRegistryAsyncClient = new SchemaRegistryClientBuilder()
25+
SchemaRegistryClient schemaRegistryClient = new SchemaRegistryClientBuilder()
2526
.fullyQualifiedNamespace("{schema-registry-endpoint")
2627
.credential(tokenCredential)
27-
.buildAsyncClient();
28-
29-
CountDownLatch countDownLatch = new CountDownLatch(1);
30-
// Register a schema
31-
schemaRegistryAsyncClient
32-
.getSchemaProperties("{group-name}", "{schema-name}", "{schema-string}", SchemaFormat.AVRO)
33-
.subscribe(schemaId -> {
34-
System.out.println("Successfully retrieved the schema id: " + schemaId);
35-
countDownLatch.countDown();
36-
});
28+
.buildClient();
3729

38-
// wait for the async task to complete
39-
countDownLatch.await();
30+
// Gets the properties of an existing schema.
31+
SchemaProperties schemaProperties = schemaRegistryClient
32+
.getSchemaProperties("{group-name}", "{schema-name}", "{schema-string}", SchemaFormat.AVRO);
4033

34+
System.out.println("Successfully retrieved the schema id: " + schemaProperties.getId());
4135
}
4236
}
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
// Copyright (c) Microsoft Corporation. All rights reserved.
2+
// Licensed under the MIT License.
3+
4+
package com.azure.data.schemaregistry;
5+
6+
import com.azure.core.credential.TokenCredential;
7+
import com.azure.data.schemaregistry.models.SchemaFormat;
8+
import com.azure.identity.DefaultAzureCredentialBuilder;
9+
10+
import java.util.concurrent.CountDownLatch;
11+
12+
/**
13+
* Sample to demonstrate retrieving properties of a schema from Schema Registry using async client.
14+
*
15+
* @see GetSchemaIdSample for the synchronous sample.
16+
*/
17+
public class GetSchemaIdSampleAsync {
18+
19+
/**
20+
* The main method to run this program.
21+
* @param args Ignored args.
22+
*/
23+
public static void main(String[] args) throws InterruptedException {
24+
TokenCredential tokenCredential = new DefaultAzureCredentialBuilder().build();
25+
26+
SchemaRegistryAsyncClient schemaRegistryAsyncClient = new SchemaRegistryClientBuilder()
27+
.fullyQualifiedNamespace("{schema-registry-endpoint")
28+
.credential(tokenCredential)
29+
.buildAsyncClient();
30+
31+
CountDownLatch countDownLatch = new CountDownLatch(1);
32+
33+
// Gets the properties of an existing schema.
34+
// `subscribe` is a non-blocking operation. It hooks up the callbacks and then moves onto the next line of code.
35+
schemaRegistryAsyncClient
36+
.getSchemaProperties("{group-name}", "{schema-name}", "{schema-string}", SchemaFormat.AVRO)
37+
.subscribe(schemaId -> {
38+
System.out.println("Successfully retrieved the schema id: " + schemaId);
39+
countDownLatch.countDown();
40+
});
41+
42+
// wait for the async task to complete
43+
countDownLatch.await();
44+
}
45+
}

sdk/schemaregistry/azure-data-schemaregistry/src/samples/java/com/azure/data/schemaregistry/GetSchemaSample.java

Lines changed: 10 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -4,38 +4,31 @@
44
package com.azure.data.schemaregistry;
55

66
import com.azure.core.credential.TokenCredential;
7+
import com.azure.data.schemaregistry.models.SchemaRegistrySchema;
78
import com.azure.identity.DefaultAzureCredentialBuilder;
89

9-
import java.util.concurrent.CountDownLatch;
10-
1110
/**
12-
* Sample to demonstrate retrieving a schema from Schema Registry.
11+
* Sample to demonstrate retrieving a schema from Schema Registry using the sync client.
1312
*/
1413
public class GetSchemaSample {
1514
/**
1615
* The main method to run this program.
16+
*
1717
* @param args Ignored args.
1818
*/
19-
public static void main(String[] args) throws InterruptedException {
19+
public static void main(String[] args) {
2020
TokenCredential tokenCredential = new DefaultAzureCredentialBuilder().build();
2121

22-
SchemaRegistryAsyncClient schemaRegistryAsyncClient = new SchemaRegistryClientBuilder()
22+
SchemaRegistryClient client = new SchemaRegistryClientBuilder()
2323
.fullyQualifiedNamespace("{schema-registry-endpoint")
2424
.credential(tokenCredential)
25-
.buildAsyncClient();
25+
.buildClient();
2626

27-
CountDownLatch countDownLatch = new CountDownLatch(1);
28-
// Register a schema
29-
schemaRegistryAsyncClient
30-
.getSchema("{schema-id}")
31-
.subscribe(schema -> {
32-
System.out.println("Successfully retrieved schema.");
33-
System.out.printf("Id: %s%nContents: %s%n", schema.getProperties().getId(), schema.getDefinition());
27+
// Get a schema using its id. The schema id is generated when it is registered via the client or Azure Portal.
28+
SchemaRegistrySchema schema = client.getSchema("{schema-id}");
3429

35-
countDownLatch.countDown();
36-
});
30+
System.out.println("Successfully retrieved schema.");
31+
System.out.printf("Id: %s%nContents: %s%n", schema.getProperties().getId(), schema.getDefinition());
3732

38-
// wait for the async task to complete
39-
countDownLatch.await();
4033
}
4134
}
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
// Copyright (c) Microsoft Corporation. All rights reserved.
2+
// Licensed under the MIT License.
3+
4+
package com.azure.data.schemaregistry;
5+
6+
import com.azure.core.credential.TokenCredential;
7+
import com.azure.identity.DefaultAzureCredentialBuilder;
8+
9+
import java.util.concurrent.CountDownLatch;
10+
11+
/**
12+
* Sample to demonstrate retrieving a schema from Schema Registry using the async client.
13+
*/
14+
public class GetSchemaSampleAsync {
15+
/**
16+
* The main method to run this program.
17+
* @param args Ignored args.
18+
*/
19+
public static void main(String[] args) throws InterruptedException {
20+
TokenCredential tokenCredential = new DefaultAzureCredentialBuilder().build();
21+
22+
SchemaRegistryAsyncClient schemaRegistryAsyncClient = new SchemaRegistryClientBuilder()
23+
.fullyQualifiedNamespace("{schema-registry-endpoint")
24+
.credential(tokenCredential)
25+
.buildAsyncClient();
26+
27+
CountDownLatch countDownLatch = new CountDownLatch(1);
28+
29+
// Get a schema using its id. The schema id is generated when it is registered via the client or Azure Portal.
30+
// `subscribe` is a non-blocking operation. It hooks up the callbacks and then moves onto the next line of code.
31+
schemaRegistryAsyncClient
32+
.getSchema("{schema-id}")
33+
.subscribe(schema -> {
34+
System.out.println("Successfully retrieved schema.");
35+
System.out.printf("Id: %s%nContents: %s%n", schema.getProperties().getId(), schema.getDefinition());
36+
37+
countDownLatch.countDown();
38+
});
39+
40+
// wait for the async task to complete
41+
countDownLatch.await();
42+
}
43+
}

0 commit comments

Comments
 (0)