Skip to content

Commit

Permalink
Change IMessageWithContentType to MessageWithMetadata (#25569)
Browse files Browse the repository at this point in the history
* save

* Change IMessageWithContentType to MessageWithMetadata

* Add IsReadOnly

* remove IMessageWithContentType

* delete commented test

* Remove EventHubs Experimental API file
  • Loading branch information
JoshLove-msft authored Dec 1, 2021
1 parent db1a076 commit b8f395e
Show file tree
Hide file tree
Showing 37 changed files with 1,222 additions and 375 deletions.
2 changes: 1 addition & 1 deletion eng/Packages.Data.props
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@
<PackageReference Update="Azure.Core" Version="1.21.0" />
<PackageReference Update="Azure.Core.Amqp" Version="1.2.0" />
<PackageReference Update="Azure.Core.Experimental" Version="0.1.0-preview.18" />
<PackageReference Update="Azure.Data.SchemaRegistry" Version="1.0.0" />
<PackageReference Update="Azure.Data.SchemaRegistry" Version="1.0.0" />
<PackageReference Update="Azure.Messaging.EventHubs" Version="5.6.2" />
<PackageReference Update="Azure.Messaging.EventGrid" Version="4.7.0" />
<PackageReference Update="Azure.Messaging.ServiceBus" Version="7.5.0" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,3 +86,13 @@ public void Set(string propertyName, string? value) { }
public System.Threading.Tasks.Task<long> WriteToAsync(System.IO.Stream stream, System.Threading.CancellationToken cancellationToken) { throw null; }
}
}
namespace Azure.Messaging
{
public abstract partial class MessageWithMetadata
{
protected MessageWithMetadata() { }
public abstract string ContentType { get; set; }
public abstract System.BinaryData Data { get; set; }
public abstract bool IsReadOnly { get; }
}
}
28 changes: 28 additions & 0 deletions sdk/core/Azure.Core.Experimental/src/MessageWithMetadata.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

using System;

namespace Azure.Messaging
{
/// <summary>
/// An abstraction for a message containing a content type along with its data.
/// </summary>
public abstract class MessageWithMetadata
{
/// <summary>
/// Gets or sets the message data.
/// </summary>
public abstract BinaryData Data { get; set; }

/// <summary>
/// Gets or sets the message content type.
/// </summary>
public abstract string ContentType { get; set; }

/// <summary>
/// Gets whether the message is read only or not.
/// </summary>
public abstract bool IsReadOnly { get; }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "External", "External", "{79
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Azure.Messaging.EventHubs", "..\Azure.Messaging.EventHubs\src\Azure.Messaging.EventHubs.csproj", "{87A3ED70-190D-4E6B-A568-40DF5B9F3939}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Azure.Core.Experimental", "..\..\core\Azure.Core.Experimental\src\Azure.Core.Experimental.csproj", "{0BFCCE8E-85FD-4DF7-8E5D-A6CE9ACDB175}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand All @@ -35,13 +37,18 @@ Global
{87A3ED70-190D-4E6B-A568-40DF5B9F3939}.Debug|Any CPU.Build.0 = Debug|Any CPU
{87A3ED70-190D-4E6B-A568-40DF5B9F3939}.Release|Any CPU.ActiveCfg = Release|Any CPU
{87A3ED70-190D-4E6B-A568-40DF5B9F3939}.Release|Any CPU.Build.0 = Release|Any CPU
{0BFCCE8E-85FD-4DF7-8E5D-A6CE9ACDB175}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{0BFCCE8E-85FD-4DF7-8E5D-A6CE9ACDB175}.Debug|Any CPU.Build.0 = Debug|Any CPU
{0BFCCE8E-85FD-4DF7-8E5D-A6CE9ACDB175}.Release|Any CPU.ActiveCfg = Release|Any CPU
{0BFCCE8E-85FD-4DF7-8E5D-A6CE9ACDB175}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(NestedProjects) = preSolution
{7DFF0E65-DC9A-410D-9A11-AD6A06860FE1} = {797FF941-76FD-45FD-AC17-A73DFE2BA621}
{87A3ED70-190D-4E6B-A568-40DF5B9F3939} = {797FF941-76FD-45FD-AC17-A73DFE2BA621}
{0BFCCE8E-85FD-4DF7-8E5D-A6CE9ACDB175} = {797FF941-76FD-45FD-AC17-A73DFE2BA621}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {44BD3BD5-61DF-464D-8627-E00B0BC4B3A3}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,11 @@
</ItemGroup>

<ItemGroup>
<!--
TEMP: Move Core to a project reference until the
MessageWithMetadata are shipped in Azure.Core.
<PackageReference Include="Azure.Core" />
-->

<!--
TEMP: Move Event Hubs to a project reference until the
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "External", "External", "{10
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Azure.Messaging.EventHubs", "..\Azure.Messaging.EventHubs\src\Azure.Messaging.EventHubs.csproj", "{870D6ACA-B778-40AA-93B5-43CF1D25235E}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Azure.Core.Experimental", "..\..\core\Azure.Core.Experimental\src\Azure.Core.Experimental.csproj", "{07A39A33-E454-4404-85DC-42B603AEBD6D}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Azure.Core", "..\..\core\Azure.Core\src\Azure.Core.csproj", "{E3B14DB9-48E1-4B7D-A384-3247163A1421}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -59,6 +63,30 @@ Global
{870D6ACA-B778-40AA-93B5-43CF1D25235E}.Release|x64.Build.0 = Release|Any CPU
{870D6ACA-B778-40AA-93B5-43CF1D25235E}.Release|x86.ActiveCfg = Release|Any CPU
{870D6ACA-B778-40AA-93B5-43CF1D25235E}.Release|x86.Build.0 = Release|Any CPU
{07A39A33-E454-4404-85DC-42B603AEBD6D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{07A39A33-E454-4404-85DC-42B603AEBD6D}.Debug|Any CPU.Build.0 = Debug|Any CPU
{07A39A33-E454-4404-85DC-42B603AEBD6D}.Debug|x64.ActiveCfg = Debug|Any CPU
{07A39A33-E454-4404-85DC-42B603AEBD6D}.Debug|x64.Build.0 = Debug|Any CPU
{07A39A33-E454-4404-85DC-42B603AEBD6D}.Debug|x86.ActiveCfg = Debug|Any CPU
{07A39A33-E454-4404-85DC-42B603AEBD6D}.Debug|x86.Build.0 = Debug|Any CPU
{07A39A33-E454-4404-85DC-42B603AEBD6D}.Release|Any CPU.ActiveCfg = Release|Any CPU
{07A39A33-E454-4404-85DC-42B603AEBD6D}.Release|Any CPU.Build.0 = Release|Any CPU
{07A39A33-E454-4404-85DC-42B603AEBD6D}.Release|x64.ActiveCfg = Release|Any CPU
{07A39A33-E454-4404-85DC-42B603AEBD6D}.Release|x64.Build.0 = Release|Any CPU
{07A39A33-E454-4404-85DC-42B603AEBD6D}.Release|x86.ActiveCfg = Release|Any CPU
{07A39A33-E454-4404-85DC-42B603AEBD6D}.Release|x86.Build.0 = Release|Any CPU
{E3B14DB9-48E1-4B7D-A384-3247163A1421}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{E3B14DB9-48E1-4B7D-A384-3247163A1421}.Debug|Any CPU.Build.0 = Debug|Any CPU
{E3B14DB9-48E1-4B7D-A384-3247163A1421}.Debug|x64.ActiveCfg = Debug|Any CPU
{E3B14DB9-48E1-4B7D-A384-3247163A1421}.Debug|x64.Build.0 = Debug|Any CPU
{E3B14DB9-48E1-4B7D-A384-3247163A1421}.Debug|x86.ActiveCfg = Debug|Any CPU
{E3B14DB9-48E1-4B7D-A384-3247163A1421}.Debug|x86.Build.0 = Debug|Any CPU
{E3B14DB9-48E1-4B7D-A384-3247163A1421}.Release|Any CPU.ActiveCfg = Release|Any CPU
{E3B14DB9-48E1-4B7D-A384-3247163A1421}.Release|Any CPU.Build.0 = Release|Any CPU
{E3B14DB9-48E1-4B7D-A384-3247163A1421}.Release|x64.ActiveCfg = Release|Any CPU
{E3B14DB9-48E1-4B7D-A384-3247163A1421}.Release|x64.Build.0 = Release|Any CPU
{E3B14DB9-48E1-4B7D-A384-3247163A1421}.Release|x86.ActiveCfg = Release|Any CPU
{E3B14DB9-48E1-4B7D-A384-3247163A1421}.Release|x86.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="Azure.Core" />
<PackageReference Include="Azure.Storage.Blobs" />
<PackageReference Include="Microsoft.NET.Test.Sdk" />
<PackageReference Include="Microsoft.Azure.Management.EventHub" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Azure.Core.TestFramework",
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "External", "External", "{2DB233D3-E757-423C-8F8D-742B0AFF4713}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Azure.Core.Experimental", "..\..\core\Azure.Core.Experimental\src\Azure.Core.Experimental.csproj", "{FB10A6B3-88DD-4296-9241-53ECDF942842}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -57,6 +59,18 @@ Global
{2CFDB3D6-5CFB-428C-9C89-29DD169B5433}.Release|x64.Build.0 = Release|Any CPU
{2CFDB3D6-5CFB-428C-9C89-29DD169B5433}.Release|x86.ActiveCfg = Release|Any CPU
{2CFDB3D6-5CFB-428C-9C89-29DD169B5433}.Release|x86.Build.0 = Release|Any CPU
{FB10A6B3-88DD-4296-9241-53ECDF942842}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{FB10A6B3-88DD-4296-9241-53ECDF942842}.Debug|Any CPU.Build.0 = Debug|Any CPU
{FB10A6B3-88DD-4296-9241-53ECDF942842}.Debug|x64.ActiveCfg = Debug|Any CPU
{FB10A6B3-88DD-4296-9241-53ECDF942842}.Debug|x64.Build.0 = Debug|Any CPU
{FB10A6B3-88DD-4296-9241-53ECDF942842}.Debug|x86.ActiveCfg = Debug|Any CPU
{FB10A6B3-88DD-4296-9241-53ECDF942842}.Debug|x86.Build.0 = Debug|Any CPU
{FB10A6B3-88DD-4296-9241-53ECDF942842}.Release|Any CPU.ActiveCfg = Release|Any CPU
{FB10A6B3-88DD-4296-9241-53ECDF942842}.Release|Any CPU.Build.0 = Release|Any CPU
{FB10A6B3-88DD-4296-9241-53ECDF942842}.Release|x64.ActiveCfg = Release|Any CPU
{FB10A6B3-88DD-4296-9241-53ECDF942842}.Release|x64.Build.0 = Release|Any CPU
{FB10A6B3-88DD-4296-9241-53ECDF942842}.Release|x86.ActiveCfg = Release|Any CPU
{FB10A6B3-88DD-4296-9241-53ECDF942842}.Release|x86.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
namespace Azure.Messaging.EventHubs
{
public partial class EventData
public partial class EventData : Azure.Messaging.MessageWithMetadata
{
public EventData() { }
public EventData(System.BinaryData eventBody) { }
Expand All @@ -14,10 +14,14 @@ public EventData(string eventBody) { }
public System.ReadOnlyMemory<byte> Body { get { throw null; } }
[System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Never)]
public System.IO.Stream BodyAsStream { get { throw null; } }
public string ContentType { get { throw null; } set { } }
public override string ContentType { get { throw null; } set { } }
public string CorrelationId { get { throw null; } set { } }
[System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Never)]
public override System.BinaryData Data { get { throw null; } set { } }
public System.DateTimeOffset EnqueuedTime { get { throw null; } }
public System.BinaryData EventBody { get { throw null; } set { } }
[System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Never)]
public override bool IsReadOnly { get { throw null; } }
public string MessageId { get { throw null; } set { } }
public long Offset { get { throw null; } }
public string PartitionKey { get { throw null; } }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,11 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="Azure.Core" />
<!--
TEMP: Move Core to a project reference until the
MessageWithMetadata are shipped in Azure.Core.
<PackageReference Include="Azure.Core" />
-->
<PackageReference Include="Azure.Core.Amqp" />
<PackageReference Include="Microsoft.Azure.Amqp" />
<PackageReference Include="Microsoft.Bcl.AsyncInterfaces" />
Expand Down Expand Up @@ -59,4 +63,7 @@
<CustomToolNamespace>Azure.Messaging.EventHubs</CustomToolNamespace>
</EmbeddedResource>
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\..\core\Azure.Core.Experimental\src\Azure.Core.Experimental.csproj" />
</ItemGroup>
</Project>
24 changes: 21 additions & 3 deletions sdk/eventhub/Azure.Messaging.EventHubs/src/EventData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
using System.IO;
using System.Text;
using Azure.Core;
using Azure.Core.Amqp;
using Azure.Core.Serialization;
using Azure.Core.Amqp;
using Azure.Messaging.EventHubs.Amqp;
using Azure.Messaging.EventHubs.Consumer;
using Azure.Messaging.EventHubs.Producer;
Expand All @@ -19,7 +19,7 @@ namespace Azure.Messaging.EventHubs
/// An Event Hubs event, encapsulating a set of data and its associated metadata.
/// </summary>
///
public class EventData
public class EventData : MessageWithMetadata
{
/// <summary>The AMQP representation of the event, allowing access to additional protocol data elements not used directly by the Event Hubs client library.</summary>
private readonly AmqpAnnotatedMessage _amqpMessage;
Expand Down Expand Up @@ -48,6 +48,17 @@ public BinaryData EventBody
set => _amqpMessage.Body = AmqpMessageBody.FromData(MessageBody.FromReadOnlyMemorySegment(value.ToMemory()));
}

/// <summary>
/// Hidden property that shadows the <see cref="EventBody"/> property. This is added
/// in order to inherit from <see cref="MessageWithMetadata"/>.
/// </summary>
[EditorBrowsable(EditorBrowsableState.Never)]
public override BinaryData Data
{
get => EventBody;
set => EventBody = value;
}

/// <summary>
/// A MIME type describing the data contained in the <see cref="EventBody" />,
/// intended to allow consumers to make informed decisions for inspecting and
Expand All @@ -71,7 +82,7 @@ public BinaryData EventBody
///
/// <seealso href="https://datatracker.ietf.org/doc/html/rfc2046">RFC2046 (MIME Types)</seealso>
///
public string ContentType
public override string ContentType
{
get
{
Expand All @@ -96,6 +107,13 @@ public string ContentType
}
}

/// <summary>
/// Hidden property that indicates that the <see cref="EventData"/> is not read-only. This is part of
/// the <see cref="MessageWithMetadata"/> abstraction.
/// </summary>
[EditorBrowsable(EditorBrowsableState.Never)]
public override bool IsReadOnly => false;

/// <summary>
/// An application-defined value that uniquely identifies the event. The identifier is
/// a free-form value and can reflect a GUID or an identifier derived from the application
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,12 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Azure.Core.TestFramework",
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Azure.Data.SchemaRegistry", "..\Azure.Data.SchemaRegistry\src\Azure.Data.SchemaRegistry.csproj", "{D451EE68-ADE4-4780-A002-2D13DEA888A2}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Azure.Core.Experimental", "..\..\core\Azure.Core.Experimental\src\Azure.Core.Experimental.csproj", "{8A0A0FBB-2B12-49B3-951E-5402D64075DD}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Azure.Messaging.EventHubs", "..\..\eventhub\Azure.Messaging.EventHubs\src\Azure.Messaging.EventHubs.csproj", "{FDC382B3-7255-4D33-AAA9-1168B7D01E94}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Azure.Messaging.ServiceBus", "..\..\servicebus\Azure.Messaging.ServiceBus\src\Azure.Messaging.ServiceBus.csproj", "{69E3D417-F0A9-4C6B-B9C5-8C29E9F2A660}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand All @@ -33,6 +39,18 @@ Global
{D451EE68-ADE4-4780-A002-2D13DEA888A2}.Debug|Any CPU.Build.0 = Debug|Any CPU
{D451EE68-ADE4-4780-A002-2D13DEA888A2}.Release|Any CPU.ActiveCfg = Release|Any CPU
{D451EE68-ADE4-4780-A002-2D13DEA888A2}.Release|Any CPU.Build.0 = Release|Any CPU
{8A0A0FBB-2B12-49B3-951E-5402D64075DD}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{8A0A0FBB-2B12-49B3-951E-5402D64075DD}.Debug|Any CPU.Build.0 = Debug|Any CPU
{8A0A0FBB-2B12-49B3-951E-5402D64075DD}.Release|Any CPU.ActiveCfg = Release|Any CPU
{8A0A0FBB-2B12-49B3-951E-5402D64075DD}.Release|Any CPU.Build.0 = Release|Any CPU
{FDC382B3-7255-4D33-AAA9-1168B7D01E94}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{FDC382B3-7255-4D33-AAA9-1168B7D01E94}.Debug|Any CPU.Build.0 = Debug|Any CPU
{FDC382B3-7255-4D33-AAA9-1168B7D01E94}.Release|Any CPU.ActiveCfg = Release|Any CPU
{FDC382B3-7255-4D33-AAA9-1168B7D01E94}.Release|Any CPU.Build.0 = Release|Any CPU
{69E3D417-F0A9-4C6B-B9C5-8C29E9F2A660}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{69E3D417-F0A9-4C6B-B9C5-8C29E9F2A660}.Debug|Any CPU.Build.0 = Debug|Any CPU
{69E3D417-F0A9-4C6B-B9C5-8C29E9F2A660}.Release|Any CPU.ActiveCfg = Release|Any CPU
{69E3D417-F0A9-4C6B-B9C5-8C29E9F2A660}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down
Loading

0 comments on commit b8f395e

Please sign in to comment.