Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add EnablePartitioning to QueueProperties ctor; rename GetRawMessage #17101

Merged
merged 5 commits into from
Nov 20, 2020
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ public ServiceBusMessage(string body) { }
public string Subject { get { throw null; } set { } }
public System.TimeSpan TimeToLive { get { throw null; } set { } }
public string To { get { throw null; } set { } }
public Azure.Core.Amqp.AmqpAnnotatedMessage GetRawMessage() { throw null; }
public Azure.Core.Amqp.AmqpAnnotatedMessage GetRawAmqpMessage() { throw null; }
public override string ToString() { throw null; }
}
public sealed partial class ServiceBusMessageBatch : System.IDisposable
Expand All @@ -184,15 +184,15 @@ public void Dispose() { }
public static partial class ServiceBusModelFactory
{
[System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Never)]
public static Azure.Messaging.ServiceBus.Administration.QueueProperties QueueProperties(string name, System.TimeSpan lockDuration = default(System.TimeSpan), long maxSizeInMegabytes = (long)0, bool requiresDuplicateDetection = false, bool requiresSession = false, System.TimeSpan defaultMessageTimeToLive = default(System.TimeSpan), System.TimeSpan autoDeleteOnIdle = default(System.TimeSpan), bool deadLetteringOnMessageExpiration = false, System.TimeSpan duplicateDetectionHistoryTimeWindow = default(System.TimeSpan), int maxDeliveryCount = 0, bool enableBatchedOperations = false, Azure.Messaging.ServiceBus.Administration.EntityStatus status = default(Azure.Messaging.ServiceBus.Administration.EntityStatus), string forwardTo = null, string forwardDeadLetteredMessagesTo = null, string userMetadata = null) { throw null; }
public static Azure.Messaging.ServiceBus.Administration.QueueProperties QueueProperties(string name, System.TimeSpan lockDuration = default(System.TimeSpan), long maxSizeInMegabytes = (long)0, bool requiresDuplicateDetection = false, bool requiresSession = false, System.TimeSpan defaultMessageTimeToLive = default(System.TimeSpan), System.TimeSpan autoDeleteOnIdle = default(System.TimeSpan), bool deadLetteringOnMessageExpiration = false, System.TimeSpan duplicateDetectionHistoryTimeWindow = default(System.TimeSpan), int maxDeliveryCount = 0, bool enableBatchedOperations = false, Azure.Messaging.ServiceBus.Administration.EntityStatus status = default(Azure.Messaging.ServiceBus.Administration.EntityStatus), string forwardTo = null, string forwardDeadLetteredMessagesTo = null, string userMetadata = null, bool enablePartitioning = false) { throw null; }
[System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Never)]
public static Azure.Messaging.ServiceBus.Administration.RuleProperties RuleProperties(string name, Azure.Messaging.ServiceBus.Administration.RuleFilter filter = null, Azure.Messaging.ServiceBus.Administration.RuleAction action = null) { throw null; }
[System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Never)]
public static Azure.Messaging.ServiceBus.ServiceBusReceivedMessage ServiceBusReceivedMessage(System.BinaryData body = null, string messageId = null, string partitionKey = null, string viaPartitionKey = null, string sessionId = null, string replyToSessionId = null, System.TimeSpan timeToLive = default(System.TimeSpan), string correlationId = null, string subject = null, string to = null, string contentType = null, string replyTo = null, System.DateTimeOffset scheduledEnqueueTime = default(System.DateTimeOffset), System.Collections.Generic.IDictionary<string, object> properties = null, System.Guid lockTokenGuid = default(System.Guid), int deliveryCount = 0, System.DateTimeOffset lockedUntil = default(System.DateTimeOffset), long sequenceNumber = (long)-1, string deadLetterSource = null, long enqueuedSequenceNumber = (long)0, System.DateTimeOffset enqueuedTime = default(System.DateTimeOffset)) { throw null; }
[System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Never)]
public static Azure.Messaging.ServiceBus.Administration.SubscriptionProperties SubscriptionProperties(string topicName, string subscriptionName, System.TimeSpan lockDuration = default(System.TimeSpan), bool requiresSession = false, System.TimeSpan defaultMessageTimeToLive = default(System.TimeSpan), System.TimeSpan autoDeleteOnIdle = default(System.TimeSpan), bool deadLetteringOnMessageExpiration = false, int maxDeliveryCount = 0, bool enableBatchedOperations = false, Azure.Messaging.ServiceBus.Administration.EntityStatus status = default(Azure.Messaging.ServiceBus.Administration.EntityStatus), string forwardTo = null, string forwardDeadLetteredMessagesTo = null, string userMetadata = null) { throw null; }
[System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Never)]
public static Azure.Messaging.ServiceBus.Administration.TopicProperties TopicProperties(string name, long maxSizeInMegabytes = (long)0, bool requiresDuplicateDetection = false, System.TimeSpan defaultMessageTimeToLive = default(System.TimeSpan), System.TimeSpan autoDeleteOnIdle = default(System.TimeSpan), System.TimeSpan duplicateDetectionHistoryTimeWindow = default(System.TimeSpan), bool enableBatchedOperations = false, Azure.Messaging.ServiceBus.Administration.EntityStatus status = default(Azure.Messaging.ServiceBus.Administration.EntityStatus)) { throw null; }
public static Azure.Messaging.ServiceBus.Administration.TopicProperties TopicProperties(string name, long maxSizeInMegabytes = (long)0, bool requiresDuplicateDetection = false, System.TimeSpan defaultMessageTimeToLive = default(System.TimeSpan), System.TimeSpan autoDeleteOnIdle = default(System.TimeSpan), System.TimeSpan duplicateDetectionHistoryTimeWindow = default(System.TimeSpan), bool enableBatchedOperations = false, Azure.Messaging.ServiceBus.Administration.EntityStatus status = default(Azure.Messaging.ServiceBus.Administration.EntityStatus), bool enablePartitioning = false) { throw null; }
}
public partial class ServiceBusProcessor : System.IAsyncDisposable
{
Expand Down Expand Up @@ -260,7 +260,7 @@ internal ServiceBusReceivedMessage() { }
public string Subject { get { throw null; } }
public System.TimeSpan TimeToLive { get { throw null; } }
public string To { get { throw null; } }
public Azure.Core.Amqp.AmqpAnnotatedMessage GetRawMessage() { throw null; }
public Azure.Core.Amqp.AmqpAnnotatedMessage GetRawAmqpMessage() { throw null; }
public override string ToString() { throw null; }
}
public enum ServiceBusReceiveMode
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@

using System;
using System.Collections.Generic;
using System.Xml;
using System.Xml.Linq;
using Azure.Core;

namespace Azure.Messaging.ServiceBus.Administration
Expand Down Expand Up @@ -51,6 +53,7 @@ internal QueueProperties(CreateQueueOptions options)
Status = options.Status;
ForwardTo = options.ForwardTo;
ForwardDeadLetteredMessagesTo = options.ForwardDeadLetteredMessagesTo;
EnablePartitioning = options.EnablePartitioning;
if (options.UserMetadata != null)
{
UserMetadata = options.UserMetadata;
Expand Down Expand Up @@ -286,11 +289,29 @@ public string UserMetadata
}
}

internal bool IsAnonymousAccessible { get; set; } = false;

internal bool SupportOrdering
{
get
{
return _internalSupportOrdering ?? !EnablePartitioning;
}
set
{
_internalSupportOrdering = value;
}
}

internal bool? _internalSupportOrdering = null;

internal bool EnableExpress { get; set; } = false;

/// <summary>
/// List of properties that were retrieved using GetQueue but are not understood by this version of client is stored here.
/// The list will be sent back when an already retrieved QueueDescription will be used in UpdateQueue call.
/// </summary>
internal List<object> UnknownProperties { get; set; }
internal List<XElement> UnknownProperties { get; set; }

/// <summary>
/// Returns a hash code for this instance.
Expand Down Expand Up @@ -326,6 +347,9 @@ public bool Equals(QueueProperties other)
&& RequiresDuplicateDetection.Equals(otherDescription.RequiresDuplicateDetection)
&& RequiresSession.Equals(otherDescription.RequiresSession)
&& Status.Equals(otherDescription.Status)
&& _internalSupportOrdering.Equals(other.SupportOrdering)
&& EnableExpress == other.EnableExpress
&& IsAnonymousAccessible == other.IsAnonymousAccessible
&& string.Equals(_userMetadata, otherDescription._userMetadata, StringComparison.OrdinalIgnoreCase)
&& (AuthorizationRules != null && otherDescription.AuthorizationRules != null
|| AuthorizationRules == null && otherDescription.AuthorizationRules == null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,20 @@ public static XDocument Serialize(this QueueProperties description)
: null,
new XElement(XName.Get("MaxDeliveryCount", AdministrationClientConstants.ServiceBusNamespace), XmlConvert.ToString(description.MaxDeliveryCount)),
new XElement(XName.Get("EnableBatchedOperations", AdministrationClientConstants.ServiceBusNamespace), XmlConvert.ToString(description.EnableBatchedOperations)),
new XElement(XName.Get("IsAnonymousAccessible", AdministrationClientConstants.ServiceBusNamespace), XmlConvert.ToString(description.IsAnonymousAccessible)),
description.AuthorizationRules?.Serialize(),
new XElement(XName.Get("Status", AdministrationClientConstants.ServiceBusNamespace), description.Status.ToString()),
description.ForwardTo != null ? new XElement(XName.Get("ForwardTo", AdministrationClientConstants.ServiceBusNamespace), description.ForwardTo) : null,
description.UserMetadata != null ? new XElement(XName.Get("UserMetadata", AdministrationClientConstants.ServiceBusNamespace), description.UserMetadata) : null,
description._internalSupportOrdering.HasValue ? new XElement(XName.Get("SupportOrdering", AdministrationClientConstants.ServiceBusNamespace), XmlConvert.ToString(description._internalSupportOrdering.Value)) : null,
description.AutoDeleteOnIdle != TimeSpan.MaxValue ? new XElement(XName.Get("AutoDeleteOnIdle", AdministrationClientConstants.ServiceBusNamespace), XmlConvert.ToString(description.AutoDeleteOnIdle)) : null,
new XElement(XName.Get("EnablePartitioning", AdministrationClientConstants.ServiceBusNamespace), XmlConvert.ToString(description.EnablePartitioning)),
description.ForwardDeadLetteredMessagesTo != null ? new XElement(XName.Get("ForwardDeadLetteredMessagesTo", AdministrationClientConstants.ServiceBusNamespace), description.ForwardDeadLetteredMessagesTo) : null
description.ForwardDeadLetteredMessagesTo != null ? new XElement(XName.Get("ForwardDeadLetteredMessagesTo", AdministrationClientConstants.ServiceBusNamespace), description.ForwardDeadLetteredMessagesTo) : null,
new XElement(XName.Get("EnableExpress", AdministrationClientConstants.ServiceBusNamespace), XmlConvert.ToString(description.EnableExpress))
};

// Insert unknown properties in the exact order they were in the received xml.
// Expectation is that servicebus will add any new elements only at the bottom of the xml tree.
if (description.UnknownProperties != null)
{
queueDescriptionElements.AddRange(description.UnknownProperties);
Expand All @@ -50,9 +55,6 @@ public static XDocument Serialize(this QueueProperties description)
queueDescriptionElements.ToArray()))));
}

/// <summary>
///
/// </summary>
public static async Task<QueueProperties> ParseResponseAsync(Response response, ClientDiagnostics diagnostics)
{
try
Expand Down Expand Up @@ -81,7 +83,6 @@ public static async Task<QueueProperties> ParseResponseAsync(Response response,
private static async Task<QueueProperties> ParseFromEntryElementAsync(XElement xEntry, Response response, ClientDiagnostics diagnostics)
{
var name = xEntry.Element(XName.Get("title", AdministrationClientConstants.AtomNamespace)).Value;
var properties = new QueueProperties(name);

var qdXml = xEntry.Element(XName.Get("content", AdministrationClientConstants.AtomNamespace))?
.Element(XName.Get("QueueDescription", AdministrationClientConstants.ServiceBusNamespace));
Expand All @@ -94,10 +95,14 @@ private static async Task<QueueProperties> ParseFromEntryElementAsync(XElement x
innerException: await diagnostics.CreateRequestFailedExceptionAsync(response).ConfigureAwait(false));
}

var properties = new QueueProperties(name);
foreach (var element in qdXml.Elements())
{
switch (element.Name.LocalName)
{
case "LockDuration":
properties.LockDuration = XmlConvert.ToTimeSpan(element.Value);
break;
case "MaxSizeInMegabytes":
properties.MaxSizeInMegabytes = int.Parse(element.Value, CultureInfo.InvariantCulture);
break;
Expand All @@ -107,65 +112,73 @@ private static async Task<QueueProperties> ParseFromEntryElementAsync(XElement x
case "RequiresSession":
properties.RequiresSession = bool.Parse(element.Value);
break;
case "DefaultMessageTimeToLive":
properties.DefaultMessageTimeToLive = XmlConvert.ToTimeSpan(element.Value);
break;
case "DeadLetteringOnMessageExpiration":
properties.DeadLetteringOnMessageExpiration = bool.Parse(element.Value);
break;
case "DuplicateDetectionHistoryTimeWindow":
properties.DuplicateDetectionHistoryTimeWindow = XmlConvert.ToTimeSpan(element.Value);
break;
case "LockDuration":
properties.LockDuration = XmlConvert.ToTimeSpan(element.Value);
break;
case "DefaultMessageTimeToLive":
properties.DefaultMessageTimeToLive = XmlConvert.ToTimeSpan(element.Value);
break;
case "MaxDeliveryCount":
properties.MaxDeliveryCount = int.Parse(element.Value, CultureInfo.InvariantCulture);
break;
case "EnableBatchedOperations":
properties.EnableBatchedOperations = bool.Parse(element.Value);
break;
case "Status":
properties.Status = element.Value;
break;
case "AutoDeleteOnIdle":
properties.AutoDeleteOnIdle = XmlConvert.ToTimeSpan(element.Value);
case "IsAnonymousAccessible":
properties.IsAnonymousAccessible = Boolean.Parse(element.Value);
break;
case "EnablePartitioning":
properties.EnablePartitioning = bool.Parse(element.Value);
case "AuthorizationRules":
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not worth taking on this close to code complete, but may be worth a follow-up at some point to pull the magic strings out into a set of constants.

properties.AuthorizationRules = AuthorizationRules.ParseFromXElement(element);
break;
case "UserMetadata":
properties.UserMetadata = element.Value;
case "Status":
properties.Status = element.Value;
break;
case "ForwardTo":
if (!string.IsNullOrWhiteSpace(element.Value))
{
properties.ForwardTo = element.Value;
}
break;
case "UserMetadata":
properties.UserMetadata = element.Value;
break;
case "SupportOrdering":
properties.SupportOrdering = Boolean.Parse(element.Value);
break;
case "AutoDeleteOnIdle":
properties.AutoDeleteOnIdle = XmlConvert.ToTimeSpan(element.Value);
break;
case "EnablePartitioning":
properties.EnablePartitioning = bool.Parse(element.Value);
break;
case "ForwardDeadLetteredMessagesTo":
if (!string.IsNullOrWhiteSpace(element.Value))
{
properties.ForwardDeadLetteredMessagesTo = element.Value;
}
break;
case "AuthorizationRules":
properties.AuthorizationRules = AuthorizationRules.ParseFromXElement(element);
case "EnableExpress":
properties.EnableExpress = bool.Parse(element.Value);
break;
case "AccessedAt":
case "CreatedAt":
case "MessageCount":
case "SizeInBytes":
case "UpdatedAt":
case "CountDetails":
case "EntityAvailabilityStatus":
case "SkippedUpdate":
// Ignore known properties
// Do nothing
break;
default:
// For unknown properties, keep them as-is for forward proof.
if (properties.UnknownProperties == null)
{
properties.UnknownProperties = new List<object>();
properties.UnknownProperties = new List<XElement>();
}

properties.UnknownProperties.Add(element);
Expand Down
Loading