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
The design for the GA Avro serializer is spearheaded by @JoshLove-msft and it is still being refined. The main idea is for the serializer to create the message to be sent, which will include the payload and a content-type header that contains the schema format and ID.
Fixes#20061
## Overview
Revamps the schema registry encoder to work on messages instead of buffers based on the recommendation of the Azure messaging architect.
This changes the APIs as follows:
```ts
const buffer: NodeJS.Buffer = await serializer.serialize(value, schema);
```
becomes
```ts
const message: MessageWithMetadata = await encoder.encodeMessageData(value, schema);
```
where `MessageWithMetadata` has a `body` field as well as a `contentType` field. The latter's format is `avro/binary+<Schema ID>`
For derserializing, the change is as follows:
```ts
const deserializedValue = await serializer.deserialize(buffer);
```
becomes:
```ts
const decodedObject = await encoder.decodeMessageData(message);
```
## Improvement upon #15959
This design introduces a new `messageAdapter` option in the encoder constructor to support processing of any message type (e.g. [cloud event](https://github.com/cloudevents/spec/blob/v1.0.1/spec.md)):
```ts
const encoder = new SchemaRegistryAvroEncoder(schemaRegistryClient, {
groupName,
messageAdapter: adapter
});
```
where `adapter` is a message adapter that follows the following contract:
```ts
interface MessageAdapter<MessageT> {
produceMessage: (messageWithMetadata: MessageWithMetadata) => MessageT;
consumeMessage: (message: MessageT) => MessageWithMetadata;
}
interface MessageWithMetadata {
body: Uint8Array;
contentType: string;
}
```
For convenience, the PR adds a couple of convenience adapter factories for Event Hubs's `EventData` and Event Grid's `SendCloudEventInput<Uint8Array>`. For example, the `createCloudEventAdapter` factory can be called to construct an adapter for the latter as follows:
```ts
const adapter = createCloudEventAdapter({
type: "azure.sdk.eventgrid.samples.cloudevent",
source: "/azure/sdk/schemaregistry/samples/withEventGrid",
}),
```
Note that these adapter factories are exported by their respective messaging package without explicitly implementing the contract and the PR adds new encoder tests that check whether the produced adapters follow the contract. This organization could change in the future if we create a new core place for the contract to be imported from.
See the newly added samples for how to send such messages with Event Hubs and Event Grid.
Schema Registry commitment tracking: #15959
Tracking issue: #18608
First iteration design: #18365
The design for the GA Avro serializer is spearheaded by @JoshLove-msft and it is still being refined. The main idea is for the serializer to create the message to be sent, which will include the payload and a content-type header that contains the schema format and ID.
See [schema-registry] Implement avro-based serializer #10890 (comment)
The text was updated successfully, but these errors were encountered: