| | | 1 | | // Copyright (c) Microsoft Corporation. All rights reserved. |
| | | 2 | | // Licensed under the MIT License. |
| | | 3 | | |
| | | 4 | | using System; |
| | | 5 | | using System.Globalization; |
| | | 6 | | using System.IO; |
| | | 7 | | using System.Threading; |
| | | 8 | | using System.Threading.Tasks; |
| | | 9 | | using Azure.Core; |
| | | 10 | | using Azure.Core.Pipeline; |
| | | 11 | | using Azure.Messaging.ServiceBus.Authorization; |
| | | 12 | | using Azure.Messaging.ServiceBus.Core; |
| | | 13 | | |
| | | 14 | | namespace Azure.Messaging.ServiceBus.Management |
| | | 15 | | { |
| | | 16 | | /// <summary> |
| | | 17 | | /// The <see cref="ServiceBusManagementClient"/> is the client through which all Service Bus |
| | | 18 | | /// entities can be created, updated, fetched and deleted. |
| | | 19 | | /// </summary> |
| | | 20 | | public class ServiceBusManagementClient |
| | | 21 | | { |
| | | 22 | | private readonly string _fullyQualifiedNamespace; |
| | | 23 | | private readonly HttpRequestAndResponse _httpRequestAndResponse; |
| | | 24 | | private readonly ClientDiagnostics _clientDiagnostics; |
| | | 25 | | |
| | | 26 | | /// <summary> |
| | | 27 | | /// Path to get the namespce properties. |
| | | 28 | | /// </summary> |
| | | 29 | | private const string NamespacePath = "$namespaceinfo"; |
| | | 30 | | |
| | | 31 | | /// <summary> |
| | | 32 | | /// Path to get the list of queues. |
| | | 33 | | /// </summary> |
| | | 34 | | private const string QueuesPath = "$Resources/queues"; |
| | | 35 | | |
| | | 36 | | /// <summary> |
| | | 37 | | /// Path to get the list of topics. |
| | | 38 | | /// </summary> |
| | | 39 | | private const string TopicsPath = "$Resources/topics"; |
| | | 40 | | |
| | | 41 | | /// <summary> |
| | | 42 | | /// Path to get the list of subscriptions for a given topic. |
| | | 43 | | /// </summary> |
| | | 44 | | private const string SubscriptionsPath = "{0}/Subscriptions"; |
| | | 45 | | |
| | | 46 | | /// <summary> |
| | | 47 | | /// Path to get the list of rules for a given subscription and topic. |
| | | 48 | | /// </summary> |
| | | 49 | | private const string RulesPath = "{0}/Subscriptions/{1}/rules"; |
| | | 50 | | |
| | | 51 | | /// <summary> |
| | | 52 | | /// Parameterless constructor to allow mocking. |
| | | 53 | | /// </summary> |
| | 88 | 54 | | protected ServiceBusManagementClient() { } |
| | | 55 | | |
| | | 56 | | /// <summary> |
| | | 57 | | /// Initializes a new <see cref="ServiceBusManagementClient"/> which can be used to perform management operation |
| | | 58 | | /// </summary> |
| | | 59 | | /// |
| | | 60 | | /// <param name="connectionString">Namespace connection string.</param> |
| | | 61 | | public ServiceBusManagementClient(string connectionString) |
| | 0 | 62 | | : this(connectionString, new ServiceBusManagementClientOptions()) |
| | | 63 | | { |
| | 0 | 64 | | } |
| | | 65 | | |
| | | 66 | | /// <summary> |
| | | 67 | | /// Initializes a new <see cref="ServiceBusManagementClient"/> which can be used to perform management operation |
| | | 68 | | /// </summary> |
| | | 69 | | /// |
| | | 70 | | /// <param name="connectionString">Namespace connection string.</param> |
| | | 71 | | /// <param name="options"></param> |
| | 40 | 72 | | public ServiceBusManagementClient( |
| | 40 | 73 | | string connectionString, |
| | 40 | 74 | | ServiceBusManagementClientOptions options) |
| | | 75 | | { |
| | 40 | 76 | | Argument.AssertNotNullOrEmpty(connectionString, nameof(connectionString)); |
| | 40 | 77 | | options ??= new ServiceBusManagementClientOptions(); |
| | 40 | 78 | | ConnectionStringProperties connectionStringProperties = ConnectionStringParser.Parse(connectionString); |
| | | 79 | | |
| | 40 | 80 | | if (string.IsNullOrEmpty(connectionStringProperties.Endpoint?.Host) |
| | 40 | 81 | | || string.IsNullOrEmpty(connectionStringProperties.SharedAccessKeyName) |
| | 40 | 82 | | || string.IsNullOrEmpty(connectionStringProperties.SharedAccessKey)) |
| | | 83 | | { |
| | 0 | 84 | | throw new ArgumentException(Resources.MissingConnectionInformation, nameof(connectionString)); |
| | | 85 | | } |
| | | 86 | | |
| | 40 | 87 | | _fullyQualifiedNamespace = connectionStringProperties.Endpoint.Host; |
| | | 88 | | |
| | 40 | 89 | | var sharedAccessSignature = new SharedAccessSignature |
| | 40 | 90 | | ( |
| | 40 | 91 | | BuildAudienceResource(connectionStringProperties.Endpoint.Host), |
| | 40 | 92 | | connectionStringProperties.SharedAccessKeyName, |
| | 40 | 93 | | connectionStringProperties.SharedAccessKey |
| | 40 | 94 | | ); |
| | | 95 | | |
| | 40 | 96 | | var sharedCredential = new SharedAccessSignatureCredential(sharedAccessSignature); |
| | 40 | 97 | | var tokenCredential = new ServiceBusTokenCredential( |
| | 40 | 98 | | sharedCredential, |
| | 40 | 99 | | BuildAudienceResource(connectionStringProperties.Endpoint.Host)); |
| | | 100 | | |
| | 40 | 101 | | HttpPipeline pipeline = HttpPipelineBuilder.Build(options); |
| | 40 | 102 | | _httpRequestAndResponse = new HttpRequestAndResponse( |
| | 40 | 103 | | pipeline, |
| | 40 | 104 | | new ClientDiagnostics(options), |
| | 40 | 105 | | tokenCredential, |
| | 40 | 106 | | _fullyQualifiedNamespace); |
| | 40 | 107 | | _clientDiagnostics = new ClientDiagnostics(options); |
| | 40 | 108 | | } |
| | | 109 | | |
| | | 110 | | /// <summary> |
| | | 111 | | /// Initializes a new <see cref="ServiceBusManagementClient"/> which can be used to perform management operation |
| | | 112 | | /// </summary> |
| | | 113 | | /// |
| | | 114 | | /// <param name="fullyQualifiedNamespace">The fully qualified Service Bus namespace to connect to. This is like |
| | | 115 | | /// <param name="credential">The Azure managed identity credential to use for authorization. Access controls ma |
| | | 116 | | public ServiceBusManagementClient( |
| | | 117 | | string fullyQualifiedNamespace, |
| | | 118 | | TokenCredential credential) |
| | 0 | 119 | | : this(fullyQualifiedNamespace, credential, new ServiceBusManagementClientOptions()) |
| | | 120 | | { |
| | 0 | 121 | | } |
| | | 122 | | |
| | | 123 | | /// <summary> |
| | | 124 | | /// Initializes a new <see cref="ServiceBusManagementClient"/> which can be used to perform management operation |
| | | 125 | | /// </summary> |
| | | 126 | | /// |
| | | 127 | | /// <param name="fullyQualifiedNamespace">The fully qualified Service Bus namespace to connect to. This is like |
| | | 128 | | /// <param name="credential">The Azure managed identity credential to use for authorization. Access controls ma |
| | | 129 | | /// <param name="options">A set of options to apply when configuring the connection.</param> |
| | 4 | 130 | | public ServiceBusManagementClient( |
| | 4 | 131 | | string fullyQualifiedNamespace, |
| | 4 | 132 | | TokenCredential credential, |
| | 4 | 133 | | ServiceBusManagementClientOptions options) |
| | | 134 | | { |
| | 4 | 135 | | Argument.AssertWellFormedServiceBusNamespace(fullyQualifiedNamespace, nameof(fullyQualifiedNamespace)); |
| | 4 | 136 | | Argument.AssertNotNull(credential, nameof(credential)); |
| | | 137 | | |
| | 4 | 138 | | options ??= new ServiceBusManagementClientOptions(); |
| | 4 | 139 | | _fullyQualifiedNamespace = fullyQualifiedNamespace; |
| | | 140 | | |
| | | 141 | | switch (credential) |
| | | 142 | | { |
| | | 143 | | case SharedAccessSignatureCredential _: |
| | | 144 | | break; |
| | | 145 | | |
| | | 146 | | case ServiceBusSharedKeyCredential sharedKeyCredential: |
| | 0 | 147 | | credential = sharedKeyCredential.AsSharedAccessSignatureCredential(BuildAudienceResource(fullyQualif |
| | | 148 | | break; |
| | | 149 | | } |
| | 4 | 150 | | var tokenCredential = new ServiceBusTokenCredential(credential, BuildAudienceResource(fullyQualifiedNamespac |
| | | 151 | | |
| | 4 | 152 | | var authenticationPolicy = new BearerTokenAuthenticationPolicy(credential, Constants.DefaultScope); |
| | 4 | 153 | | HttpPipeline pipeline = HttpPipelineBuilder.Build( |
| | 4 | 154 | | options, |
| | 4 | 155 | | authenticationPolicy); |
| | 4 | 156 | | _clientDiagnostics = new ClientDiagnostics(options); |
| | | 157 | | |
| | 4 | 158 | | _httpRequestAndResponse = new HttpRequestAndResponse( |
| | 4 | 159 | | pipeline, |
| | 4 | 160 | | _clientDiagnostics, |
| | 4 | 161 | | tokenCredential, |
| | 4 | 162 | | _fullyQualifiedNamespace); |
| | | 163 | | |
| | 4 | 164 | | } |
| | | 165 | | |
| | | 166 | | /// <summary> |
| | | 167 | | /// Gets information related to the currently used namespace. |
| | | 168 | | /// </summary> |
| | | 169 | | /// |
| | | 170 | | /// <param name="cancellationToken">An optional <see cref="CancellationToken"/> instance to signal the request t |
| | | 171 | | /// |
| | | 172 | | /// <remarks>Works with any claim (Send/Listen/Manage).</remarks> |
| | | 173 | | /// <returns><see cref="NamespaceProperties"/> containing namespace information.</returns> |
| | | 174 | | public virtual async Task<Response<NamespaceProperties>> GetNamespacePropertiesAsync(CancellationToken cancellat |
| | | 175 | | { |
| | 4 | 176 | | using DiagnosticScope scope = _clientDiagnostics.CreateScope($"{nameof(ServiceBusManagementClient)}.GetNames |
| | 4 | 177 | | scope.Start(); |
| | | 178 | | |
| | | 179 | | try |
| | | 180 | | { |
| | 4 | 181 | | Response response = await _httpRequestAndResponse.GetEntityAsync( |
| | 4 | 182 | | NamespacePath, |
| | 4 | 183 | | null, |
| | 4 | 184 | | false, |
| | 4 | 185 | | cancellationToken).ConfigureAwait(false); |
| | 4 | 186 | | var result = await ReadAsString(response).ConfigureAwait(false); |
| | 4 | 187 | | NamespaceProperties properties = NamespacePropertiesExtensions.ParseFromContent(result); |
| | | 188 | | |
| | 4 | 189 | | return Response.FromValue(properties, response); |
| | | 190 | | } |
| | 0 | 191 | | catch (Exception ex) |
| | | 192 | | { |
| | 0 | 193 | | scope.Failed(ex); |
| | 0 | 194 | | throw; |
| | | 195 | | } |
| | 4 | 196 | | } |
| | | 197 | | |
| | | 198 | | #region DeleteEntity |
| | | 199 | | |
| | | 200 | | /// <summary> |
| | | 201 | | /// Deletes the queue described by the name relative to the service namespace base address. |
| | | 202 | | /// </summary> |
| | | 203 | | /// |
| | | 204 | | /// <param name="name">The name of the queue relative to the service namespace base address.</param> |
| | | 205 | | /// <param name="cancellationToken">An optional <see cref="CancellationToken"/> instance to signal the request t |
| | | 206 | | /// |
| | | 207 | | /// <exception cref="ArgumentException"><paramref name="name"/> is empty or null, or name starts or ends with "/ |
| | | 208 | | /// <exception cref="ArgumentOutOfRangeException">The length of name is greater than 260.</exception> |
| | | 209 | | /// <exception cref="ServiceBusFailureReason.ServiceTimeout">The operation times out. The timeout period is init |
| | | 210 | | /// <exception cref="ServiceBusFailureReason.MessagingEntityNotFound">Queue with this name does not exist.</exce |
| | | 211 | | /// <exception cref="UnauthorizedAccessException">No sufficient permission to perform this operation. You should |
| | | 212 | | /// <exception cref="ServiceBusFailureReason.ServiceBusy">The server is busy. You should wait before you retry t |
| | | 213 | | /// <exception cref="ServiceBusException">An internal error or an unexpected exception occured.</exception> |
| | | 214 | | public virtual async Task<Response> DeleteQueueAsync( |
| | | 215 | | string name, |
| | | 216 | | CancellationToken cancellationToken = default) |
| | | 217 | | { |
| | 20 | 218 | | EntityNameFormatter.CheckValidQueueName(name); |
| | 20 | 219 | | using DiagnosticScope scope = _clientDiagnostics.CreateScope($"{nameof(ServiceBusManagementClient)}.DeleteQu |
| | 20 | 220 | | scope.Start(); |
| | | 221 | | |
| | | 222 | | try |
| | | 223 | | { |
| | 20 | 224 | | return await _httpRequestAndResponse.DeleteEntityAsync(name, cancellationToken).ConfigureAwait(false); |
| | | 225 | | } |
| | 4 | 226 | | catch (Exception ex) |
| | | 227 | | { |
| | 4 | 228 | | scope.Failed(ex); |
| | 4 | 229 | | throw; |
| | | 230 | | } |
| | 16 | 231 | | } |
| | | 232 | | |
| | | 233 | | /// <summary> |
| | | 234 | | /// Deletes the topic described by the name relative to the service namespace base address. |
| | | 235 | | /// </summary> |
| | | 236 | | /// |
| | | 237 | | /// <param name="name">The name of the topic relative to the service namespace base address.</param> |
| | | 238 | | /// <param name="cancellationToken">An optional <see cref="CancellationToken"/> instance to signal the request t |
| | | 239 | | /// |
| | | 240 | | /// <exception cref="ArgumentException"><paramref name="name"/> is empty or null, or name starts or ends with "/ |
| | | 241 | | /// <exception cref="ArgumentOutOfRangeException">The length of topic name is greater than 260.</exception> |
| | | 242 | | /// <exception cref="ServiceBusFailureReason.ServiceTimeout">The operation times out. The timeout period is init |
| | | 243 | | /// <exception cref="ServiceBusFailureReason.MessagingEntityNotFound">Topic with this name does not exist.</exce |
| | | 244 | | /// <exception cref="UnauthorizedAccessException">No sufficient permission to perform this operation. You should |
| | | 245 | | /// <exception cref="ServiceBusFailureReason.ServiceBusy">The server is busy. You should wait before you retry t |
| | | 246 | | /// <exception cref="ServiceBusException">An internal error or an unexpected exception occured.</exception> |
| | | 247 | | public virtual async Task<Response> DeleteTopicAsync( |
| | | 248 | | string name, |
| | | 249 | | CancellationToken cancellationToken = default) |
| | | 250 | | { |
| | 40 | 251 | | EntityNameFormatter.CheckValidTopicName(name); |
| | 40 | 252 | | using DiagnosticScope scope = _clientDiagnostics.CreateScope($"{nameof(ServiceBusManagementClient)}.DeleteTo |
| | 40 | 253 | | scope.Start(); |
| | | 254 | | |
| | | 255 | | try |
| | | 256 | | { |
| | 40 | 257 | | return await _httpRequestAndResponse.DeleteEntityAsync(name, cancellationToken).ConfigureAwait(false); |
| | | 258 | | } |
| | 4 | 259 | | catch (Exception ex) |
| | | 260 | | { |
| | 4 | 261 | | scope.Failed(ex); |
| | 4 | 262 | | throw; |
| | | 263 | | } |
| | 36 | 264 | | } |
| | | 265 | | |
| | | 266 | | /// <summary> |
| | | 267 | | /// Deletes the subscription with the specified topic and subscription name. |
| | | 268 | | /// </summary> |
| | | 269 | | /// |
| | | 270 | | /// <param name="topicName">The name of the topic relative to the service namespace base address.</param> |
| | | 271 | | /// <param name="subscriptionName">The name of the subscription to delete.</param> |
| | | 272 | | /// <param name="cancellationToken">An optional <see cref="CancellationToken"/> instance to signal the request t |
| | | 273 | | /// |
| | | 274 | | /// <exception cref="ArgumentException"><paramref name="topicName"/> or <paramref name="subscriptionName"/> is e |
| | | 275 | | /// <exception cref="ArgumentOutOfRangeException">The length of topic name is greater than 260 or length of subs |
| | | 276 | | /// <exception cref="ServiceBusFailureReason.ServiceTimeout">The operation times out. The timeout period is init |
| | | 277 | | /// <exception cref="ServiceBusFailureReason.MessagingEntityNotFound">Subscription with this name does not exist |
| | | 278 | | /// <exception cref="UnauthorizedAccessException">No sufficient permission to perform this operation. You should |
| | | 279 | | /// <exception cref="ServiceBusFailureReason.ServiceBusy">The server is busy. You should wait before you retry t |
| | | 280 | | /// <exception cref="ServiceBusException">An internal error or an unexpected exception occured.</exception> |
| | | 281 | | public virtual async Task<Response> DeleteSubscriptionAsync( |
| | | 282 | | string topicName, |
| | | 283 | | string subscriptionName, |
| | | 284 | | CancellationToken cancellationToken = default) |
| | | 285 | | { |
| | 8 | 286 | | EntityNameFormatter.CheckValidTopicName(topicName); |
| | 8 | 287 | | EntityNameFormatter.CheckValidSubscriptionName(subscriptionName); |
| | 8 | 288 | | using DiagnosticScope scope = _clientDiagnostics.CreateScope($"{nameof(ServiceBusManagementClient)}.DeleteSu |
| | 8 | 289 | | scope.Start(); |
| | | 290 | | |
| | | 291 | | try |
| | | 292 | | { |
| | 8 | 293 | | return await _httpRequestAndResponse.DeleteEntityAsync(EntityNameFormatter.FormatSubscriptionPath(topicN |
| | | 294 | | } |
| | 4 | 295 | | catch (Exception ex) |
| | | 296 | | { |
| | 4 | 297 | | scope.Failed(ex); |
| | 4 | 298 | | throw; |
| | | 299 | | } |
| | 4 | 300 | | } |
| | | 301 | | |
| | | 302 | | /// <summary> |
| | | 303 | | /// Deletes the rule described by <paramref name="ruleName"/> from <paramref name="subscriptionName"/> under <pa |
| | | 304 | | /// </summary> |
| | | 305 | | /// |
| | | 306 | | /// <param name="topicName">The name of the topic relative to the service namespace base address.</param> |
| | | 307 | | /// <param name="subscriptionName">The name of the subscription to delete.</param> |
| | | 308 | | /// <param name="ruleName">The name of the rule to delete.</param> |
| | | 309 | | /// <param name="cancellationToken">An optional <see cref="CancellationToken"/> instance to signal the request t |
| | | 310 | | /// |
| | | 311 | | /// <exception cref="ArgumentException">Thrown if <paramref name="topicName"/>, <paramref name="subscriptionName |
| | | 312 | | /// <exception cref="ArgumentOutOfRangeException">The length of topic name is greater than 260 or length of subs |
| | | 313 | | /// <exception cref="ServiceBusFailureReason.ServiceTimeout">The operation times out. The timeout period is init |
| | | 314 | | /// <exception cref="ServiceBusFailureReason.MessagingEntityNotFound">Rule with this name does not exist.</excep |
| | | 315 | | /// <exception cref="UnauthorizedAccessException">No sufficient permission to perform this operation. You should |
| | | 316 | | /// <exception cref="ServiceBusFailureReason.ServiceBusy">The server is busy. You should wait before you retry t |
| | | 317 | | /// <exception cref="ServiceBusException">An internal error or an unexpected exception occured.</exception> |
| | | 318 | | public virtual async Task<Response> DeleteRuleAsync( |
| | | 319 | | string topicName, |
| | | 320 | | string subscriptionName, |
| | | 321 | | string ruleName, |
| | | 322 | | CancellationToken cancellationToken = default) |
| | | 323 | | { |
| | 4 | 324 | | EntityNameFormatter.CheckValidTopicName(topicName); |
| | 4 | 325 | | EntityNameFormatter.CheckValidSubscriptionName(subscriptionName); |
| | 4 | 326 | | EntityNameFormatter.CheckValidRuleName(ruleName); |
| | 4 | 327 | | using DiagnosticScope scope = _clientDiagnostics.CreateScope($"{nameof(ServiceBusManagementClient)}.DeleteRu |
| | 4 | 328 | | scope.Start(); |
| | | 329 | | |
| | | 330 | | try |
| | | 331 | | { |
| | 4 | 332 | | return await _httpRequestAndResponse.DeleteEntityAsync(EntityNameFormatter.FormatRulePath(topicName, sub |
| | | 333 | | } |
| | 0 | 334 | | catch (Exception ex) |
| | | 335 | | { |
| | 0 | 336 | | scope.Failed(ex); |
| | 0 | 337 | | throw; |
| | | 338 | | } |
| | 4 | 339 | | } |
| | | 340 | | |
| | | 341 | | #endregion |
| | | 342 | | |
| | | 343 | | #region GetEntity |
| | | 344 | | |
| | | 345 | | /// <summary> |
| | | 346 | | /// Retrieves a queue from the service namespace. |
| | | 347 | | /// </summary> |
| | | 348 | | /// |
| | | 349 | | /// <param name="name">The name of the queue relative to service bus namespace.</param> |
| | | 350 | | /// <param name="cancellationToken">An optional <see cref="CancellationToken"/> instance to signal the request t |
| | | 351 | | /// |
| | | 352 | | /// <returns><see cref="QueueProperties"/> containing information about the queue.</returns> |
| | | 353 | | /// <exception cref="ArgumentException">Thrown if <paramref name="name"/> is null, white space empty or not in t |
| | | 354 | | /// <exception cref="ArgumentOutOfRangeException">The length of queue name is greater than 260.</exception> |
| | | 355 | | /// <exception cref="ServiceBusFailureReason.ServiceTimeout">The operation times out. The timeout period is init |
| | | 356 | | /// <exception cref="ServiceBusFailureReason.MessagingEntityNotFound">Queue with this name does not exist.</exce |
| | | 357 | | /// <exception cref="UnauthorizedAccessException">No sufficient permission to perform this operation. You should |
| | | 358 | | /// <exception cref="ServiceBusFailureReason.ServiceBusy">The server is busy. You should wait before you retry t |
| | | 359 | | /// <exception cref="ServiceBusException">An internal error or an unexpected exception occured.</exception> |
| | | 360 | | public virtual async Task<Response<QueueProperties>> GetQueueAsync( |
| | | 361 | | string name, |
| | | 362 | | CancellationToken cancellationToken = default) |
| | | 363 | | { |
| | 20 | 364 | | EntityNameFormatter.CheckValidQueueName(name); |
| | 20 | 365 | | using DiagnosticScope scope = _clientDiagnostics.CreateScope($"{nameof(ServiceBusManagementClient)}.GetQueue |
| | 20 | 366 | | scope.Start(); |
| | | 367 | | |
| | | 368 | | try |
| | | 369 | | { |
| | 20 | 370 | | Response response = await _httpRequestAndResponse.GetEntityAsync(name, null, false, cancellationToken).C |
| | 20 | 371 | | var result = await ReadAsString(response).ConfigureAwait(false); |
| | 20 | 372 | | QueueProperties properties = QueuePropertiesExtensions.ParseFromContent(result); |
| | 4 | 373 | | return Response.FromValue(properties, response); |
| | | 374 | | } |
| | 16 | 375 | | catch (Exception ex) |
| | | 376 | | { |
| | 16 | 377 | | scope.Failed(ex); |
| | 16 | 378 | | throw; |
| | | 379 | | } |
| | 4 | 380 | | } |
| | | 381 | | |
| | | 382 | | /// <summary> |
| | | 383 | | /// Retrieves a topic from the service namespace. |
| | | 384 | | /// </summary> |
| | | 385 | | /// |
| | | 386 | | /// <param name="name">The name of the topic relative to service bus namespace.</param> |
| | | 387 | | /// <param name="cancellationToken">An optional <see cref="CancellationToken"/> instance to signal the request t |
| | | 388 | | /// |
| | | 389 | | /// <returns><see cref="TopicProperties"/> containing information about the topic.</returns> |
| | | 390 | | /// <exception cref="ArgumentException">Thrown if <paramref name="name"/> is null, white space empty or not in t |
| | | 391 | | /// <exception cref="ArgumentOutOfRangeException">The length of topic name is greater than 260.</exception> |
| | | 392 | | /// <exception cref="ServiceBusFailureReason.ServiceTimeout">The operation times out. The timeout period is init |
| | | 393 | | /// <exception cref="ServiceBusFailureReason.MessagingEntityNotFound">Topic with this name does not exist.</exce |
| | | 394 | | /// <exception cref="UnauthorizedAccessException">No sufficient permission to perform this operation. You should |
| | | 395 | | /// <exception cref="ServiceBusFailureReason.ServiceBusy">The server is busy. You should wait before you retry t |
| | | 396 | | /// <exception cref="ServiceBusException">An internal error or an unexpected exception occured.</exception> |
| | | 397 | | public virtual async Task<Response<TopicProperties>> GetTopicAsync( |
| | | 398 | | string name, |
| | | 399 | | CancellationToken cancellationToken = default) |
| | | 400 | | { |
| | 16 | 401 | | EntityNameFormatter.CheckValidTopicName(name); |
| | 16 | 402 | | using DiagnosticScope scope = _clientDiagnostics.CreateScope($"{nameof(ServiceBusManagementClient)}.GetTopic |
| | 16 | 403 | | scope.Start(); |
| | | 404 | | |
| | | 405 | | try |
| | | 406 | | { |
| | 16 | 407 | | Response response = await _httpRequestAndResponse.GetEntityAsync(name, null, false, cancellationToken).C |
| | 16 | 408 | | var result = await ReadAsString(response).ConfigureAwait(false); |
| | 16 | 409 | | TopicProperties properties = TopicPropertiesExtensions.ParseFromContent(result); |
| | | 410 | | |
| | 8 | 411 | | return Response.FromValue(properties, response); |
| | | 412 | | } |
| | 8 | 413 | | catch (Exception ex) |
| | | 414 | | { |
| | 8 | 415 | | scope.Failed(ex); |
| | 8 | 416 | | throw; |
| | | 417 | | } |
| | 8 | 418 | | } |
| | | 419 | | |
| | | 420 | | /// <summary> |
| | | 421 | | /// Retrieves a subscription from the service namespace. |
| | | 422 | | /// </summary> |
| | | 423 | | /// |
| | | 424 | | /// <param name="topicName">The name of the topic relative to service bus namespace.</param> |
| | | 425 | | /// <param name="subscriptionName">The subscription name.</param> |
| | | 426 | | /// <param name="cancellationToken">An optional <see cref="CancellationToken"/> instance to signal the request t |
| | | 427 | | /// |
| | | 428 | | /// <returns><see cref="SubscriptionProperties"/> containing information about the subscription.</returns> |
| | | 429 | | /// <exception cref="ArgumentException">Thrown if <paramref name="topicName"/>, <paramref name="subscriptionName |
| | | 430 | | /// <exception cref="ArgumentOutOfRangeException">The length of topic name is greater than 260 or length of subs |
| | | 431 | | /// <exception cref="ServiceBusFailureReason.ServiceTimeout">The operation times out. The timeout period is init |
| | | 432 | | /// <exception cref="ServiceBusFailureReason.MessagingEntityNotFound">Topic or Subscription with this name does |
| | | 433 | | /// <exception cref="UnauthorizedAccessException">No sufficient permission to perform this operation. You should |
| | | 434 | | /// <exception cref="ServiceBusFailureReason.ServiceBusy">The server is busy. You should wait before you retry t |
| | | 435 | | /// <exception cref="ServiceBusException">An internal error or an unexpected exception occured.</exception> |
| | | 436 | | public virtual async Task<Response<SubscriptionProperties>> GetSubscriptionAsync( |
| | | 437 | | string topicName, |
| | | 438 | | string subscriptionName, |
| | | 439 | | CancellationToken cancellationToken = default) |
| | | 440 | | { |
| | 16 | 441 | | EntityNameFormatter.CheckValidTopicName(topicName); |
| | 16 | 442 | | EntityNameFormatter.CheckValidSubscriptionName(subscriptionName); |
| | 16 | 443 | | using DiagnosticScope scope = _clientDiagnostics.CreateScope($"{nameof(ServiceBusManagementClient)}.GetSubsc |
| | 16 | 444 | | scope.Start(); |
| | | 445 | | try |
| | | 446 | | { |
| | 16 | 447 | | Response response = await _httpRequestAndResponse.GetEntityAsync(EntityNameFormatter.FormatSubscriptionP |
| | 12 | 448 | | var result = await ReadAsString(response).ConfigureAwait(false); |
| | 12 | 449 | | SubscriptionProperties properties = SubscriptionPropertiesExtensions.ParseFromContent(topicName, result) |
| | | 450 | | |
| | 8 | 451 | | return Response.FromValue(properties, response); |
| | | 452 | | } |
| | 8 | 453 | | catch (Exception ex) |
| | | 454 | | { |
| | 8 | 455 | | scope.Failed(ex); |
| | 8 | 456 | | throw; |
| | | 457 | | } |
| | 8 | 458 | | } |
| | | 459 | | |
| | | 460 | | /// <summary> |
| | | 461 | | /// Retrieves a rule from the service namespace. |
| | | 462 | | /// </summary> |
| | | 463 | | /// |
| | | 464 | | /// <param name="topicName">The name of the topic relative to service bus namespace.</param> |
| | | 465 | | /// <param name="subscriptionName">The subscription name the rule belongs to.</param> |
| | | 466 | | /// <param name="ruleName">The name of the rule to retrieve.</param> |
| | | 467 | | /// <param name="cancellationToken">An optional <see cref="CancellationToken"/> instance to signal the request t |
| | | 468 | | /// |
| | | 469 | | /// <remarks>Note - Only following data types are deserialized in Filters and Action parameters - string,int,lon |
| | | 470 | | /// Other data types would return its string value.</remarks> |
| | | 471 | | /// <returns><see cref="RuleProperties"/> containing information about the rule.</returns> |
| | | 472 | | /// <exception cref="ArgumentException">Thrown if <paramref name="topicName"/>, <paramref name="subscriptionName |
| | | 473 | | /// <exception cref="ArgumentOutOfRangeException">The length of topic name is greater than 260 or length of subs |
| | | 474 | | /// <exception cref="ServiceBusFailureReason.ServiceTimeout">The operation times out. The timeout period is init |
| | | 475 | | /// <exception cref="ServiceBusFailureReason.MessagingEntityNotFound">Topic/Subscription/Rule with this name doe |
| | | 476 | | /// <exception cref="UnauthorizedAccessException">No sufficient permission to perform this operation. You should |
| | | 477 | | /// <exception cref="ServiceBusFailureReason.ServiceBusy">The server is busy. You should wait before you retry t |
| | | 478 | | /// <exception cref="ServiceBusException">An internal error or an unexpected exception occured.</exception> |
| | | 479 | | public virtual async Task<Response<RuleProperties>> GetRuleAsync( |
| | | 480 | | string topicName, |
| | | 481 | | string subscriptionName, |
| | | 482 | | string ruleName, |
| | | 483 | | CancellationToken cancellationToken = default) |
| | | 484 | | { |
| | 16 | 485 | | EntityNameFormatter.CheckValidTopicName(topicName); |
| | 16 | 486 | | EntityNameFormatter.CheckValidSubscriptionName(subscriptionName); |
| | 16 | 487 | | EntityNameFormatter.CheckValidRuleName(ruleName); |
| | | 488 | | |
| | 16 | 489 | | using DiagnosticScope scope = _clientDiagnostics.CreateScope($"{nameof(ServiceBusManagementClient)}.GetRule" |
| | 16 | 490 | | scope.Start(); |
| | | 491 | | |
| | | 492 | | try |
| | | 493 | | { |
| | 16 | 494 | | Response response = await _httpRequestAndResponse.GetEntityAsync(EntityNameFormatter.FormatRulePath(topi |
| | 12 | 495 | | var result = await ReadAsString(response).ConfigureAwait(false); |
| | 12 | 496 | | RuleProperties rule = RuleDescriptionExtensions.ParseFromContent(result); |
| | | 497 | | |
| | 12 | 498 | | return Response.FromValue(rule, response); |
| | | 499 | | } |
| | 4 | 500 | | catch (Exception ex) |
| | | 501 | | { |
| | 4 | 502 | | scope.Failed(ex); |
| | 4 | 503 | | throw; |
| | | 504 | | } |
| | 12 | 505 | | } |
| | | 506 | | |
| | | 507 | | #endregion |
| | | 508 | | |
| | | 509 | | #region GetRuntimeProperties |
| | | 510 | | /// <summary> |
| | | 511 | | /// Retrieves the runtime properties of a queue. |
| | | 512 | | /// </summary> |
| | | 513 | | /// |
| | | 514 | | /// <param name="name">The name of the queue relative to service bus namespace.</param> |
| | | 515 | | /// <param name="cancellationToken">An optional <see cref="CancellationToken"/> instance to signal the request t |
| | | 516 | | /// |
| | | 517 | | /// <returns><see cref="QueueRuntimeProperties"/> containing runtime properties about the queue.</returns> |
| | | 518 | | /// <exception cref="ArgumentException">Thrown if <paramref name="name"/> is null, white space empty or not in t |
| | | 519 | | /// <exception cref="ArgumentOutOfRangeException">The length of queue name is greater than 260.</exception> |
| | | 520 | | /// <exception cref="ServiceBusFailureReason.ServiceTimeout">The operation times out. The timeout period is init |
| | | 521 | | /// <exception cref="ServiceBusFailureReason.MessagingEntityNotFound">Queue with this name does not exist.</exce |
| | | 522 | | /// <exception cref="UnauthorizedAccessException">No sufficient permission to perform this operation. You should |
| | | 523 | | /// <exception cref="ServiceBusFailureReason.ServiceBusy">The server is busy. You should wait before you retry t |
| | | 524 | | /// <exception cref="ServiceBusException">An internal error or an unexpected exception occured.</exception> |
| | | 525 | | public virtual async Task<Response<QueueRuntimeProperties>> GetQueueRuntimePropertiesAsync( |
| | | 526 | | string name, |
| | | 527 | | CancellationToken cancellationToken = default) |
| | | 528 | | { |
| | 0 | 529 | | EntityNameFormatter.CheckValidQueueName(name); |
| | 0 | 530 | | using DiagnosticScope scope = _clientDiagnostics.CreateScope($"{nameof(ServiceBusManagementClient)}.GetQueue |
| | 0 | 531 | | scope.Start(); |
| | | 532 | | |
| | | 533 | | try |
| | | 534 | | { |
| | 0 | 535 | | Response response = await _httpRequestAndResponse.GetEntityAsync(name, null, true, cancellationToken).Co |
| | 0 | 536 | | var result = await ReadAsString(response).ConfigureAwait(false); |
| | 0 | 537 | | QueueRuntimeProperties runtimeProperties = QueueRuntimePropertiesExtensions.ParseFromContent(result); |
| | | 538 | | |
| | 0 | 539 | | return Response.FromValue(runtimeProperties, response); |
| | | 540 | | } |
| | 0 | 541 | | catch (Exception ex) |
| | | 542 | | { |
| | 0 | 543 | | scope.Failed(ex); |
| | 0 | 544 | | throw; |
| | | 545 | | } |
| | 0 | 546 | | } |
| | | 547 | | |
| | | 548 | | /// <summary> |
| | | 549 | | /// Retrieves the runtime properties of a topic. |
| | | 550 | | /// </summary> |
| | | 551 | | /// <param name="name">The name of the topic relative to service bus namespace.</param> |
| | | 552 | | /// <param name="cancellationToken">An optional <see cref="CancellationToken"/> instance to signal the request t |
| | | 553 | | /// |
| | | 554 | | /// <returns><see cref="TopicRuntimeProperties"/> containing runtime properties about the topic.</returns> |
| | | 555 | | /// <exception cref="ArgumentException">Thrown if <paramref name="name"/> is null, white space empty or not in t |
| | | 556 | | /// <exception cref="ArgumentOutOfRangeException">The length of topic name is greater than 260.</exception> |
| | | 557 | | /// <exception cref="ServiceBusFailureReason.ServiceTimeout">The operation times out. The timeout period is init |
| | | 558 | | /// <exception cref="ServiceBusFailureReason.MessagingEntityNotFound">Topic with this name does not exist.</exce |
| | | 559 | | /// <exception cref="UnauthorizedAccessException">No sufficient permission to perform this operation. You should |
| | | 560 | | /// <exception cref="ServiceBusFailureReason.ServiceBusy">The server is busy. You should wait before you retry t |
| | | 561 | | /// <exception cref="ServiceBusException">An internal error or an unexpected exception occured.</exception> |
| | | 562 | | public virtual async Task<Response<TopicRuntimeProperties>> GetTopicRuntimePropertiesAsync( |
| | | 563 | | string name, |
| | | 564 | | CancellationToken cancellationToken = default) |
| | | 565 | | { |
| | 4 | 566 | | EntityNameFormatter.CheckValidTopicName(name); |
| | 4 | 567 | | using DiagnosticScope scope = _clientDiagnostics.CreateScope($"{nameof(ServiceBusManagementClient)}.GetTopic |
| | 4 | 568 | | scope.Start(); |
| | | 569 | | |
| | | 570 | | try |
| | | 571 | | { |
| | 4 | 572 | | Response response = await _httpRequestAndResponse.GetEntityAsync(name, null, true, cancellationToken).Co |
| | 4 | 573 | | var result = await ReadAsString(response).ConfigureAwait(false); |
| | 4 | 574 | | TopicRuntimeProperties runtimeProperties = TopicRuntimePropertiesExtensions.ParseFromContent(result); |
| | | 575 | | |
| | 4 | 576 | | return Response.FromValue(runtimeProperties, response); |
| | | 577 | | } |
| | 0 | 578 | | catch (Exception ex) |
| | | 579 | | { |
| | 0 | 580 | | scope.Failed(ex); |
| | 0 | 581 | | throw; |
| | | 582 | | } |
| | 4 | 583 | | } |
| | | 584 | | |
| | | 585 | | /// <summary> |
| | | 586 | | /// Retrieves the runtime properties of a subscription. |
| | | 587 | | /// </summary> |
| | | 588 | | /// |
| | | 589 | | /// <param name="topicName">The name of the topic relative to service bus namespace.</param> |
| | | 590 | | /// <param name="subscriptionName">The subscription name.</param> |
| | | 591 | | /// <param name="cancellationToken">An optional <see cref="CancellationToken"/> instance to signal the request t |
| | | 592 | | /// |
| | | 593 | | /// <returns><see cref="SubscriptionRuntimeProperties"/> containing runtime properties about the subscription.</ |
| | | 594 | | /// <exception cref="ArgumentException">Thrown if <paramref name="topicName"/>, <paramref name="subscriptionName |
| | | 595 | | /// <exception cref="ArgumentOutOfRangeException">The length of topic name is greater than 260 or length of subs |
| | | 596 | | /// <exception cref="ServiceBusFailureReason.ServiceTimeout">The operation times out. The timeout period is init |
| | | 597 | | /// <exception cref="ServiceBusFailureReason.MessagingEntityNotFound">Topic or Subscription with this name does |
| | | 598 | | /// <exception cref="UnauthorizedAccessException">No sufficient permission to perform this operation. You should |
| | | 599 | | /// <exception cref="ServiceBusFailureReason.ServiceBusy">The server is busy. You should wait before you retry t |
| | | 600 | | /// <exception cref="ServiceBusException">An internal error or an unexpected exception occured.</exception> |
| | | 601 | | public virtual async Task<Response<SubscriptionRuntimeProperties>> GetSubscriptionRuntimePropertiesAsync( |
| | | 602 | | string topicName, |
| | | 603 | | string subscriptionName, |
| | | 604 | | CancellationToken cancellationToken = default) |
| | | 605 | | { |
| | 0 | 606 | | EntityNameFormatter.CheckValidTopicName(topicName); |
| | 0 | 607 | | EntityNameFormatter.CheckValidSubscriptionName(subscriptionName); |
| | 0 | 608 | | using DiagnosticScope scope = _clientDiagnostics.CreateScope($"{nameof(ServiceBusManagementClient)}.GetSubsc |
| | 0 | 609 | | scope.Start(); |
| | | 610 | | |
| | | 611 | | try |
| | | 612 | | { |
| | 0 | 613 | | Response response = await _httpRequestAndResponse.GetEntityAsync(EntityNameFormatter.FormatSubscriptionP |
| | 0 | 614 | | var result = await ReadAsString(response).ConfigureAwait(false); |
| | 0 | 615 | | SubscriptionRuntimeProperties runtimeProperties = SubscriptionRuntimePropertiesExtensions.ParseFromConte |
| | | 616 | | |
| | 0 | 617 | | return Response.FromValue(runtimeProperties, response); |
| | | 618 | | } |
| | 0 | 619 | | catch (Exception ex) |
| | | 620 | | { |
| | 0 | 621 | | scope.Failed(ex); |
| | 0 | 622 | | throw; |
| | | 623 | | } |
| | 0 | 624 | | } |
| | | 625 | | |
| | | 626 | | #endregion |
| | | 627 | | |
| | | 628 | | #region GetEntities |
| | | 629 | | /// <summary> |
| | | 630 | | /// Retrieves the list of queues present in the namespace. |
| | | 631 | | /// </summary> |
| | | 632 | | /// |
| | | 633 | | /// <param name="cancellationToken">An optional <see cref="CancellationToken"/> instance to signal the request t |
| | | 634 | | /// |
| | | 635 | | /// <returns>An <see cref="AsyncPageable{T}"/> describing the queues.</returns> |
| | | 636 | | /// <remarks>Maximum value allowed is 100 per page.</remarks> |
| | | 637 | | /// <exception cref="ArgumentOutOfRangeException">If the parameters are out of range.</exception> |
| | | 638 | | /// <exception cref="ServiceBusFailureReason.ServiceTimeout">The operation times out. The timeout period is init |
| | | 639 | | /// <exception cref="UnauthorizedAccessException">No sufficient permission to perform this operation. You should |
| | | 640 | | /// <exception cref="ServiceBusFailureReason.ServiceBusy">The server is busy. You should wait before you retry t |
| | | 641 | | /// <exception cref="ServiceBusException">An internal error or an unexpected exception occured.</exception> |
| | | 642 | | public virtual AsyncPageable<QueueProperties> GetQueuesAsync(CancellationToken cancellationToken = default) |
| | | 643 | | { |
| | 4 | 644 | | using DiagnosticScope scope = _clientDiagnostics.CreateScope($"{nameof(ServiceBusManagementClient)}.GetQueue |
| | 4 | 645 | | scope.Start(); |
| | | 646 | | |
| | | 647 | | try |
| | | 648 | | { |
| | 8 | 649 | | return PageResponseEnumerator.CreateAsyncEnumerable(nextSkip => _httpRequestAndResponse.GetEntitiesPageA |
| | 8 | 650 | | QueuesPath, |
| | 8 | 651 | | nextSkip, |
| | 12 | 652 | | rawResult => QueuePropertiesExtensions.ParseCollectionFromContent(rawResult), |
| | 8 | 653 | | cancellationToken)); |
| | | 654 | | } |
| | 0 | 655 | | catch (Exception ex) |
| | | 656 | | { |
| | 0 | 657 | | scope.Failed(ex); |
| | 0 | 658 | | throw; |
| | | 659 | | } |
| | 4 | 660 | | } |
| | | 661 | | |
| | | 662 | | /// <summary> |
| | | 663 | | /// Retrieves the list of topics present in the namespace. |
| | | 664 | | /// </summary> |
| | | 665 | | /// |
| | | 666 | | /// <param name="cancellationToken">An optional <see cref="CancellationToken"/> instance to signal the request t |
| | | 667 | | /// |
| | | 668 | | /// <returns>An <see cref="AsyncPageable{T}"/> describing the topics.</returns> |
| | | 669 | | /// <remarks>Maximum value allowed is 100 per page.</remarks> |
| | | 670 | | /// <exception cref="ArgumentOutOfRangeException">If the parameters are out of range.</exception> |
| | | 671 | | /// <exception cref="ServiceBusFailureReason.ServiceTimeout">The operation times out. The timeout period is init |
| | | 672 | | /// <exception cref="UnauthorizedAccessException">No sufficient permission to perform this operation. You should |
| | | 673 | | /// <exception cref="ServiceBusFailureReason.ServiceBusy">The server is busy. You should wait before you retry t |
| | | 674 | | /// <exception cref="ServiceBusException">An internal error or an unexpected exception occured.</exception> |
| | | 675 | | public virtual AsyncPageable<TopicProperties> GetTopicsAsync(CancellationToken cancellationToken = default) |
| | | 676 | | { |
| | 4 | 677 | | using DiagnosticScope scope = _clientDiagnostics.CreateScope($"{nameof(ServiceBusManagementClient)}.GetTopic |
| | 4 | 678 | | scope.Start(); |
| | | 679 | | |
| | | 680 | | try |
| | | 681 | | { |
| | 8 | 682 | | return PageResponseEnumerator.CreateAsyncEnumerable(nextSkip => _httpRequestAndResponse.GetEntitiesPageA |
| | 8 | 683 | | TopicsPath, |
| | 8 | 684 | | nextSkip, |
| | 12 | 685 | | rawResult => TopicPropertiesExtensions.ParseCollectionFromContent(rawResult), |
| | 8 | 686 | | cancellationToken)); |
| | | 687 | | } |
| | 0 | 688 | | catch (Exception ex) |
| | | 689 | | { |
| | 0 | 690 | | scope.Failed(ex); |
| | 0 | 691 | | throw; |
| | | 692 | | } |
| | 4 | 693 | | } |
| | | 694 | | |
| | | 695 | | /// <summary> |
| | | 696 | | /// Retrieves the list of subscriptions present in the topic. |
| | | 697 | | /// </summary> |
| | | 698 | | /// |
| | | 699 | | /// <param name="topicName">The topic name under which all the subscriptions need to be retrieved.</param> |
| | | 700 | | /// <param name="cancellationToken">An optional <see cref="CancellationToken"/> instance to signal the request t |
| | | 701 | | /// |
| | | 702 | | /// <returns>An <see cref="AsyncPageable{T}"/> describing the subscriptions.</returns> |
| | | 703 | | /// <remarks>Maximum value allowed is 100 per page.</remarks> |
| | | 704 | | /// <exception cref="ArgumentOutOfRangeException">If the parameters are out of range.</exception> |
| | | 705 | | /// <exception cref="ServiceBusFailureReason.ServiceTimeout">The operation times out. The timeout period is init |
| | | 706 | | /// <exception cref="UnauthorizedAccessException">No sufficient permission to perform this operation. You should |
| | | 707 | | /// <exception cref="ServiceBusFailureReason.ServiceBusy">The server is busy. You should wait before you retry t |
| | | 708 | | /// <exception cref="ServiceBusException">An internal error or an unexpected exception occured.</exception> |
| | | 709 | | public virtual AsyncPageable<SubscriptionProperties> GetSubscriptionsAsync( |
| | | 710 | | string topicName, |
| | | 711 | | CancellationToken cancellationToken = default) |
| | | 712 | | { |
| | 4 | 713 | | EntityNameFormatter.CheckValidTopicName(topicName); |
| | 4 | 714 | | using DiagnosticScope scope = _clientDiagnostics.CreateScope($"{nameof(ServiceBusManagementClient)}.GetSubsc |
| | 4 | 715 | | scope.Start(); |
| | | 716 | | try |
| | | 717 | | { |
| | 8 | 718 | | return PageResponseEnumerator.CreateAsyncEnumerable(nextSkip => _httpRequestAndResponse.GetEntitiesPageA |
| | 8 | 719 | | string.Format(CultureInfo.CurrentCulture, SubscriptionsPath, topicName), |
| | 8 | 720 | | nextSkip, |
| | 12 | 721 | | rawResult => SubscriptionPropertiesExtensions.ParseCollectionFromContent(topicName, rawResult), |
| | 8 | 722 | | cancellationToken)); |
| | | 723 | | } |
| | 0 | 724 | | catch (Exception ex) |
| | | 725 | | { |
| | 0 | 726 | | scope.Failed(ex); |
| | 0 | 727 | | throw; |
| | | 728 | | } |
| | 4 | 729 | | } |
| | | 730 | | |
| | | 731 | | /// <summary> |
| | | 732 | | /// Retrieves the list of rules for a given subscription in a topic. |
| | | 733 | | /// </summary> |
| | | 734 | | /// |
| | | 735 | | /// <param name="topicName">The topic name.</param> |
| | | 736 | | /// <param name="subscriptionName"> The subscription for which all the rules need to be retrieved.</param> |
| | | 737 | | /// <param name="cancellationToken">An optional <see cref="CancellationToken"/> instance to signal the request t |
| | | 738 | | /// |
| | | 739 | | /// <returns>An <see cref="AsyncPageable{T}"/> describing the rules.</returns> |
| | | 740 | | /// <remarks>Maximum value allowed is 100 per page.</remarks> |
| | | 741 | | /// <exception cref="ArgumentOutOfRangeException">If the parameters are out of range.</exception> |
| | | 742 | | /// <exception cref="ServiceBusFailureReason.ServiceTimeout">The operation times out. The timeout period is init |
| | | 743 | | /// <exception cref="UnauthorizedAccessException">No sufficient permission to perform this operation. You should |
| | | 744 | | /// <exception cref="ServiceBusFailureReason.ServiceBusy">The server is busy. You should wait before you retry t |
| | | 745 | | /// <exception cref="ServiceBusException">An internal error or an unexpected exception occured.</exception> |
| | | 746 | | public virtual AsyncPageable<RuleProperties> GetRulesAsync( |
| | | 747 | | string topicName, |
| | | 748 | | string subscriptionName, |
| | | 749 | | CancellationToken cancellationToken = default) |
| | | 750 | | { |
| | 4 | 751 | | EntityNameFormatter.CheckValidTopicName(topicName); |
| | 4 | 752 | | EntityNameFormatter.CheckValidSubscriptionName(subscriptionName); |
| | 4 | 753 | | using DiagnosticScope scope = _clientDiagnostics.CreateScope($"{nameof(ServiceBusManagementClient)}.GetRules |
| | 4 | 754 | | scope.Start(); |
| | | 755 | | |
| | | 756 | | try |
| | | 757 | | { |
| | 8 | 758 | | return PageResponseEnumerator.CreateAsyncEnumerable(nextSkip => _httpRequestAndResponse.GetEntitiesPageA |
| | 8 | 759 | | string.Format(CultureInfo.CurrentCulture, RulesPath, topicName, subscriptionName), |
| | 8 | 760 | | nextSkip, |
| | 12 | 761 | | rawResult => RuleDescriptionExtensions.ParseCollectionFromContent(rawResult), |
| | 8 | 762 | | cancellationToken)); |
| | | 763 | | } |
| | 0 | 764 | | catch (Exception ex) |
| | | 765 | | { |
| | 0 | 766 | | scope.Failed(ex); |
| | 0 | 767 | | throw; |
| | | 768 | | } |
| | 4 | 769 | | } |
| | | 770 | | |
| | | 771 | | #endregion |
| | | 772 | | |
| | | 773 | | #region GetEntitiesRuntimeProperties |
| | | 774 | | /// <summary> |
| | | 775 | | /// Retrieves the list of runtime properties for queues present in the namespace. |
| | | 776 | | /// </summary> |
| | | 777 | | /// |
| | | 778 | | /// <param name="cancellationToken">An optional <see cref="CancellationToken"/> instance to signal the request t |
| | | 779 | | /// |
| | | 780 | | /// <returns>An <see cref="AsyncPageable{T}"/> describing the queues runtime properties.</returns> |
| | | 781 | | /// <remarks>Maximum value allowed is 100 per page.</remarks> |
| | | 782 | | /// <exception cref="ArgumentOutOfRangeException">If the parameters are out of range.</exception> |
| | | 783 | | /// <exception cref="ServiceBusFailureReason.ServiceTimeout">The operation times out. The timeout period is init |
| | | 784 | | /// <exception cref="UnauthorizedAccessException">No sufficient permission to perform this operation. You should |
| | | 785 | | /// <exception cref="ServiceBusFailureReason.ServiceBusy">The server is busy. You should wait before you retry t |
| | | 786 | | /// <exception cref="ServiceBusException">An internal error or an unexpected exception occured.</exception> |
| | | 787 | | public virtual AsyncPageable<QueueRuntimeProperties> GetQueuesRuntimePropertiesAsync(CancellationToken cancellat |
| | | 788 | | { |
| | 0 | 789 | | using DiagnosticScope scope = _clientDiagnostics.CreateScope($"{nameof(ServiceBusManagementClient)}.GetQueue |
| | 0 | 790 | | scope.Start(); |
| | | 791 | | |
| | | 792 | | try |
| | | 793 | | { |
| | 0 | 794 | | return PageResponseEnumerator.CreateAsyncEnumerable(nextSkip => _httpRequestAndResponse.GetEntitiesPageA |
| | 0 | 795 | | QueuesPath, |
| | 0 | 796 | | nextSkip, |
| | 0 | 797 | | rawResult => QueueRuntimePropertiesExtensions.ParseCollectionFromContent(rawResult), |
| | 0 | 798 | | cancellationToken)); |
| | | 799 | | } |
| | 0 | 800 | | catch (Exception ex) |
| | | 801 | | { |
| | 0 | 802 | | scope.Failed(ex); |
| | 0 | 803 | | throw; |
| | | 804 | | } |
| | 0 | 805 | | } |
| | | 806 | | |
| | | 807 | | /// <summary> |
| | | 808 | | /// Retrieves the list of runtime properties for topics present in the namespace. |
| | | 809 | | /// </summary> |
| | | 810 | | /// |
| | | 811 | | /// <param name="cancellationToken">An optional <see cref="CancellationToken"/> instance to signal the request t |
| | | 812 | | /// |
| | | 813 | | /// <returns>An <see cref="AsyncPageable{T}"/> describing the topics runtime properties.</returns> |
| | | 814 | | /// <remarks>Maximum value allowed is 100 per page.</remarks> |
| | | 815 | | /// <exception cref="ArgumentOutOfRangeException">If the parameters are out of range.</exception> |
| | | 816 | | /// <exception cref="ServiceBusFailureReason.ServiceTimeout">The operation times out. The timeout period is init |
| | | 817 | | /// <exception cref="UnauthorizedAccessException">No sufficient permission to perform this operation. You should |
| | | 818 | | /// <exception cref="ServiceBusFailureReason.ServiceBusy">The server is busy. You should wait before you retry t |
| | | 819 | | /// <exception cref="ServiceBusException">An internal error or an unexpected exception occured.</exception> |
| | | 820 | | public virtual AsyncPageable<TopicRuntimeProperties> GetTopicsRuntimePropertiesAsync(CancellationToken cancellat |
| | | 821 | | { |
| | 4 | 822 | | using DiagnosticScope scope = _clientDiagnostics.CreateScope($"{nameof(ServiceBusManagementClient)}.GetTopic |
| | 4 | 823 | | scope.Start(); |
| | | 824 | | try |
| | | 825 | | { |
| | 8 | 826 | | return PageResponseEnumerator.CreateAsyncEnumerable(nextSkip => _httpRequestAndResponse.GetEntitiesPageA |
| | 8 | 827 | | TopicsPath, |
| | 8 | 828 | | nextSkip, |
| | 12 | 829 | | rawResult => TopicRuntimePropertiesExtensions.ParseCollectionFromContent(rawResult), |
| | 8 | 830 | | cancellationToken)); |
| | | 831 | | } |
| | 0 | 832 | | catch (Exception ex) |
| | | 833 | | { |
| | 0 | 834 | | scope.Failed(ex); |
| | 0 | 835 | | throw; |
| | | 836 | | } |
| | 4 | 837 | | } |
| | | 838 | | /// <summary> |
| | | 839 | | /// Retrieves the list of runtime properties for subscriptions present in the namespace. |
| | | 840 | | /// </summary> |
| | | 841 | | /// |
| | | 842 | | /// <param name="topicName">The name of the topic relative to service bus namespace.</param> |
| | | 843 | | /// <param name="cancellationToken">An optional <see cref="CancellationToken"/> instance to signal the request t |
| | | 844 | | /// |
| | | 845 | | /// <returns>An <see cref="AsyncPageable{T}"/> describing the subscriptions runtime properties.</returns> |
| | | 846 | | /// <remarks>Maximum value allowed is 100 per page.</remarks> |
| | | 847 | | /// <exception cref="ArgumentOutOfRangeException">If the parameters are out of range.</exception> |
| | | 848 | | /// <exception cref="ServiceBusFailureReason.ServiceTimeout">The operation times out. The timeout period is init |
| | | 849 | | /// <exception cref="UnauthorizedAccessException">No sufficient permission to perform this operation. You should |
| | | 850 | | /// <exception cref="ServiceBusFailureReason.ServiceBusy">The server is busy. You should wait before you retry t |
| | | 851 | | /// <exception cref="ServiceBusException">An internal error or an unexpected exception occured.</exception> |
| | | 852 | | public virtual AsyncPageable<SubscriptionRuntimeProperties> GetSubscriptionsRuntimePropertiesAsync( |
| | | 853 | | string topicName, |
| | | 854 | | CancellationToken cancellationToken = default) |
| | | 855 | | { |
| | 0 | 856 | | EntityNameFormatter.CheckValidTopicName(topicName); |
| | 0 | 857 | | using DiagnosticScope scope = _clientDiagnostics.CreateScope($"{nameof(ServiceBusManagementClient)}.GetSubsc |
| | 0 | 858 | | scope.Start(); |
| | | 859 | | try |
| | | 860 | | { |
| | 0 | 861 | | return PageResponseEnumerator.CreateAsyncEnumerable(nextSkip => _httpRequestAndResponse.GetEntitiesPageA |
| | 0 | 862 | | string.Format(CultureInfo.CurrentCulture, SubscriptionsPath, topicName), |
| | 0 | 863 | | nextSkip, |
| | 0 | 864 | | rawResult => SubscriptionRuntimePropertiesExtensions.ParseCollectionFromContent(topicName, rawResult |
| | 0 | 865 | | cancellationToken)); |
| | | 866 | | } |
| | 0 | 867 | | catch (Exception ex) |
| | | 868 | | { |
| | 0 | 869 | | scope.Failed(ex); |
| | 0 | 870 | | throw; |
| | | 871 | | } |
| | 0 | 872 | | } |
| | | 873 | | |
| | | 874 | | #endregion |
| | | 875 | | |
| | | 876 | | #region CreateEntity |
| | | 877 | | |
| | | 878 | | /// <summary> |
| | | 879 | | /// Creates a new queue in the service namespace with the given name. |
| | | 880 | | /// </summary> |
| | | 881 | | /// |
| | | 882 | | /// <param name="name">The name of the queue relative to the service namespace base address.</param> |
| | | 883 | | /// <param name="cancellationToken">An optional <see cref="CancellationToken"/> instance to signal the request t |
| | | 884 | | /// |
| | | 885 | | /// <remarks>Throws if a queue already exists. <see cref="QueueProperties"/> for default values of queue propert |
| | | 886 | | /// <returns>The <see cref="QueueProperties"/> of the newly created queue.</returns> |
| | | 887 | | /// <exception cref="ArgumentNullException">Queue name is null or empty.</exception> |
| | | 888 | | /// <exception cref="ArgumentOutOfRangeException">The length of <paramref name="name"/> is greater than 260 char |
| | | 889 | | /// <exception cref="ServiceBusFailureReason.MessagingEntityAlreadyExists">An entity with the same name exists u |
| | | 890 | | /// <exception cref="ServiceBusFailureReason.ServiceTimeout">The operation times out. The timeout period is init |
| | | 891 | | /// <exception cref="UnauthorizedAccessException">No sufficient permission to perform this operation. You should |
| | | 892 | | /// <exception cref="ServiceBusFailureReason.QuotaExceeded">Either the specified size in the description is not |
| | | 893 | | /// <exception cref="ServiceBusFailureReason.ServiceBusy">The server is busy. You should wait before you retry t |
| | | 894 | | /// <exception cref="ServiceBusException">An internal error or unexpected exception occurs.</exception> |
| | | 895 | | public virtual async Task<Response<QueueProperties>> CreateQueueAsync( |
| | | 896 | | string name, |
| | | 897 | | CancellationToken cancellationToken = default) => |
| | 12 | 898 | | await CreateQueueAsync( |
| | 12 | 899 | | new CreateQueueOptions(name), |
| | 12 | 900 | | cancellationToken).ConfigureAwait(false); |
| | | 901 | | |
| | | 902 | | /// <summary> |
| | | 903 | | /// Creates a new queue in the service namespace with the given name. |
| | | 904 | | /// </summary> |
| | | 905 | | /// <param name="options">A <see cref="CreateQueueOptions"/> object describing the attributes with which the new |
| | | 906 | | /// <param name="cancellationToken">An optional <see cref="CancellationToken"/> instance to signal the request t |
| | | 907 | | /// |
| | | 908 | | /// <remarks>Throws if a queue already exists.</remarks> |
| | | 909 | | /// <returns>The <see cref="QueueProperties"/> of the newly created queue.</returns> |
| | | 910 | | /// <exception cref="ArgumentNullException">Queue name is null or empty.</exception> |
| | | 911 | | /// <exception cref="ServiceBusFailureReason.MessagingEntityAlreadyExists">An entity with the same name exists u |
| | | 912 | | /// <exception cref="ServiceBusFailureReason.ServiceTimeout">The operation times out. The timeout period is init |
| | | 913 | | /// <exception cref="UnauthorizedAccessException">No sufficient permission to perform this operation. You should |
| | | 914 | | /// <exception cref="ServiceBusFailureReason.QuotaExceeded">Either the specified size in the description is not |
| | | 915 | | /// <exception cref="ServiceBusFailureReason.ServiceBusy">The server is busy. You should wait before you retry t |
| | | 916 | | /// <exception cref="ServiceBusException">An internal error or unexpected exception occurs.</exception> |
| | | 917 | | public virtual async Task<Response<QueueProperties>> CreateQueueAsync( |
| | | 918 | | CreateQueueOptions options, |
| | | 919 | | CancellationToken cancellationToken = default) |
| | | 920 | | { |
| | 20 | 921 | | Argument.AssertNotNull(options, nameof(options)); |
| | 20 | 922 | | using DiagnosticScope scope = _clientDiagnostics.CreateScope($"{nameof(ServiceBusManagementClient)}.CreateQu |
| | 20 | 923 | | scope.Start(); |
| | | 924 | | try |
| | | 925 | | { |
| | 20 | 926 | | var queue = new QueueProperties(options); |
| | 20 | 927 | | queue.NormalizeDescription(_fullyQualifiedNamespace); |
| | 20 | 928 | | var atomRequest = queue.Serialize().ToString(); |
| | 20 | 929 | | Response response = await _httpRequestAndResponse.PutEntityAsync( |
| | 20 | 930 | | queue.Name, |
| | 20 | 931 | | atomRequest, |
| | 20 | 932 | | false, |
| | 20 | 933 | | queue.ForwardTo, |
| | 20 | 934 | | queue.ForwardDeadLetteredMessagesTo, |
| | 20 | 935 | | cancellationToken).ConfigureAwait(false); |
| | | 936 | | |
| | 16 | 937 | | var result = await ReadAsString(response).ConfigureAwait(false); |
| | 16 | 938 | | QueueProperties description = QueuePropertiesExtensions.ParseFromContent(result); |
| | 16 | 939 | | return Response.FromValue(description, response); |
| | | 940 | | } |
| | 4 | 941 | | catch (Exception ex) |
| | | 942 | | { |
| | 4 | 943 | | scope.Failed(ex); |
| | 4 | 944 | | throw; |
| | | 945 | | } |
| | 16 | 946 | | } |
| | | 947 | | |
| | | 948 | | /// <summary> |
| | | 949 | | /// Creates a new topic in the service namespace with the given name. |
| | | 950 | | /// </summary> |
| | | 951 | | /// |
| | | 952 | | /// <param name="name">The name of the topic relative to the service namespace base address.</param> |
| | | 953 | | /// <param name="cancellationToken">An optional <see cref="CancellationToken"/> instance to signal the request t |
| | | 954 | | /// |
| | | 955 | | /// <remarks>Throws if a topic already exists. <see cref="TopicProperties"/> for default values of topic propert |
| | | 956 | | /// <returns>The <see cref="TopicProperties"/> of the newly created topic.</returns> |
| | | 957 | | /// <exception cref="ArgumentNullException">Topic name is null or empty.</exception> |
| | | 958 | | /// <exception cref="ArgumentOutOfRangeException">The length of <paramref name="name"/> is greater than 260 char |
| | | 959 | | /// <exception cref="ServiceBusFailureReason.MessagingEntityAlreadyExists">A topic with the same name exists und |
| | | 960 | | /// <exception cref="ServiceBusFailureReason.ServiceTimeout">The operation times out. The timeout period is init |
| | | 961 | | /// <exception cref="UnauthorizedAccessException">No sufficient permission to perform this operation. You should |
| | | 962 | | /// <exception cref="ServiceBusFailureReason.QuotaExceeded">Either the specified size in the description is not |
| | | 963 | | /// <exception cref="ServiceBusFailureReason.ServiceBusy">The server is busy. You should wait before you retry t |
| | | 964 | | /// <exception cref="ServiceBusException">An internal error or unexpected exception occurs.</exception> |
| | | 965 | | public virtual async Task<Response<TopicProperties>> CreateTopicAsync( |
| | | 966 | | string name, |
| | | 967 | | CancellationToken cancellationToken = default) => |
| | 32 | 968 | | await CreateTopicAsync( |
| | 32 | 969 | | new CreateTopicOptions(name), |
| | 32 | 970 | | cancellationToken).ConfigureAwait(false); |
| | | 971 | | |
| | | 972 | | /// <summary> |
| | | 973 | | /// Creates a new topic in the service namespace with the given name. |
| | | 974 | | /// </summary> |
| | | 975 | | /// |
| | | 976 | | /// <param name="options">A <see cref="TopicProperties"/> object describing the attributes with which the new to |
| | | 977 | | /// <param name="cancellationToken">An optional <see cref="CancellationToken"/> instance to signal the request t |
| | | 978 | | /// |
| | | 979 | | /// <remarks>Throws if a topic already exists. <see cref="TopicProperties"/> for default values of topic propert |
| | | 980 | | /// <returns>The <see cref="TopicProperties"/> of the newly created topic.</returns> |
| | | 981 | | /// <exception cref="ArgumentNullException">Topic description is null.</exception> |
| | | 982 | | /// <exception cref="ServiceBusFailureReason.MessagingEntityAlreadyExists">A topic with the same name exists und |
| | | 983 | | /// <exception cref="ServiceBusFailureReason.ServiceTimeout">The operation times out. The timeout period is init |
| | | 984 | | /// <exception cref="UnauthorizedAccessException">No sufficient permission to perform this operation. You should |
| | | 985 | | /// <exception cref="ServiceBusFailureReason.QuotaExceeded">Either the specified size in the description is not |
| | | 986 | | /// <exception cref="ServiceBusFailureReason.ServiceBusy">The server is busy. You should wait before you retry t |
| | | 987 | | /// <exception cref="ServiceBusException">An internal error or unexpected exception occurs.</exception> |
| | | 988 | | public virtual async Task<Response<TopicProperties>> CreateTopicAsync( |
| | | 989 | | CreateTopicOptions options, |
| | | 990 | | CancellationToken cancellationToken = default) |
| | | 991 | | { |
| | 40 | 992 | | Argument.AssertNotNull(options, nameof(options)); |
| | 40 | 993 | | using DiagnosticScope scope = _clientDiagnostics.CreateScope($"{nameof(ServiceBusManagementClient)}.CreateTo |
| | 40 | 994 | | scope.Start(); |
| | | 995 | | |
| | | 996 | | try |
| | | 997 | | { |
| | 40 | 998 | | var topic = new TopicProperties(options); |
| | 40 | 999 | | var atomRequest = topic.Serialize().ToString(); |
| | | 1000 | | |
| | 40 | 1001 | | Response response = await _httpRequestAndResponse.PutEntityAsync( |
| | 40 | 1002 | | topic.Name, |
| | 40 | 1003 | | atomRequest, |
| | 40 | 1004 | | false, |
| | 40 | 1005 | | null, |
| | 40 | 1006 | | null, |
| | 40 | 1007 | | cancellationToken).ConfigureAwait(false); |
| | 36 | 1008 | | var result = await ReadAsString(response).ConfigureAwait(false); |
| | 36 | 1009 | | TopicProperties description = TopicPropertiesExtensions.ParseFromContent(result); |
| | | 1010 | | |
| | 36 | 1011 | | return Response.FromValue(description, response); |
| | | 1012 | | } |
| | 4 | 1013 | | catch (Exception ex) |
| | | 1014 | | { |
| | 4 | 1015 | | scope.Failed(ex); |
| | 4 | 1016 | | throw; |
| | | 1017 | | } |
| | 36 | 1018 | | } |
| | | 1019 | | |
| | | 1020 | | /// <summary> |
| | | 1021 | | /// Creates a new subscription within a topic in the service namespace with the given name. |
| | | 1022 | | /// </summary> |
| | | 1023 | | /// |
| | | 1024 | | /// <param name="topicName">The name of the topic relative to the service namespace base address.</param> |
| | | 1025 | | /// <param name="subscriptionName">The name of the subscription.</param> |
| | | 1026 | | /// <param name="cancellationToken">An optional <see cref="CancellationToken"/> instance to signal the request t |
| | | 1027 | | /// |
| | | 1028 | | /// <remarks>Throws if a subscription already exists. <see cref="SubscriptionProperties"/> for default values of |
| | | 1029 | | /// By default, A "pass-through" filter is created for this subscription, which means it will allow all messages |
| | | 1030 | | /// <see cref="CreateSubscriptionAsync(CreateSubscriptionOptions, CreateRuleOptions, CancellationToken)"/> for c |
| | | 1031 | | /// <returns>The <see cref="SubscriptionProperties"/> of the newly created subscription.</returns> |
| | | 1032 | | /// <exception cref="ArgumentNullException">Topic name or subscription name is null or empty.</exception> |
| | | 1033 | | /// <exception cref="ArgumentOutOfRangeException">The length of <paramref name="topicName"/> is greater than 260 |
| | | 1034 | | /// <exception cref="ServiceBusFailureReason.MessagingEntityAlreadyExists">A subscription with the same name exi |
| | | 1035 | | /// <exception cref="ServiceBusFailureReason.ServiceTimeout">The operation times out. The timeout period is init |
| | | 1036 | | /// <exception cref="UnauthorizedAccessException">No sufficient permission to perform this operation. You should |
| | | 1037 | | /// <exception cref="ServiceBusFailureReason.QuotaExceeded">Either the specified size in the description is not |
| | | 1038 | | /// <exception cref="ServiceBusFailureReason.ServiceBusy">The server is busy. You should wait before you retry t |
| | | 1039 | | /// <exception cref="ServiceBusException">An internal error or unexpected exception occurs.</exception> |
| | | 1040 | | public virtual async Task<Response<SubscriptionProperties>> CreateSubscriptionAsync( |
| | | 1041 | | string topicName, |
| | | 1042 | | string subscriptionName, |
| | | 1043 | | CancellationToken cancellationToken = default) => |
| | 20 | 1044 | | await CreateSubscriptionAsync( |
| | 20 | 1045 | | new CreateSubscriptionOptions(topicName, subscriptionName), |
| | 20 | 1046 | | cancellationToken).ConfigureAwait(false); |
| | | 1047 | | |
| | | 1048 | | /// <summary> |
| | | 1049 | | /// Creates a new subscription within a topic in the service namespace with the given name. |
| | | 1050 | | /// </summary> |
| | | 1051 | | /// |
| | | 1052 | | /// <param name="options">A <see cref="SubscriptionProperties"/> object describing the attributes with which the |
| | | 1053 | | /// <param name="cancellationToken">An optional <see cref="CancellationToken"/> instance to signal the request t |
| | | 1054 | | /// |
| | | 1055 | | /// <remarks>Throws if a subscription already exists. |
| | | 1056 | | /// Be default, A "pass-through" filter is created for this subscription, which means it will allow all messages |
| | | 1057 | | /// <see cref="CreateSubscriptionAsync(CreateSubscriptionOptions, CreateRuleOptions, CancellationToken)"/> for c |
| | | 1058 | | /// <returns>The <see cref="SubscriptionProperties"/> of the newly created subscription.</returns> |
| | | 1059 | | /// <exception cref="ArgumentNullException">Subscription description is null.</exception> |
| | | 1060 | | /// <exception cref="ServiceBusFailureReason.MessagingEntityAlreadyExists">A subscription with the same name exi |
| | | 1061 | | /// <exception cref="ServiceBusFailureReason.ServiceTimeout">The operation times out. The timeout period is init |
| | | 1062 | | /// <exception cref="UnauthorizedAccessException">No sufficient permission to perform this operation. You should |
| | | 1063 | | /// <exception cref="ServiceBusFailureReason.QuotaExceeded">Either the specified size in the description is not |
| | | 1064 | | /// <exception cref="ServiceBusFailureReason.ServiceBusy">The server is busy. You should wait before you retry t |
| | | 1065 | | /// <exception cref="ServiceBusException">An internal error or unexpected exception occurs.</exception> |
| | | 1066 | | public virtual Task<Response<SubscriptionProperties>> CreateSubscriptionAsync( |
| | | 1067 | | CreateSubscriptionOptions options, |
| | | 1068 | | CancellationToken cancellationToken = default) |
| | | 1069 | | { |
| | 24 | 1070 | | options = options ?? throw new ArgumentNullException(nameof(options)); |
| | 24 | 1071 | | return CreateSubscriptionAsync(options, new CreateRuleOptions(), cancellationToken); |
| | | 1072 | | } |
| | | 1073 | | |
| | | 1074 | | /// <summary> |
| | | 1075 | | /// Creates a new subscription within a topic with the provided default rule. |
| | | 1076 | | /// </summary> |
| | | 1077 | | /// |
| | | 1078 | | /// <param name="options">A <see cref="SubscriptionProperties"/> object describing the attributes with which the |
| | | 1079 | | /// <param name="rule"> A <see cref="RuleProperties"/> object describing the default rule. If null, then pass-th |
| | | 1080 | | /// <param name="cancellationToken">An optional <see cref="CancellationToken"/> instance to signal the request t |
| | | 1081 | | /// |
| | | 1082 | | /// <remarks>Throws if a subscription already exists. </remarks> |
| | | 1083 | | /// <returns>The <see cref="SubscriptionProperties"/> of the newly created subscription.</returns> |
| | | 1084 | | /// <exception cref="ArgumentNullException">Subscription description is null.</exception> |
| | | 1085 | | /// <exception cref="ServiceBusFailureReason.MessagingEntityAlreadyExists">A subscription with the same name exi |
| | | 1086 | | /// <exception cref="ServiceBusFailureReason.ServiceTimeout">The operation times out. The timeout period is init |
| | | 1087 | | /// <exception cref="UnauthorizedAccessException">No sufficient permission to perform this operation. You should |
| | | 1088 | | /// <exception cref="ServiceBusFailureReason.QuotaExceeded">Either the specified size in the description is not |
| | | 1089 | | /// <exception cref="ServiceBusFailureReason.ServiceBusy">The server is busy. You should wait before you retry t |
| | | 1090 | | /// <exception cref="ServiceBusException">An internal error or unexpected exception occurs.</exception> |
| | | 1091 | | public virtual async Task<Response<SubscriptionProperties>> CreateSubscriptionAsync( |
| | | 1092 | | CreateSubscriptionOptions options, |
| | | 1093 | | CreateRuleOptions rule, |
| | | 1094 | | CancellationToken cancellationToken = default) |
| | | 1095 | | { |
| | 28 | 1096 | | options = options ?? throw new ArgumentNullException(nameof(options)); |
| | 28 | 1097 | | using DiagnosticScope scope = _clientDiagnostics.CreateScope($"{nameof(ServiceBusManagementClient)}.CreateSu |
| | 28 | 1098 | | scope.Start(); |
| | | 1099 | | |
| | | 1100 | | try |
| | | 1101 | | { |
| | 28 | 1102 | | var subscription = new SubscriptionProperties(options); |
| | 28 | 1103 | | subscription.NormalizeDescription(_fullyQualifiedNamespace); |
| | 28 | 1104 | | subscription.Rule = new RuleProperties(rule); |
| | 28 | 1105 | | var atomRequest = subscription.Serialize().ToString(); |
| | | 1106 | | |
| | 28 | 1107 | | Response response = await _httpRequestAndResponse.PutEntityAsync( |
| | 28 | 1108 | | EntityNameFormatter.FormatSubscriptionPath(subscription.TopicName, subscription.SubscriptionName), |
| | 28 | 1109 | | atomRequest, |
| | 28 | 1110 | | false, |
| | 28 | 1111 | | subscription.ForwardTo, |
| | 28 | 1112 | | subscription.ForwardDeadLetteredMessagesTo, |
| | 28 | 1113 | | cancellationToken).ConfigureAwait(false); |
| | 24 | 1114 | | var result = await ReadAsString(response).ConfigureAwait(false); |
| | 24 | 1115 | | SubscriptionProperties description = SubscriptionPropertiesExtensions.ParseFromContent(subscription.Topi |
| | | 1116 | | |
| | 24 | 1117 | | return Response.FromValue(description, response); |
| | | 1118 | | } |
| | 4 | 1119 | | catch (Exception ex) |
| | | 1120 | | { |
| | 4 | 1121 | | scope.Failed(ex); |
| | 4 | 1122 | | throw; |
| | | 1123 | | } |
| | 24 | 1124 | | } |
| | | 1125 | | |
| | | 1126 | | /// <summary> |
| | | 1127 | | /// Adds a new rule to the subscription under given topic. |
| | | 1128 | | /// </summary> |
| | | 1129 | | /// |
| | | 1130 | | /// <param name="topicName">The topic name relative to the service namespace base address.</param> |
| | | 1131 | | /// <param name="subscriptionName">The name of the subscription.</param> |
| | | 1132 | | /// <param name="options">A <see cref="CreateRuleOptions"/> object describing the attributes with which the mess |
| | | 1133 | | /// <param name="cancellationToken">An optional <see cref="CancellationToken"/> instance to signal the request t |
| | | 1134 | | /// |
| | | 1135 | | /// <exception cref="ArgumentNullException">Subscription or rule description is null.</exception> |
| | | 1136 | | /// <exception cref="ServiceBusFailureReason.MessagingEntityAlreadyExists">A subscription with the same name exi |
| | | 1137 | | /// <exception cref="ServiceBusFailureReason.ServiceTimeout">The operation times out. The timeout period is init |
| | | 1138 | | /// <exception cref="UnauthorizedAccessException">No sufficient permission to perform this operation. You should |
| | | 1139 | | /// <exception cref="ServiceBusFailureReason.QuotaExceeded">Either the specified size in the description is not |
| | | 1140 | | /// <exception cref="ServiceBusFailureReason.ServiceBusy">The server is busy. You should wait before you retry t |
| | | 1141 | | /// <exception cref="ServiceBusException">An internal error or unexpected exception occurs.</exception> |
| | | 1142 | | /// <returns><see cref="RuleProperties"/> of the recently created rule.</returns> |
| | | 1143 | | public virtual async Task<Response<RuleProperties>> CreateRuleAsync( |
| | | 1144 | | string topicName, |
| | | 1145 | | string subscriptionName, |
| | | 1146 | | CreateRuleOptions options, |
| | | 1147 | | CancellationToken cancellationToken = default) |
| | | 1148 | | { |
| | 16 | 1149 | | EntityNameFormatter.CheckValidTopicName(topicName); |
| | 16 | 1150 | | EntityNameFormatter.CheckValidSubscriptionName(subscriptionName); |
| | 16 | 1151 | | options = options ?? throw new ArgumentNullException(nameof(options)); |
| | | 1152 | | |
| | 16 | 1153 | | using DiagnosticScope scope = _clientDiagnostics.CreateScope($"{nameof(ServiceBusManagementClient)}.CreateRu |
| | 16 | 1154 | | scope.Start(); |
| | | 1155 | | |
| | | 1156 | | try |
| | | 1157 | | { |
| | 16 | 1158 | | var rule = new RuleProperties(options); |
| | 16 | 1159 | | var atomRequest = rule.Serialize().ToString(); |
| | | 1160 | | |
| | 16 | 1161 | | Response response = await _httpRequestAndResponse.PutEntityAsync( |
| | 16 | 1162 | | EntityNameFormatter.FormatRulePath(topicName, subscriptionName, rule.Name), |
| | 16 | 1163 | | atomRequest, |
| | 16 | 1164 | | false, |
| | 16 | 1165 | | null, |
| | 16 | 1166 | | null, |
| | 16 | 1167 | | cancellationToken).ConfigureAwait(false); |
| | 16 | 1168 | | var result = await ReadAsString(response).ConfigureAwait(false); |
| | 16 | 1169 | | RuleProperties description = RuleDescriptionExtensions.ParseFromContent(result); |
| | | 1170 | | |
| | 16 | 1171 | | return Response.FromValue(description, response); |
| | | 1172 | | } |
| | 0 | 1173 | | catch (Exception ex) |
| | | 1174 | | { |
| | 0 | 1175 | | scope.Failed(ex); |
| | 0 | 1176 | | throw; |
| | | 1177 | | } |
| | 16 | 1178 | | } |
| | | 1179 | | |
| | | 1180 | | #endregion CreateEntity |
| | | 1181 | | |
| | | 1182 | | #region UpdateEntity |
| | | 1183 | | /// <summary> |
| | | 1184 | | /// Updates an existing queue. |
| | | 1185 | | /// </summary> |
| | | 1186 | | /// |
| | | 1187 | | /// <param name="queue">A <see cref="QueueProperties"/> object describing the attributes with which the queue wi |
| | | 1188 | | /// <param name="cancellationToken">An optional <see cref="CancellationToken"/> instance to signal the request t |
| | | 1189 | | /// |
| | | 1190 | | /// <returns>The <see cref="QueueProperties"/> of the updated queue.</returns> |
| | | 1191 | | /// <exception cref="ArgumentNullException">Queue descriptor is null.</exception> |
| | | 1192 | | /// <exception cref="ServiceBusFailureReason.MessagingEntityNotFound">Described queue was not found.</exception> |
| | | 1193 | | /// <exception cref="ServiceBusFailureReason.ServiceTimeout">The operation times out.</exception> |
| | | 1194 | | /// <exception cref="UnauthorizedAccessException">No sufficient permission to perform this operation. You should |
| | | 1195 | | /// <exception cref="ServiceBusFailureReason.QuotaExceeded">Either the specified size in the description is not |
| | | 1196 | | /// <exception cref="ServiceBusFailureReason.ServiceBusy">The server is busy. You should wait before you retry t |
| | | 1197 | | /// <exception cref="ServiceBusException">An internal error or unexpected exception occurs.</exception> |
| | | 1198 | | public virtual async Task<Response<QueueProperties>> UpdateQueueAsync( |
| | | 1199 | | QueueProperties queue, |
| | | 1200 | | CancellationToken cancellationToken = default) |
| | | 1201 | | { |
| | 8 | 1202 | | queue = queue ?? throw new ArgumentNullException(nameof(queue)); |
| | | 1203 | | |
| | 8 | 1204 | | using DiagnosticScope scope = _clientDiagnostics.CreateScope($"{nameof(ServiceBusManagementClient)}.UpdateQu |
| | 8 | 1205 | | scope.Start(); |
| | | 1206 | | |
| | | 1207 | | try |
| | | 1208 | | { |
| | 8 | 1209 | | queue.NormalizeDescription(_fullyQualifiedNamespace); |
| | 8 | 1210 | | var atomRequest = queue.Serialize().ToString(); |
| | | 1211 | | |
| | 8 | 1212 | | Response response = await _httpRequestAndResponse.PutEntityAsync( |
| | 8 | 1213 | | queue.Name, |
| | 8 | 1214 | | atomRequest, |
| | 8 | 1215 | | true, |
| | 8 | 1216 | | queue.ForwardTo, |
| | 8 | 1217 | | queue.ForwardDeadLetteredMessagesTo, |
| | 8 | 1218 | | cancellationToken).ConfigureAwait(false); |
| | 4 | 1219 | | var result = await ReadAsString(response).ConfigureAwait(false); |
| | 4 | 1220 | | QueueProperties description = QueuePropertiesExtensions.ParseFromContent(result); |
| | | 1221 | | |
| | 4 | 1222 | | return Response.FromValue(description, response); |
| | | 1223 | | } |
| | 4 | 1224 | | catch (Exception ex) |
| | | 1225 | | { |
| | 4 | 1226 | | scope.Failed(ex); |
| | 4 | 1227 | | throw; |
| | | 1228 | | } |
| | 4 | 1229 | | } |
| | | 1230 | | |
| | | 1231 | | /// <summary> |
| | | 1232 | | /// Updates an existing topic. |
| | | 1233 | | /// </summary> |
| | | 1234 | | /// |
| | | 1235 | | /// <param name="topic">A <see cref="TopicProperties"/> object describing the attributes with which the topic wi |
| | | 1236 | | /// <param name="cancellationToken">An optional <see cref="CancellationToken"/> instance to signal the request t |
| | | 1237 | | /// |
| | | 1238 | | /// <returns>The <see cref="TopicProperties"/> of the updated topic.</returns> |
| | | 1239 | | /// <exception cref="ArgumentNullException">Topic descriptor is null.</exception> |
| | | 1240 | | /// <exception cref="ServiceBusFailureReason.MessagingEntityNotFound">Described topic was not found.</exception> |
| | | 1241 | | /// <exception cref="ServiceBusFailureReason.ServiceTimeout">The operation times out.</exception> |
| | | 1242 | | /// <exception cref="UnauthorizedAccessException">No sufficient permission to perform this operation. You should |
| | | 1243 | | /// <exception cref="ServiceBusFailureReason.QuotaExceeded">Either the specified size in the description is not |
| | | 1244 | | /// <exception cref="ServiceBusFailureReason.ServiceBusy">The server is busy. You should wait before you retry t |
| | | 1245 | | /// <exception cref="ServiceBusException">An internal error or unexpected exception occurs.</exception> |
| | | 1246 | | public virtual async Task<Response<TopicProperties>> UpdateTopicAsync( |
| | | 1247 | | TopicProperties topic, |
| | | 1248 | | CancellationToken cancellationToken = default) |
| | | 1249 | | { |
| | 12 | 1250 | | topic = topic ?? throw new ArgumentNullException(nameof(topic)); |
| | 12 | 1251 | | using DiagnosticScope scope = _clientDiagnostics.CreateScope($"{nameof(ServiceBusManagementClient)}.UpdateTo |
| | 12 | 1252 | | scope.Start(); |
| | | 1253 | | |
| | | 1254 | | try |
| | | 1255 | | { |
| | 12 | 1256 | | var atomRequest = topic.Serialize().ToString(); |
| | | 1257 | | |
| | 12 | 1258 | | Response response = await _httpRequestAndResponse.PutEntityAsync( |
| | 12 | 1259 | | topic.Name, |
| | 12 | 1260 | | atomRequest, |
| | 12 | 1261 | | true, |
| | 12 | 1262 | | forwardTo: null, |
| | 12 | 1263 | | fwdDeadLetterTo: null, |
| | 12 | 1264 | | cancellationToken).ConfigureAwait(false); |
| | 8 | 1265 | | var result = await ReadAsString(response).ConfigureAwait(false); |
| | 8 | 1266 | | TopicProperties description = TopicPropertiesExtensions.ParseFromContent(result); |
| | | 1267 | | |
| | 8 | 1268 | | return Response.FromValue(description, response); |
| | | 1269 | | } |
| | 4 | 1270 | | catch (Exception ex) |
| | | 1271 | | { |
| | 4 | 1272 | | scope.Failed(ex); |
| | 4 | 1273 | | throw; |
| | | 1274 | | } |
| | 8 | 1275 | | } |
| | | 1276 | | |
| | | 1277 | | /// <summary> |
| | | 1278 | | /// Updates an existing subscription under a topic. |
| | | 1279 | | /// </summary> |
| | | 1280 | | /// |
| | | 1281 | | /// <param name="subscription">A <see cref="SubscriptionProperties"/> object describing the attributes with whic |
| | | 1282 | | /// <param name="cancellationToken">An optional <see cref="CancellationToken"/> instance to signal the request t |
| | | 1283 | | /// |
| | | 1284 | | /// <returns>The <see cref="SubscriptionProperties"/> of the updated subscription.</returns> |
| | | 1285 | | /// <exception cref="ArgumentNullException">subscription descriptor is null.</exception> |
| | | 1286 | | /// <exception cref="ServiceBusFailureReason.MessagingEntityNotFound">Described subscription was not found.</exc |
| | | 1287 | | /// <exception cref="ServiceBusFailureReason.ServiceTimeout">The operation times out.</exception> |
| | | 1288 | | /// <exception cref="UnauthorizedAccessException">No sufficient permission to perform this operation. You should |
| | | 1289 | | /// <exception cref="ServiceBusFailureReason.QuotaExceeded">Either the specified size in the description is not |
| | | 1290 | | /// <exception cref="ServiceBusFailureReason.ServiceBusy">The server is busy. You should wait before you retry t |
| | | 1291 | | /// <exception cref="ServiceBusException">An internal error or unexpected exception occurs.</exception> |
| | | 1292 | | public virtual async Task<Response<SubscriptionProperties>> UpdateSubscriptionAsync( |
| | | 1293 | | SubscriptionProperties subscription, |
| | | 1294 | | CancellationToken cancellationToken = default) |
| | | 1295 | | { |
| | 8 | 1296 | | subscription = subscription ?? throw new ArgumentNullException(nameof(subscription)); |
| | | 1297 | | |
| | 8 | 1298 | | using DiagnosticScope scope = _clientDiagnostics.CreateScope($"{nameof(ServiceBusManagementClient)}.UpdateSu |
| | 8 | 1299 | | scope.Start(); |
| | | 1300 | | |
| | | 1301 | | try |
| | | 1302 | | { |
| | 8 | 1303 | | subscription.NormalizeDescription(_fullyQualifiedNamespace); |
| | 8 | 1304 | | var atomRequest = subscription.Serialize().ToString(); |
| | | 1305 | | |
| | 8 | 1306 | | Response response = await _httpRequestAndResponse.PutEntityAsync( |
| | 8 | 1307 | | EntityNameFormatter.FormatSubscriptionPath(subscription.TopicName, subscription.SubscriptionName), |
| | 8 | 1308 | | atomRequest, |
| | 8 | 1309 | | true, |
| | 8 | 1310 | | subscription.ForwardTo, |
| | 8 | 1311 | | subscription.ForwardDeadLetteredMessagesTo, |
| | 8 | 1312 | | cancellationToken).ConfigureAwait(false); |
| | 4 | 1313 | | var result = await ReadAsString(response).ConfigureAwait(false); |
| | 4 | 1314 | | SubscriptionProperties description = SubscriptionPropertiesExtensions.ParseFromContent(subscription.Topi |
| | | 1315 | | |
| | 4 | 1316 | | return Response.FromValue(description, response); |
| | | 1317 | | } |
| | 4 | 1318 | | catch (Exception ex) |
| | | 1319 | | { |
| | 4 | 1320 | | scope.Failed(ex); |
| | 4 | 1321 | | throw; |
| | | 1322 | | } |
| | 4 | 1323 | | } |
| | | 1324 | | |
| | | 1325 | | /// <summary> |
| | | 1326 | | /// Updates an existing rule for a topic-subscription. |
| | | 1327 | | /// </summary> |
| | | 1328 | | /// |
| | | 1329 | | /// <param name="topicName">Name of the topic.</param> |
| | | 1330 | | /// <param name="subscriptionName">Name of the subscription.</param> |
| | | 1331 | | /// <param name="rule">A <see cref="RuleProperties"/> object describing the attributes with which the rule will |
| | | 1332 | | /// <param name="cancellationToken">An optional <see cref="CancellationToken"/> instance to signal the request t |
| | | 1333 | | /// |
| | | 1334 | | /// <returns>The <see cref="RuleProperties"/> of the updated rule.</returns> |
| | | 1335 | | /// <exception cref="ArgumentNullException">rule descriptor is null.</exception> |
| | | 1336 | | /// <exception cref="ServiceBusFailureReason.MessagingEntityNotFound">Described topic/subscription/rule was not |
| | | 1337 | | /// <exception cref="ServiceBusFailureReason.ServiceTimeout">The operation times out.</exception> |
| | | 1338 | | /// <exception cref="UnauthorizedAccessException">No sufficient permission to perform this operation. You should |
| | | 1339 | | /// <exception cref="ServiceBusFailureReason.QuotaExceeded">Either the specified size in the description is not |
| | | 1340 | | /// <exception cref="ServiceBusFailureReason.ServiceBusy">The server is busy. You should wait before you retry t |
| | | 1341 | | /// <exception cref="ServiceBusException">An internal error or unexpected exception occurs.</exception> |
| | | 1342 | | public virtual async Task<Response<RuleProperties>> UpdateRuleAsync( |
| | | 1343 | | string topicName, |
| | | 1344 | | string subscriptionName, |
| | | 1345 | | RuleProperties rule, |
| | | 1346 | | CancellationToken cancellationToken = default) |
| | | 1347 | | { |
| | 4 | 1348 | | rule = rule ?? throw new ArgumentNullException(nameof(rule)); |
| | | 1349 | | |
| | 4 | 1350 | | using DiagnosticScope scope = _clientDiagnostics.CreateScope($"{nameof(ServiceBusManagementClient)}.UpdateRu |
| | 4 | 1351 | | scope.Start(); |
| | | 1352 | | |
| | | 1353 | | try |
| | | 1354 | | { |
| | 4 | 1355 | | EntityNameFormatter.CheckValidTopicName(topicName); |
| | 4 | 1356 | | EntityNameFormatter.CheckValidSubscriptionName(subscriptionName); |
| | | 1357 | | |
| | 4 | 1358 | | var atomRequest = rule.Serialize().ToString(); |
| | 4 | 1359 | | Response response = await _httpRequestAndResponse.PutEntityAsync( |
| | 4 | 1360 | | EntityNameFormatter.FormatRulePath(topicName, subscriptionName, rule.Name), |
| | 4 | 1361 | | atomRequest, |
| | 4 | 1362 | | true, |
| | 4 | 1363 | | null, |
| | 4 | 1364 | | null, |
| | 4 | 1365 | | cancellationToken).ConfigureAwait(false); |
| | 4 | 1366 | | var result = await ReadAsString(response).ConfigureAwait(false); |
| | 4 | 1367 | | RuleProperties description = RuleDescriptionExtensions.ParseFromContent(result); |
| | | 1368 | | |
| | 4 | 1369 | | return Response.FromValue(description, response); |
| | | 1370 | | } |
| | 0 | 1371 | | catch (Exception ex) |
| | | 1372 | | { |
| | 0 | 1373 | | scope.Failed(ex); |
| | 0 | 1374 | | throw; |
| | | 1375 | | } |
| | 4 | 1376 | | } |
| | | 1377 | | |
| | | 1378 | | #endregion |
| | | 1379 | | |
| | | 1380 | | #region Exists |
| | | 1381 | | /// <summary> |
| | | 1382 | | /// Checks whether a given queue exists or not. |
| | | 1383 | | /// </summary> |
| | | 1384 | | /// |
| | | 1385 | | /// <param name="name">Name of the queue entity to check.</param> |
| | | 1386 | | /// <param name="cancellationToken">An optional <see cref="CancellationToken"/> instance to signal the request t |
| | | 1387 | | /// |
| | | 1388 | | /// <returns>True if queue exists, false otherwise.</returns> |
| | | 1389 | | /// <exception cref="ArgumentException">Queue name provided is not valid.</exception> |
| | | 1390 | | /// <exception cref="ServiceBusFailureReason.ServiceTimeout">The operation times out.</exception> |
| | | 1391 | | /// <exception cref="UnauthorizedAccessException">No sufficient permission to perform this operation. You should |
| | | 1392 | | /// <exception cref="ServiceBusFailureReason.ServiceBusy">The server is busy. You should wait before you retry t |
| | | 1393 | | /// <exception cref="ServiceBusException">An internal error or unexpected exception occurs.</exception> |
| | | 1394 | | public virtual async Task<Response<bool>> QueueExistsAsync( |
| | | 1395 | | string name, |
| | | 1396 | | CancellationToken cancellationToken = default) |
| | | 1397 | | { |
| | 8 | 1398 | | EntityNameFormatter.CheckValidQueueName(name); |
| | 8 | 1399 | | using DiagnosticScope scope = _clientDiagnostics.CreateScope($"{nameof(ServiceBusManagementClient)}.QueueExi |
| | 8 | 1400 | | scope.Start(); |
| | | 1401 | | try |
| | | 1402 | | { |
| | 8 | 1403 | | Response response = null; |
| | | 1404 | | try |
| | | 1405 | | { |
| | 8 | 1406 | | response = await _httpRequestAndResponse.GetEntityAsync(name, null, false, cancellationToken).Config |
| | 8 | 1407 | | var result = await ReadAsString(response).ConfigureAwait(false); |
| | 8 | 1408 | | QueueProperties description = QueuePropertiesExtensions.ParseFromContent(result); |
| | 4 | 1409 | | } |
| | 4 | 1410 | | catch (ServiceBusException ex) when (ex.Reason == ServiceBusFailureReason.MessagingEntityNotFound) |
| | | 1411 | | { |
| | 4 | 1412 | | return Response.FromValue(false, response); |
| | | 1413 | | } |
| | | 1414 | | |
| | 4 | 1415 | | return Response.FromValue(true, response); |
| | | 1416 | | } |
| | 0 | 1417 | | catch (Exception ex) |
| | | 1418 | | { |
| | 0 | 1419 | | scope.Failed(ex); |
| | 0 | 1420 | | throw; |
| | | 1421 | | } |
| | 8 | 1422 | | } |
| | | 1423 | | |
| | | 1424 | | /// <summary> |
| | | 1425 | | /// Checks whether a given topic exists or not. |
| | | 1426 | | /// </summary> |
| | | 1427 | | /// |
| | | 1428 | | /// <param name="name">Name of the topic entity to check.</param> |
| | | 1429 | | /// <param name="cancellationToken">An optional <see cref="CancellationToken"/> instance to signal the request t |
| | | 1430 | | /// |
| | | 1431 | | /// <returns>True if topic exists, false otherwise.</returns> |
| | | 1432 | | /// <exception cref="ArgumentException">topic name provided is not valid.</exception> |
| | | 1433 | | /// <exception cref="ServiceBusFailureReason.ServiceTimeout">The operation times out.</exception> |
| | | 1434 | | /// <exception cref="UnauthorizedAccessException">No sufficient permission to perform this operation. You should |
| | | 1435 | | /// <exception cref="ServiceBusFailureReason.ServiceBusy">The server is busy. You should wait before you retry t |
| | | 1436 | | /// <exception cref="ServiceBusException">An internal error or unexpected exception occurs.</exception> |
| | | 1437 | | public virtual async Task<Response<bool>> TopicExistsAsync( |
| | | 1438 | | string name, |
| | | 1439 | | CancellationToken cancellationToken = default) |
| | | 1440 | | { |
| | 8 | 1441 | | EntityNameFormatter.CheckValidTopicName(name); |
| | 8 | 1442 | | using DiagnosticScope scope = _clientDiagnostics.CreateScope($"{nameof(ServiceBusManagementClient)}.TopicExi |
| | 8 | 1443 | | scope.Start(); |
| | | 1444 | | |
| | | 1445 | | try |
| | | 1446 | | { |
| | 8 | 1447 | | Response response = null; |
| | | 1448 | | |
| | | 1449 | | try |
| | | 1450 | | { |
| | 8 | 1451 | | response = await _httpRequestAndResponse.GetEntityAsync(name, null, false, cancellationToken).Config |
| | 8 | 1452 | | var result = await ReadAsString(response).ConfigureAwait(false); |
| | 8 | 1453 | | TopicProperties description = TopicPropertiesExtensions.ParseFromContent(result); |
| | 4 | 1454 | | } |
| | 4 | 1455 | | catch (ServiceBusException ex) when (ex.Reason == ServiceBusFailureReason.MessagingEntityNotFound) |
| | | 1456 | | { |
| | 4 | 1457 | | return Response.FromValue(false, response); |
| | | 1458 | | } |
| | | 1459 | | |
| | 4 | 1460 | | return Response.FromValue(true, response); |
| | | 1461 | | } |
| | 0 | 1462 | | catch (Exception ex) |
| | | 1463 | | { |
| | 0 | 1464 | | scope.Failed(ex); |
| | 0 | 1465 | | throw; |
| | | 1466 | | } |
| | 8 | 1467 | | } |
| | | 1468 | | |
| | | 1469 | | /// <summary> |
| | | 1470 | | /// Checks whether a given subscription exists or not. |
| | | 1471 | | /// </summary> |
| | | 1472 | | /// |
| | | 1473 | | /// <param name="topicName">Name of the topic.</param> |
| | | 1474 | | /// <param name="subscriptionName">Name of the subscription to check.</param> |
| | | 1475 | | /// <param name="cancellationToken">An optional <see cref="CancellationToken"/> instance to signal the request t |
| | | 1476 | | /// |
| | | 1477 | | /// <returns>True if subscription exists, false otherwise.</returns> |
| | | 1478 | | /// <exception cref="ArgumentException">topic or subscription name provided is not valid.</exception> |
| | | 1479 | | /// <exception cref="ServiceBusFailureReason.ServiceTimeout">The operation times out.</exception> |
| | | 1480 | | /// <exception cref="UnauthorizedAccessException">No sufficient permission to perform this operation. You should |
| | | 1481 | | /// <exception cref="ServiceBusFailureReason.ServiceBusy">The server is busy. You should wait before you retry t |
| | | 1482 | | /// <exception cref="ServiceBusException">An internal error or unexpected exception occurs.</exception> |
| | | 1483 | | public virtual async Task<Response<bool>> SubscriptionExistsAsync( |
| | | 1484 | | string topicName, |
| | | 1485 | | string subscriptionName, |
| | | 1486 | | CancellationToken cancellationToken = default) |
| | | 1487 | | { |
| | 8 | 1488 | | EntityNameFormatter.CheckValidTopicName(topicName); |
| | 8 | 1489 | | EntityNameFormatter.CheckValidSubscriptionName(subscriptionName); |
| | 8 | 1490 | | using DiagnosticScope scope = _clientDiagnostics.CreateScope($"{nameof(ServiceBusManagementClient)}.Subscrip |
| | 8 | 1491 | | scope.Start(); |
| | | 1492 | | |
| | | 1493 | | try |
| | | 1494 | | { |
| | 8 | 1495 | | Response response = null; |
| | | 1496 | | |
| | | 1497 | | try |
| | | 1498 | | { |
| | 8 | 1499 | | response = await _httpRequestAndResponse.GetEntityAsync(EntityNameFormatter.FormatSubscriptionPath(t |
| | 8 | 1500 | | var result = await ReadAsString(response).ConfigureAwait(false); |
| | 8 | 1501 | | SubscriptionProperties description = SubscriptionPropertiesExtensions.ParseFromContent(topicName, re |
| | 4 | 1502 | | } |
| | 4 | 1503 | | catch (ServiceBusException ex) when (ex.Reason == ServiceBusFailureReason.MessagingEntityNotFound) |
| | | 1504 | | { |
| | 4 | 1505 | | return Response.FromValue(false, response); |
| | | 1506 | | } |
| | | 1507 | | |
| | 4 | 1508 | | return Response.FromValue(true, response); |
| | | 1509 | | } |
| | 0 | 1510 | | catch (Exception ex) |
| | | 1511 | | { |
| | 0 | 1512 | | scope.Failed(ex); |
| | 0 | 1513 | | throw; |
| | | 1514 | | } |
| | 8 | 1515 | | } |
| | | 1516 | | |
| | | 1517 | | /// <summary> |
| | | 1518 | | /// Checks whether a given rule exists or not. |
| | | 1519 | | /// </summary> |
| | | 1520 | | /// |
| | | 1521 | | /// <param name="topicName">Name of the topic.</param> |
| | | 1522 | | /// <param name="subscriptionName">Name of the subscription to check.</param> |
| | | 1523 | | /// <param name="ruleName">The name of the rule to retrieve.</param> |
| | | 1524 | | /// <param name="cancellationToken">An optional <see cref="CancellationToken"/> instance to signal the request t |
| | | 1525 | | /// |
| | | 1526 | | /// <returns>True if subscription exists, false otherwise.</returns> |
| | | 1527 | | /// <exception cref="ArgumentException">topic or subscription name provided is not valid.</exception> |
| | | 1528 | | /// <exception cref="ServiceBusFailureReason.ServiceTimeout">The operation times out.</exception> |
| | | 1529 | | /// <exception cref="UnauthorizedAccessException">No sufficient permission to perform this operation. You should |
| | | 1530 | | /// <exception cref="ServiceBusFailureReason.ServiceBusy">The server is busy. You should wait before you retry t |
| | | 1531 | | /// <exception cref="ServiceBusException">An internal error or unexpected exception occurs.</exception> |
| | | 1532 | | public virtual async Task<Response<bool>> RuleExistsAsync( |
| | | 1533 | | string topicName, |
| | | 1534 | | string subscriptionName, |
| | | 1535 | | string ruleName, |
| | | 1536 | | CancellationToken cancellationToken = default) |
| | | 1537 | | { |
| | 8 | 1538 | | EntityNameFormatter.CheckValidTopicName(topicName); |
| | 8 | 1539 | | EntityNameFormatter.CheckValidSubscriptionName(subscriptionName); |
| | 8 | 1540 | | using DiagnosticScope scope = _clientDiagnostics.CreateScope($"{nameof(ServiceBusManagementClient)}.RuleExis |
| | 8 | 1541 | | scope.Start(); |
| | | 1542 | | |
| | | 1543 | | try |
| | | 1544 | | { |
| | 8 | 1545 | | Response response = null; |
| | | 1546 | | |
| | | 1547 | | try |
| | | 1548 | | { |
| | 8 | 1549 | | response = await _httpRequestAndResponse.GetEntityAsync(EntityNameFormatter.FormatRulePath(topicName |
| | 4 | 1550 | | var result = await ReadAsString(response).ConfigureAwait(false); |
| | 4 | 1551 | | RuleProperties description = RuleDescriptionExtensions.ParseFromContent(result); |
| | 4 | 1552 | | } |
| | 4 | 1553 | | catch (ServiceBusException ex) when (ex.Reason == ServiceBusFailureReason.MessagingEntityNotFound) |
| | | 1554 | | { |
| | 4 | 1555 | | return Response.FromValue(false, response); |
| | | 1556 | | } |
| | | 1557 | | |
| | 4 | 1558 | | return Response.FromValue(true, response); |
| | | 1559 | | } |
| | 0 | 1560 | | catch (Exception ex) |
| | | 1561 | | { |
| | 0 | 1562 | | scope.Failed(ex); |
| | 0 | 1563 | | throw; |
| | | 1564 | | } |
| | 8 | 1565 | | } |
| | | 1566 | | |
| | | 1567 | | #endregion |
| | | 1568 | | |
| | | 1569 | | private static async Task<string> ReadAsString(Response response) |
| | | 1570 | | { |
| | | 1571 | | string exceptionMessage; |
| | 208 | 1572 | | using StreamReader reader = new StreamReader(response.ContentStream); |
| | 208 | 1573 | | exceptionMessage = await reader.ReadToEndAsync().ConfigureAwait(false); |
| | 208 | 1574 | | return exceptionMessage; |
| | 208 | 1575 | | } |
| | | 1576 | | |
| | | 1577 | | /// <summary> |
| | | 1578 | | /// Builds the audience for use in the signature. |
| | | 1579 | | /// </summary> |
| | | 1580 | | /// |
| | | 1581 | | /// <param name="fullyQualifiedNamespace">The fully qualified Service Bus namespace. This is likely to be simil |
| | | 1582 | | /// |
| | | 1583 | | /// <returns>The value to use as the audience of the signature.</returns> |
| | | 1584 | | private static string BuildAudienceResource(string fullyQualifiedNamespace) |
| | | 1585 | | { |
| | 84 | 1586 | | var builder = new UriBuilder(fullyQualifiedNamespace) |
| | 84 | 1587 | | { |
| | 84 | 1588 | | Scheme = Uri.UriSchemeHttps, |
| | 84 | 1589 | | Port = -1, |
| | 84 | 1590 | | Fragment = string.Empty, |
| | 84 | 1591 | | Password = string.Empty, |
| | 84 | 1592 | | UserName = string.Empty, |
| | 84 | 1593 | | }; |
| | | 1594 | | |
| | 84 | 1595 | | if (builder.Path.EndsWith("/", StringComparison.InvariantCultureIgnoreCase)) |
| | | 1596 | | { |
| | 84 | 1597 | | builder.Path = builder.Path.TrimEnd('/'); |
| | | 1598 | | } |
| | | 1599 | | |
| | 84 | 1600 | | return builder.Uri.AbsoluteUri.ToLowerInvariant(); |
| | | 1601 | | } |
| | | 1602 | | } |
| | | 1603 | | |
| | | 1604 | | } |