/// <summary>
        /// Creates a session receiver which can be used to interact with all messages with the same sessionId.
        /// </summary>
        ///
        /// <param name="entityPath">The name of the specific queue to associate the receiver with.</param>
        /// <param name="connection">The <see cref="ServiceBusConnection" /> connection to use for communication with the Service Bus service.</param>
        /// <param name="plugins">The set of plugins to apply to incoming messages.</param>
        /// <param name="options">A set of options to apply when configuring the receiver.</param>
        /// <param name="cancellationToken">An optional <see cref="CancellationToken"/> instance to signal the request to cancel the operation.</param>
        ///
        ///<returns>Returns a new instance of the <see cref="ServiceBusSessionReceiver"/> class.</returns>
        internal static async Task <ServiceBusSessionReceiver> CreateSessionReceiverAsync(
            string entityPath,
            ServiceBusConnection connection,
            IList <ServiceBusPlugin> plugins,
            ServiceBusSessionReceiverOptions options = default,
            CancellationToken cancellationToken      = default)
        {
            var receiver = new ServiceBusSessionReceiver(
                connection: connection,
                entityPath: entityPath,
                plugins: plugins,
                options: options);

            try
            {
                await receiver.OpenLinkAsync(cancellationToken).ConfigureAwait(false);
            }
            catch (Exception ex)
            {
                receiver.Logger.ClientCreateException(typeof(ServiceBusSessionReceiver), receiver.FullyQualifiedNamespace, entityPath, ex);
                throw;
            }
            receiver.Logger.ClientCreateComplete(typeof(ServiceBusSessionReceiver), receiver.Identifier);
            return(receiver);
        }
Пример #2
0
        /// <summary>
        /// Creates a session receiver which can be used to interact with all messages with the same sessionId.
        /// </summary>
        ///
        /// <param name="entityPath">The name of the specific queue to associate the receiver with.</param>
        /// <param name="connection">The <see cref="ServiceBusConnection" /> connection to use for communication with the Service Bus service.</param>
        /// <param name="sessionId">The sessionId for this receiver</param>
        /// <param name="options">A set of options to apply when configuring the receiver.</param>
        /// <param name="cancellationToken">An optional <see cref="CancellationToken"/> instance to signal the request to cancel the operation.</param>
        ///
        ///<returns>Returns a new instance of the <see cref="ServiceBusSessionReceiver"/> class.</returns>
        internal static async Task <ServiceBusSessionReceiver> CreateSessionReceiverAsync(
            string entityPath,
            ServiceBusConnection connection,
            string sessionId = default,
            ServiceBusReceiverOptions options   = default,
            CancellationToken cancellationToken = default)
        {
            var receiver = new ServiceBusSessionReceiver(
                connection: connection,
                entityPath: entityPath,
                options: options,
                sessionId: sessionId);

            await receiver.OpenLinkAsync(cancellationToken).ConfigureAwait(false);

            return(receiver);
        }
        ///  <summary>
        ///  Creates a session receiver which can be used to interact with all messages with the same sessionId.
        ///  </summary>
        ///  <param name="entityPath">The name of the specific queue to associate the receiver with.</param>
        ///  <param name="connection">The <see cref="ServiceBusConnection" /> connection to use for communication with the Service Bus service.</param>
        ///  <param name="plugins">The set of plugins to apply to incoming messages.</param>
        ///  <param name="options">A set of options to apply when configuring the receiver.</param>
        ///  <param name="sessionId">The Session Id to receive from or null to receive from the next available session.</param>
        ///  <param name="cancellationToken">An optional <see cref="CancellationToken"/> instance to signal the request to cancel the operation.</param>
        ///  <param name="isProcessor">True if called from the session processor.</param>
        ///  <returns>Returns a new instance of the <see cref="ServiceBusSessionReceiver"/> class.</returns>
        internal static async Task <ServiceBusSessionReceiver> CreateSessionReceiverAsync(
            string entityPath,
            ServiceBusConnection connection,
            IList <ServiceBusPlugin> plugins,
            ServiceBusSessionReceiverOptions options,
            string sessionId,
            CancellationToken cancellationToken,
            bool isProcessor = false)
        {
            var receiver = new ServiceBusSessionReceiver(
                connection: connection,
                entityPath: entityPath,
                plugins: plugins,
                options: options,
                cancellationToken: cancellationToken,
                sessionId: sessionId,
                isProcessor: isProcessor);

            try
            {
                await receiver.OpenLinkAsync(isProcessor, cancellationToken).ConfigureAwait(false);
            }
            catch (ServiceBusException e)
                when(e.Reason == ServiceBusFailureReason.ServiceTimeout && isProcessor)
                {
                    receiver.Logger.ProcessorAcceptSessionTimeout(receiver.FullyQualifiedNamespace, entityPath, e.ToString());
                    throw;
                }
            catch (TaskCanceledException exception)
                when(isProcessor)
                {
                    receiver.Logger.ProcessorStoppingAcceptSessionCanceled(receiver.FullyQualifiedNamespace, entityPath, exception.ToString());
                    throw;
                }
            catch (Exception ex)
            {
                receiver.Logger.ClientCreateException(typeof(ServiceBusSessionReceiver), receiver.FullyQualifiedNamespace, entityPath, ex);
                throw;
            }
            receiver.Logger.ClientCreateComplete(typeof(ServiceBusSessionReceiver), receiver.Identifier);
            return(receiver);
        }