Skip to content

Commit

Permalink
Renames MessageWithMetadata to MessageContent (#28096)
Browse files Browse the repository at this point in the history
* Updating CHANGELOG.

* Rename class to MessageContent.

* Move MessageContent to com.azure.

* Remove unused package-info.java.

* Remove unused module-info.java

* Update CHANGELOG.

* Update to use unreleased_azure.core dependency and rename MessageContent.
  • Loading branch information
conniey authored Apr 14, 2022
1 parent 6c8a533 commit 1ea2d78
Show file tree
Hide file tree
Showing 19 changed files with 74 additions and 83 deletions.
1 change: 1 addition & 0 deletions eng/versioning/version_client.txt
Original file line number Diff line number Diff line change
Expand Up @@ -345,6 +345,7 @@ com.azure.tools:azure-sdk-build-tool;1.0.0-beta.1;1.0.0-beta.2
# In the pom, the version update tag after the version should name the unreleased package and the dependency version:
# <!-- {x-version-update;unreleased_com.azure:azure-core;dependency} -->
unreleased_com.azure:azure-aot-graalvm-perf;1.0.0-beta.1
unreleased_com.azure:azure-core;1.28.0-beta.1

# Released Beta dependencies: Copy the entry from above, prepend "beta_", remove the current
# version and set the version to the released beta. Released beta dependencies are only valid
Expand Down
2 changes: 2 additions & 0 deletions sdk/core/azure-core-experimental/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@

### Breaking Changes

- Move `MessageWithMetadata` to `com.azure` package as `com.azure.core.models.MessageContent`.

### Bugs Fixed

### Other Changes
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,5 @@
exports com.azure.core.experimental.http;
exports com.azure.core.experimental.http.policy;

exports com.azure.core.experimental.models;

uses com.azure.core.experimental.serializer.AvroSerializerProvider;
}
2 changes: 2 additions & 0 deletions sdk/core/azure-core/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

### Features Added

- Add `com.azure.core.models.MessageContent`.

### Breaking Changes

### Bugs Fixed
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

package com.azure.core.experimental.models;
package com.azure.core.models;

import com.azure.core.annotation.Fluent;
import com.azure.core.util.BinaryData;
Expand All @@ -10,7 +10,7 @@
* An abstraction for a message containing a content type along with its data.
*/
@Fluent
public class MessageWithMetadata {
public class MessageContent {
private BinaryData binaryData;
private String contentType;

Expand All @@ -28,9 +28,9 @@ public BinaryData getBodyAsBinaryData() {
*
* @param binaryData The message body.
*
* @return The updated {@link MessageWithMetadata} object.
* @return The updated {@link MessageContent} object.
*/
public MessageWithMetadata setBodyAsBinaryData(BinaryData binaryData) {
public MessageContent setBodyAsBinaryData(BinaryData binaryData) {
this.binaryData = binaryData;
return this;
}
Expand All @@ -49,9 +49,9 @@ public String getContentType() {
*
* @param contentType The content type.
*
* @return The updated {@link MessageWithMetadata} object.
* @return The updated {@link MessageContent} object.
*/
public MessageWithMetadata setContentType(String contentType) {
public MessageContent setContentType(String contentType) {
this.contentType = contentType;
return this;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
package com.azure.core.experimental.models;
package com.azure.core.models;

import com.azure.core.util.BinaryData;
import org.junit.jupiter.api.Test;
Expand All @@ -9,16 +9,16 @@
import static org.junit.jupiter.api.Assertions.assertNull;

/**
* Tests for {@link MessageWithMetadata}
* Tests for {@link MessageContent}
*/
public class MessageWithMetadataTest {
public class MessageContentTest {
/**
* Verify default parameters.
*/
@Test
public void initialize() {
// Act
final MessageWithMetadata message = new MessageWithMetadata();
final MessageContent message = new MessageContent();

// Assert
assertNull(message.getBodyAsBinaryData(), "'body' should initially be null.");
Expand All @@ -33,10 +33,10 @@ public void settingProperties() {
// Arrange
final BinaryData binaryData = BinaryData.fromString("foo.bar.baz");
final String contentType = "some-content";
final MessageWithMetadata message = new MessageWithMetadata();
final MessageContent message = new MessageContent();

// Act
final MessageWithMetadata actual = message.setContentType(contentType)
final MessageContent actual = message.setContentType(contentType)
.setBodyAsBinaryData(binaryData);

// Assert
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@

### Features Added

- Changed `SchemaRegistryApacheAvroEncoder` to deserialize `MessageWithMetadata` rather than tied to a binary format
- Changed `SchemaRegistryApacheAvroEncoder` to deserialize `MessageContent` rather than tied to a binary format
with preamble. Backwards compatibility with preamble format supported for this release. See issue #26449.

### Breaking Changes
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,8 +101,8 @@ playingCard.setPlayingCardSuit(PlayingCardSuit.SPADES);
playingCard.setIsFaceCard(false);
playingCard.setCardValue(5);

MessageWithMetadata message = serializer.serializeMessageData(playingCard,
TypeReference.createInstance(MessageWithMetadata.class));
MessageContent message = serializer.serializeMessageData(playingCard,
TypeReference.createInstance(MessageContent.class));
```

The avro type `PlayingCard` is available in samples package
Expand All @@ -113,7 +113,7 @@ Deserialize a Schema Registry-compatible avro payload into a strongly-type objec

```java readme-sample-deserializeSample
SchemaRegistryApacheAvroSerializer serializer = createAvroSchemaRegistrySerializer();
MessageWithMetadata message = getSchemaRegistryAvroMessage();
MessageContent message = getSchemaRegistryAvroMessage();
PlayingCard playingCard = serializer.deserializeMessageData(message, TypeReference.createInstance(PlayingCard.class));
```

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,7 @@
<dependency>
<groupId>com.azure</groupId>
<artifactId>azure-core</artifactId>
<version>1.27.0</version> <!-- {x-version-update;com.azure:azure-core;dependency} -->
</dependency>
<dependency>
<groupId>com.azure</groupId>
<artifactId>azure-core-experimental</artifactId>
<version>1.0.0-beta.26</version> <!-- {x-version-update;com.azure:azure-core-experimental;dependency} -->
<version>1.28.0-beta.1</version> <!-- {x-version-update;unreleased_com.azure:azure-core;dependency} -->
</dependency>
<dependency>
<groupId>com.azure</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

import com.azure.core.exception.HttpResponseException;
import com.azure.core.exception.ResourceNotFoundException;
import com.azure.core.experimental.models.MessageWithMetadata;
import com.azure.core.models.MessageContent;
import com.azure.core.util.BinaryData;
import com.azure.core.util.CoreUtils;
import com.azure.core.util.logging.ClientLogger;
Expand Down Expand Up @@ -50,9 +50,9 @@
* <!-- end com.azure.data.schemaregistry.apacheavro.schemaregistryapacheavroserializer.instantiation -->
*
* <p><strong>Serialize an object</strong></p>
* Serializes an Avro generated object into {@link MessageWithMetadata}.
* Serializes an Avro generated object into {@link MessageContent}.
* {@link #serializeMessageData(Object, TypeReference)} assumes that there is a no argument constructor used to
* instantiate the {@link MessageWithMetadata} type. If there is a different way to instantiate the concrete type, use
* instantiate the {@link MessageContent} type. If there is a different way to instantiate the concrete type, use
* the overload which takes a message factory function, {@link #serializeMessageData(Object, TypeReference, Function)}.
*
* <!-- src_embed com.azure.data.schemaregistry.apacheavro.schemaregistryapacheavroserializer.serialize -->
Expand All @@ -73,16 +73,16 @@
* .setFavouriteColour&#40;&quot;Turquoise&quot;&#41;
* .build&#40;&#41;;
*
* MessageWithMetadata message = serializer.serializeMessageData&#40;person,
* TypeReference.createInstance&#40;MessageWithMetadata.class&#41;&#41;;
* MessageContent message = serializer.serializeMessageData&#40;person,
* TypeReference.createInstance&#40;MessageContent.class&#41;&#41;;
* </pre>
* <!-- end com.azure.data.schemaregistry.apacheavro.schemaregistryapacheavroserializer.serialize -->
*
* <p><strong>Deserialize an object</strong></p>
* <!-- src_embed com.azure.data.schemaregistry.apacheavro.schemaregistryapacheavroserializer.deserialize -->
* <pre>
* &#47;&#47; Message to deserialize. Assume that the body contains data which has been serialized using an Avro encoder.
* MessageWithMetadata message = new MessageWithMetadata&#40;&#41;
* MessageContent message = new MessageContent&#40;&#41;
* .setBodyAsBinaryData&#40;BinaryData.fromBytes&#40;new byte[0]&#41;&#41;
* .setContentType&#40;&quot;avro&#47;binary+&#123;schema-id&#125;&quot;&#41;;
*
Expand All @@ -92,7 +92,7 @@
* <!-- end com.azure.data.schemaregistry.apacheavro.schemaregistryapacheavroserializer.deserialize -->
*
* <p><strong>Serialize an object using a message factory</strong></p>
* Serializes an Avro generated object into {@link MessageWithMetadata}. It uses the {@link Function messageFactory} to
* Serializes an Avro generated object into {@link MessageContent}. It uses the {@link Function messageFactory} to
* instantiate and populate the type.
*
* <!-- src_embed com.azure.data.schemaregistry.apacheavro.schemaregistryapacheavroserializer.serializeMessageFactory -->
Expand Down Expand Up @@ -154,7 +154,7 @@ public final class SchemaRegistryApacheAvroSerializer {
*
* @param object Object to serialize.
* @param typeReference Type of message to create.
* @param <T> Concrete type of {@link MessageWithMetadata}.
* @param <T> Concrete type of {@link MessageContent}.
*
* @return The message encoded or {@code null} if the message could not be serialized.
*
Expand All @@ -168,7 +168,7 @@ public final class SchemaRegistryApacheAvroSerializer {
* SchemaRegistryApacheAvroSerializerBuilder#autoRegisterSchema(boolean)} is false.
* @throws HttpResponseException if an error occurred while trying to fetch the schema from the service.
*/
public <T extends MessageWithMetadata> T serializeMessageData(Object object, TypeReference<T> typeReference) {
public <T extends MessageContent> T serializeMessageData(Object object, TypeReference<T> typeReference) {
return serializeMessageDataAsync(object, typeReference).block();
}

Expand All @@ -178,7 +178,7 @@ public <T extends MessageWithMetadata> T serializeMessageData(Object object, Typ
* @param object Object to serialize.
* @param typeReference Type of message to create.
* @param messageFactory Factory to create an instance given the serialized Avro.
* @param <T> Concrete type of {@link MessageWithMetadata}.
* @param <T> Concrete type of {@link MessageContent}.
*
* @return The message encoded or {@code null} if the message could not be serialized.
*
Expand All @@ -191,7 +191,7 @@ public <T extends MessageWithMetadata> T serializeMessageData(Object object, Typ
* SchemaRegistryApacheAvroSerializerBuilder#autoRegisterSchema(boolean)} is false.
* @throws HttpResponseException if an error occurred while trying to fetch the schema from the service.
*/
public <T extends MessageWithMetadata> T serializeMessageData(Object object, TypeReference<T> typeReference,
public <T extends MessageContent> T serializeMessageData(Object object, TypeReference<T> typeReference,
Function<BinaryData, T> messageFactory) {
return serializeMessageDataAsync(object, typeReference, messageFactory).block();
}
Expand All @@ -201,7 +201,7 @@ public <T extends MessageWithMetadata> T serializeMessageData(Object object, Typ
*
* @param object Object to serialize.
* @param typeReference Type of message to create.
* @param <T> Concrete type of {@link MessageWithMetadata}.
* @param <T> Concrete type of {@link MessageContent}.
*
* @return A Mono that completes with the serialized message.
*
Expand All @@ -214,7 +214,7 @@ public <T extends MessageWithMetadata> T serializeMessageData(Object object, Typ
* SchemaRegistryApacheAvroSerializerBuilder#autoRegisterSchema(boolean)} is false.
* @throws HttpResponseException if an error occurred while trying to fetch the schema from the service.
*/
public <T extends MessageWithMetadata> Mono<T> serializeMessageDataAsync(Object object,
public <T extends MessageContent> Mono<T> serializeMessageDataAsync(Object object,
TypeReference<T> typeReference) {

return serializeMessageDataAsync(object, typeReference, null);
Expand All @@ -227,7 +227,7 @@ public <T extends MessageWithMetadata> Mono<T> serializeMessageDataAsync(Object
* @param typeReference Type of message to create.
* @param messageFactory Factory to create an instance given the serialized Avro. If null is passed in, then the
* no argument constructor will be used.
* @param <T> Concrete type of {@link MessageWithMetadata}.
* @param <T> Concrete type of {@link MessageContent}.
*
* @return A Mono that completes with the serialized message.
*
Expand All @@ -240,7 +240,7 @@ public <T extends MessageWithMetadata> Mono<T> serializeMessageDataAsync(Object
* SchemaRegistryApacheAvroSerializerBuilder#autoRegisterSchema(boolean)} is false.
* @throws HttpResponseException if an error occurred while trying to fetch the schema from the service.
*/
public <T extends MessageWithMetadata> Mono<T> serializeMessageDataAsync(Object object,
public <T extends MessageContent> Mono<T> serializeMessageDataAsync(Object object,
TypeReference<T> typeReference, Function<BinaryData, T> messageFactory) {

if (object == null) {
Expand Down Expand Up @@ -304,7 +304,7 @@ public <T extends MessageWithMetadata> Mono<T> serializeMessageDataAsync(Object
*
* @param message Object to deserialize.
* @param typeReference Message type to deserialize to.
* @param <T> Concrete type of {@link MessageWithMetadata}.
* @param <T> Concrete type of {@link MessageContent}.
*
* @return The message deserialized.
*
Expand All @@ -318,7 +318,7 @@ public <T extends MessageWithMetadata> Mono<T> serializeMessageDataAsync(Object
* SchemaRegistryApacheAvroSerializerBuilder#autoRegisterSchema(boolean)} is false.
* @throws HttpResponseException if an error occurred while trying to fetch the schema from the service.
*/
public <T> T deserializeMessageData(MessageWithMetadata message, TypeReference<T> typeReference) {
public <T> T deserializeMessageData(MessageContent message, TypeReference<T> typeReference) {
return deserializeMessageDataAsync(message, typeReference).block();
}

Expand All @@ -327,7 +327,7 @@ public <T> T deserializeMessageData(MessageWithMetadata message, TypeReference<T
*
* @param message Object to deserialize.
* @param typeReference Message to deserialize to.
* @param <T> Concrete type of {@link MessageWithMetadata}.
* @param <T> Concrete type of {@link MessageContent}.
*
* @return A Mono that completes when the message encoded. If {@code message.getBodyAsBinaryData()} is null or
* empty, then an empty Mono is returned.
Expand All @@ -342,7 +342,7 @@ public <T> T deserializeMessageData(MessageWithMetadata message, TypeReference<T
* SchemaRegistryApacheAvroSerializerBuilder#autoRegisterSchema(boolean)} is false.
* @throws HttpResponseException if an error occurred while trying to fetch the schema from the service.
*/
public <T> Mono<T> deserializeMessageDataAsync(MessageWithMetadata message, TypeReference<T> typeReference) {
public <T> Mono<T> deserializeMessageDataAsync(MessageContent message, TypeReference<T> typeReference) {
if (message == null) {
return monoError(logger, new NullPointerException("'message' cannot be null."));
} else if (typeReference == null) {
Expand Down Expand Up @@ -433,7 +433,7 @@ public <T> Mono<T> deserializeMessageDataAsync(MessageWithMetadata message, Type
* @throws RuntimeException if an instance of {@code T} could not be instantiated.
*/
@SuppressWarnings("unchecked")
private static <T extends MessageWithMetadata> T createNoArgumentInstance(TypeReference<T> typeReference) {
private static <T extends MessageContent> T createNoArgumentInstance(TypeReference<T> typeReference) {

final Optional<Constructor<?>> constructor =
Arrays.stream(typeReference.getJavaClass().getDeclaredConstructors())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
// Licensed under the MIT License.

module com.azure.data.schemaregistry.apacheavro {
requires transitive com.azure.core;
requires transitive com.azure.data.schemaregistry;
requires transitive com.azure.core.experimental;

requires org.apache.avro;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@
// Licensed under the MIT License.
package com.azure.data.schemaregistry.apacheavro;

import com.azure.core.experimental.models.MessageWithMetadata;
import com.azure.core.models.MessageContent;

import java.time.OffsetDateTime;

/**
* Sample type used in {@link SchemaRegistryApacheAvroSerializerJavaDocCodeSamples#serializeMessageFactory()}.
*/
public class ComplexMessage extends MessageWithMetadata {
public class ComplexMessage extends MessageContent {
private final String id;
private final OffsetDateTime creationTime;

Expand Down
Loading

0 comments on commit 1ea2d78

Please sign in to comment.