You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: sdk/schemaregistry/azure-schemaregistry-avroencoder/CHANGELOG.md
+24-1Lines changed: 24 additions & 1 deletion
Original file line number
Diff line number
Diff line change
@@ -1,15 +1,38 @@
1
1
# Release History
2
2
3
-
## 1.0.0b4 (Unreleased)
3
+
## 1.0.0 (Unreleased)
4
+
5
+
**Note:** This is the first stable release of our efforts to create a user-friendly and Pythonic client library for Azure Schema Registry.
4
6
5
7
### Features Added
6
8
9
+
-`AvroEncoder` sync and async classes provide the functionality to encode and decode content which follows a schema with the RecordSchema format, as defined by the Apache Avro specification. The Apache Avro library is used as the implementation for encoding and decoding.
10
+
The encoder will automatically register and retrieve schemas from Azure Schema Registry Service. It provides the following methods:
11
+
- constructor: If `auto_register=True` keyword is passed in, will automatically register schemas passed in to the `encode` method. Otherwise, and by default, will require pre-registering of schemas passed to `encode`. Takes a `group_name` argument that is optional when decoding, but required for encoding.
12
+
-`encode`: Encodes dict content into bytes according to the given schema and registers schema if needed. Returns either a dict of encoded content and corresponding content type or a `MessageType` subtype object, depending on arguments provided.
13
+
-`decode`: Decodes bytes content into dict content by automatically retrieving schema from the service.
14
+
-`MessageContent` TypedDict has been introduced with the following required keys:
15
+
-`content`: The bytes content.
16
+
-`content_type`: The string content type, which holds the schema ID and the record format indicator.
17
+
-`MessageType` has been introduced with the following methods:
18
+
-`from_message_content`: Class method that creates an object with given bytes content and string content type.
19
+
-`__message_content__`: Returns a `MessageContent` object with content and content type values set to their respective properties on the object.
20
+
- Schemas and Schema IDs are cached locally, so that multiple calls with the same schema/schema ID will not trigger multiple service calls.
21
+
- The number of hits, misses, and total entries for the schema/schema ID caches will be logged at an info level when a new entry is added.
22
+
-`InvalidContentError` has been introduced for errors related to invalid content and content types, where `__cause__` will contain the underlying exception raised by the Avro library.
23
+
-`InvalidSchemaError` has been introduced for errors related to invalid schemas, where `__cause__` will contain the underlying exception raised by the Apache Avro library.
24
+
- The `encode` and `decode` methods on `AvroEncoder` support the following message models:
25
+
-`azure.eventhub.EventData` in `azure-eventhub>=5.9.0`
26
+
7
27
### Breaking Changes
8
28
9
29
### Bugs Fixed
10
30
11
31
### Other Changes
12
32
33
+
- This package is meant to replace the azure-schemaregistry-avroserializer package, which will no longer be supported.
34
+
-`group_name` is now an optional parameter in the sync and async `AvroEncoder` constructors.
@@ -70,11 +71,11 @@ content type with schema ID. Uses [SchemaRegistryClient][schemaregistry_client]
70
71
71
72
Support has been added to certain Azure Messaging SDK model classes for interoperability with the `AvroEncoder`. These models are subtypes of the `MessageType` protocol defined under the `azure.schemaregistry.encoder.avroencoder` namespace. Currently, the supported model classes are:
72
73
73
-
-`azure.eventhub.EventData` for `azure-eventhub==5.9.0b3`
74
+
-`azure.eventhub.EventData` for `azure-eventhub>=5.9.0`
74
75
75
76
### Message format
76
77
77
-
If a message type that follows the MessageType protocol is provided to the encoder, it will encode the corresponding content and content type properties as follows:
78
+
If a message type that follows the MessageType protocol is provided to the encoder for encoding, it will set the corresponding content and content type properties, where:
78
79
79
80
-`content`: Avro payload (in general, format-specific payload)
80
81
- Avro Binary Encoding
@@ -86,6 +87,10 @@ If a message type that follows the MessageType protocol is provided to the encod
86
87
-`avro/binary` is the format indicator
87
88
-`<schema ID>` is the hexadecimal representation of GUID, same format and byte order as the string from the Schema Registry service.
88
89
90
+
If `EventData` is passed in as the message type, the following properties will be set on the `EventData` object:
91
+
- The `body` property will be set to the content value.
92
+
- The `content_type` property will be set to the content type value.
93
+
89
94
If message type is not provided, and by default, the encoder will create the following dict:
@@ -100,8 +105,8 @@ The following sections provide several code snippets covering some of the most c
100
105
101
106
### Encoding
102
107
103
-
Use `AvroEncoder.encode` method to encode dict content with the given Avro schema.
104
-
The method will use a schema previously registered to the Schema Registry service and keep the schema cached for future encoding usage. It is also possible to avoid pre-registering the schema to the service and automatically register with the `encode` method by instantiating the `AvroEncoder` with the keyword argument `auto_register=True`.
108
+
Use the `AvroEncoder.encode` method to encode content with the given Avro schema.
109
+
The method will use a schema previously registered to the Schema Registry service and keep the schema cached for future encoding usage. In order to avoid pre-registering the schema to the service and automatically register it with the `encode` method, the keyword argument `auto_register=True` should be passed to the `AvroEncoder` constructor.
105
110
106
111
```python
107
112
import os
@@ -112,7 +117,7 @@ from azure.eventhub import EventData
@@ -254,7 +261,7 @@ with eventhub_consumer, avro_encoder:
254
261
255
262
### General
256
263
257
-
Azure Schema Registry Avro Encoder raises exceptions defined in [Azure Core][azure_core].
264
+
Azure Schema Registry Avro Encoder raises exceptions defined in [Azure Core][azure_core] if errors are encountered when communicating with the Schema Registry service. Errors related to invalid content/content types and invalid schemas will be raised as `azure.schemaregistry.encoder.avroencoder.InvalidContentError` and `azure.schemaregistry.encoder.avroencoder.InvalidSchemaError`, respectively, where `__cause__` will contain the underlying exception raised by the Apache Avro library.
258
265
259
266
### Logging
260
267
This library uses the standard
@@ -266,6 +273,7 @@ Detailed DEBUG level logging, including request/response bodies and unredacted
266
273
headers, can be enabled on a client with the `logging_enable` argument:
267
274
```python
268
275
import sys
276
+
import os
269
277
import logging
270
278
from azure.schemaregistry import SchemaRegistryClient
271
279
from azure.schemaregistry.encoder.avroencoder import AvroEncoder
Copy file name to clipboardExpand all lines: sdk/schemaregistry/azure-schemaregistry-avroencoder/azure/schemaregistry/encoder/avroencoder/_message_protocol.py
+8-2Lines changed: 8 additions & 2 deletions
Original file line number
Diff line number
Diff line change
@@ -25,8 +25,8 @@ def from_message_content(
25
25
cls, content: bytes, content_type: str, **kwargs: Any
26
26
) ->"MessageType":
27
27
"""
28
-
Creates an object that is a subtype of MessageType given content type and
29
-
a content value to be set as body.
28
+
Creates an object that is a subtype of MessageType, given content type and
29
+
a content value to be set on the object.
30
30
31
31
:param bytes content: The content value to be set as the body of the message.
32
32
:param str content_type: The content type to be set on the message.
@@ -35,4 +35,10 @@ def from_message_content(
35
35
...
36
36
37
37
def__message_content__(self) ->MessageContent:
38
+
"""
39
+
A MessageContent object, with `content` and `content_type` set to
40
+
the values of their respective properties on the MessageType object.
Copy file name to clipboardExpand all lines: sdk/schemaregistry/azure-schemaregistry-avroencoder/azure/schemaregistry/encoder/avroencoder/_schema_registry_avro_encoder.py
+17-17Lines changed: 17 additions & 17 deletions
Original file line number
Diff line number
Diff line change
@@ -33,41 +33,39 @@
33
33
Optional,
34
34
Type,
35
35
overload,
36
-
TypeVar,
37
36
Union,
38
37
)
39
38
from ._utilsimport ( # pylint: disable=import-error
40
39
validate_schema,
41
40
create_message_content,
42
41
validate_message,
43
42
decode_content,
43
+
MessageType
44
44
)
45
45
46
46
from ._apache_avro_encoderimport ( # pylint: disable=import-error
47
47
ApacheAvroObjectEncoderasAvroObjectEncoder,
48
48
)
49
49
from ._message_protocolimport ( # pylint: disable=import-error
0 commit comments