| | | 1 | | // Copyright (c) Microsoft Corporation. All rights reserved. |
| | | 2 | | // Licensed under the MIT License. |
| | | 3 | | |
| | | 4 | | using System; |
| | | 5 | | using System.Collections.Generic; |
| | | 6 | | using System.Threading; |
| | | 7 | | using System.Threading.Tasks; |
| | | 8 | | using Azure.Messaging.ServiceBus.Amqp; |
| | | 9 | | using Azure.Messaging.ServiceBus.Primitives; |
| | | 10 | | |
| | | 11 | | namespace Azure.Messaging.ServiceBus.Core |
| | | 12 | | { |
| | | 13 | | /// <summary> |
| | | 14 | | /// Provides an abstraction for generalizing an Service Bus entity client so that a dedicated instance may provide |
| | | 15 | | /// for a specific transport, such as AMQP or JMS. It is intended that the public <see cref="ServiceBusConnection |
| | | 16 | | /// a transport client via containment and delegate operations to it rather than understanding protocol-specific d |
| | | 17 | | /// for different transports. |
| | | 18 | | /// </summary> |
| | | 19 | | /// |
| | | 20 | | internal abstract class TransportClient : IAsyncDisposable |
| | | 21 | | { |
| | | 22 | | /// <summary> |
| | | 23 | | /// Indicates whether or not this client has been closed. |
| | | 24 | | /// </summary> |
| | | 25 | | /// |
| | | 26 | | /// <value> |
| | | 27 | | /// <c>true</c> if the client is closed; otherwise, <c>false</c>. |
| | | 28 | | /// </value> |
| | | 29 | | /// |
| | 0 | 30 | | public virtual bool IsClosed { get; } |
| | | 31 | | |
| | | 32 | | /// <summary> |
| | | 33 | | /// The endpoint for the Service Bus service to which the client is associated. |
| | | 34 | | /// </summary> |
| | | 35 | | /// |
| | 0 | 36 | | public virtual Uri ServiceEndpoint { get; } |
| | | 37 | | |
| | | 38 | | |
| | | 39 | | |
| | | 40 | | /// <summary> |
| | | 41 | | /// Creates a sender strongly aligned with the active protocol and transport, |
| | | 42 | | /// responsible for sending <see cref="ServiceBusMessage" /> to the entity. |
| | | 43 | | /// </summary> |
| | | 44 | | /// <param name="entityPath">The entity path to send the message to.</param> |
| | | 45 | | /// <param name="viaEntityPath">The entity path to route the message through. Useful when using transactions.</p |
| | | 46 | | /// <param name="retryPolicy">The policy which governs retry behavior and try timeouts.</param> |
| | | 47 | | /// <param name="identifier">The identifier for the sender.</param> |
| | | 48 | | /// |
| | | 49 | | /// <returns>A <see cref="TransportSender"/> configured in the requested manner.</returns> |
| | | 50 | | /// |
| | | 51 | | public abstract TransportSender CreateSender(string entityPath, string viaEntityPath, ServiceBusRetryPolicy retr |
| | | 52 | | |
| | | 53 | | /// <summary> |
| | | 54 | | /// Creates a receiver strongly aligned with the active protocol and transport, responsible |
| | | 55 | | /// for reading <see cref="ServiceBusMessage" /> from a specific Service Bus entity. |
| | | 56 | | /// </summary> |
| | | 57 | | /// <param name="entityPath"></param> |
| | | 58 | | /// |
| | | 59 | | /// <param name="retryPolicy">The policy which governs retry behavior and try timeouts.</param> |
| | | 60 | | /// <param name="receiveMode">The <see cref="ReceiveMode"/> used to specify how messages are received. Defaults |
| | | 61 | | /// <param name="prefetchCount">Controls the number of events received and queued locally without regard to whet |
| | | 62 | | /// <param name="identifier"></param> |
| | | 63 | | /// <param name="sessionId"></param> |
| | | 64 | | /// <param name="isSessionReceiver"></param> |
| | | 65 | | /// |
| | | 66 | | /// <returns>A <see cref="TransportReceiver" /> configured in the requested manner.</returns> |
| | | 67 | | /// |
| | | 68 | | public abstract TransportReceiver CreateReceiver( |
| | | 69 | | string entityPath, |
| | | 70 | | ServiceBusRetryPolicy retryPolicy, |
| | | 71 | | ReceiveMode receiveMode, |
| | | 72 | | uint prefetchCount, |
| | | 73 | | string identifier, |
| | | 74 | | string sessionId, |
| | | 75 | | bool isSessionReceiver); |
| | | 76 | | |
| | | 77 | | /// <summary> |
| | | 78 | | /// Creates a rule manager strongly aligned with the active protocol and transport, |
| | | 79 | | /// responsible for adding, removing and getting rules from the Service Bus subscription. |
| | | 80 | | /// </summary> |
| | | 81 | | /// |
| | | 82 | | /// <param name="subscriptionPath">The path of the Service Bus subscription to which the rule manager is bound.< |
| | | 83 | | /// <param name="retryPolicy">The policy which governs retry behavior and try timeouts.</param> |
| | | 84 | | /// <param name="identifier">The identifier for the rule manager.</param> |
| | | 85 | | /// |
| | | 86 | | /// <returns>A <see cref="TransportRuleManager"/> configured in the requested manner.</returns> |
| | | 87 | | /// |
| | | 88 | | public abstract TransportRuleManager CreateRuleManager( |
| | | 89 | | string subscriptionPath, |
| | | 90 | | ServiceBusRetryPolicy retryPolicy, |
| | | 91 | | string identifier); |
| | | 92 | | |
| | | 93 | | /// <summary> |
| | | 94 | | /// Closes the connection to the transport client instance. |
| | | 95 | | /// </summary> |
| | | 96 | | /// |
| | | 97 | | /// <param name="cancellationToken">An optional <see cref="CancellationToken"/> instance to signal the request t |
| | | 98 | | /// |
| | | 99 | | public abstract Task CloseAsync(CancellationToken cancellationToken); |
| | | 100 | | |
| | | 101 | | /// <summary> |
| | | 102 | | /// Performs the task needed to clean up resources used by the client, |
| | | 103 | | /// including ensuring that the client itself has been closed. |
| | | 104 | | /// </summary> |
| | | 105 | | /// |
| | | 106 | | /// <returns>A task to be resolved on when the operation has completed.</returns> |
| | | 107 | | /// |
| | 0 | 108 | | public virtual async ValueTask DisposeAsync() => await CloseAsync(CancellationToken.None).ConfigureAwait(false); |
| | | 109 | | } |
| | | 110 | | } |