/// <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);
        }
 public SessionReceiverManager(
     ServiceBusConnection connection,
     string fullyQualifiedNamespace,
     string entityPath,
     string identifier,
     string sessionId,
     ServiceBusProcessorOptions processorOptions,
     Func <ProcessSessionEventArgs, Task> sessionInitHandler,
     Func <ProcessSessionEventArgs, Task> sessionCloseHandler,
     Func <ProcessSessionMessageEventArgs, Task> messageHandler,
     Func <ProcessErrorEventArgs, Task> errorHandler,
     SemaphoreSlim concurrentAcceptSessionsSemaphore,
     EntityScopeFactory scopeFactory,
     IList <ServiceBusPlugin> plugins)
     : base(connection, fullyQualifiedNamespace, entityPath, identifier, processorOptions, default, errorHandler,
            scopeFactory, plugins)
 {
     _sessionInitHandler  = sessionInitHandler;
     _sessionCloseHandler = sessionCloseHandler;
     _messageHandler      = messageHandler;
     _concurrentAcceptSessionsSemaphore = concurrentAcceptSessionsSemaphore;
     _sessionReceiverOptions            = new ServiceBusSessionReceiverOptions
     {
         ReceiveMode   = _processorOptions.ReceiveMode,
         PrefetchCount = _processorOptions.PrefetchCount,
         SessionId     = sessionId
     };
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="ServiceBusReceiver"/> class.
 /// </summary>
 ///
 /// <param name="connection">The <see cref="ServiceBusConnection" /> connection to use for communication with the Service Bus service.</param>
 /// <param name="entityPath"></param>
 /// <param name="options">A set of options to apply when configuring the consumer.</param>
 internal ServiceBusSessionReceiver(
     ServiceBusConnection connection,
     string entityPath,
     ServiceBusSessionReceiverOptions options) :
     base(connection, entityPath, true, options?.ToReceiverOptions(), options?.SessionId)
 {
 }
Esempio n. 4
0
 /// <summary>
 /// Initializes a new instance of the <see cref="ServiceBusReceiver"/> class.
 /// </summary>
 ///
 /// <param name="connection">The <see cref="ServiceBusConnection" /> connection to use for communication with the Service Bus service.</param>
 /// <param name="entityPath"></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 consumer.</param>
 /// <param name="sessionId">An optional session Id to receive from.</param>
 internal ServiceBusSessionReceiver(
     ServiceBusConnection connection,
     string entityPath,
     IList <ServiceBusPlugin> plugins,
     ServiceBusSessionReceiverOptions options,
     string sessionId = default) :
     base(connection, entityPath, true, plugins, options?.ToReceiverOptions(), sessionId)
 {
 }
Esempio n. 5
0
 /// <summary>
 /// Initializes a new instance of the <see cref="ServiceBusReceiver"/> class.
 /// </summary>
 ///
 /// <param name="connection">The <see cref="ServiceBusConnection" /> connection to use for communication with the Service Bus service.</param>
 /// <param name="entityPath"></param>
 /// <param name="options">A set of options to apply when configuring the consumer.</param>
 /// <param name="cancellationToken">The cancellation token to use when opening the receiver link.</param>
 /// <param name="sessionId">An optional session Id to receive from.</param>
 /// <param name="isProcessor"></param>
 internal ServiceBusSessionReceiver(
     ServiceBusConnection connection,
     string entityPath,
     ServiceBusSessionReceiverOptions options,
     CancellationToken cancellationToken,
     string sessionId = default,
     bool isProcessor = false) :
     base(connection, entityPath, true, options?.ToReceiverOptions(), sessionId, isProcessor, cancellationToken)
 {
     _connection = connection;
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="ServiceBusReceiver"/> class.
 /// </summary>
 ///
 /// <param name="connection">The <see cref="ServiceBusConnection" /> connection to use for communication with the Service Bus service.</param>
 /// <param name="entityPath"></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 consumer.</param>
 /// <param name="cancellationToken">The cancellation token to use when opening the receiver link.</param>
 /// <param name="sessionId">An optional session Id to receive from.</param>
 internal ServiceBusSessionReceiver(
     ServiceBusConnection connection,
     string entityPath,
     IList <ServiceBusPlugin> plugins,
     ServiceBusSessionReceiverOptions options,
     CancellationToken cancellationToken,
     string sessionId = default) :
     base(connection, entityPath, true, plugins, options?.ToReceiverOptions(), sessionId, cancellationToken)
 {
     _connection = connection;
 }
        /// <summary>
        /// Creates a <see cref="ServiceBusSessionReceiver"/> instance that can be used for receiving
        /// and settling messages from a specific session-enabled queue. It uses <see cref="ReceiveMode"/> to specify
        /// how messages are received. Defaults to PeekLock mode. The <see cref="ReceiveMode"/> is set in <see cref="ServiceBusReceiverOptions"/>.
        /// </summary>
        ///
        /// <param name="queueName">The session-enabled queue to create a <see cref="ServiceBusSessionReceiver"/> for.</param>
        /// <param name="options">The set of <see cref="ServiceBusReceiverOptions"/> to use for configuring the
        /// <see cref="ServiceBusSessionReceiver"/>.</param>
        /// <param name="cancellationToken">An optional <see cref="CancellationToken"/> instance to signal the request to cancel the operation.</param>
        ///
        /// <remarks>Because this is establishing a session lock, this method performs a service call. If the
        /// sessionId parameter is not specified, and there are no available messages in the queue, this will
        /// throw a <see cref="ServiceBusException"/> with <see cref="ServiceBusException.Reason"/> of <see cref="ServiceBusException.FailureReason.ServiceTimeout"/>.
        /// </remarks>
        ///
        /// <returns>A <see cref="ServiceBusSessionReceiver"/> scoped to the specified queue and a specific session.</returns>
        public virtual async Task <ServiceBusSessionReceiver> CreateSessionReceiverAsync(
            string queueName,
            ServiceBusSessionReceiverOptions options = default,
            CancellationToken cancellationToken      = default)
        {
            ValidateEntityName(queueName);

            return(await ServiceBusSessionReceiver.CreateSessionReceiverAsync(
                       entityPath : queueName,
                       connection : Connection,
                       options : options,
                       cancellationToken : cancellationToken).ConfigureAwait(false));
        }
Esempio n. 8
0
        /// <summary>
        /// Creates a <see cref="ServiceBusSessionReceiver"/> instance that can be used for receiving
        /// and settling messages from a specific session-enabled queue. It uses <see cref="ServiceBusReceiveMode"/> to specify
        /// how messages are received. Defaults to PeekLock mode. The <see cref="ServiceBusReceiveMode"/> is set in <see cref="ServiceBusReceiverOptions"/>.
        /// </summary>
        ///
        /// <param name="queueName">The session-enabled queue to create a <see cref="ServiceBusSessionReceiver"/> for.</param>
        /// <param name="options">The set of <see cref="ServiceBusReceiverOptions"/> to use for configuring the
        /// <see cref="ServiceBusSessionReceiver"/>.</param>
        /// <param name="cancellationToken">An optional <see cref="CancellationToken"/> instance to signal the request to cancel the operation.</param>
        ///
        /// <remarks>Because this is establishing a session lock, this method performs a service call. If there are no available messages in the queue,
        /// this will throw a <see cref="ServiceBusException"/> with <see cref="ServiceBusException.Reason"/> of <see cref="ServiceBusFailureReason.ServiceTimeout"/>.
        /// </remarks>
        ///
        /// <returns>A <see cref="ServiceBusSessionReceiver"/> scoped to the specified queue and a specific session.</returns>
        public virtual async Task <ServiceBusSessionReceiver> AcceptNextSessionAsync(
            string queueName,
            ServiceBusSessionReceiverOptions options = default,
            CancellationToken cancellationToken      = default)
        {
            ValidateEntityName(queueName);

            return(await ServiceBusSessionReceiver.CreateSessionReceiverAsync(
                       entityPath : queueName,
                       connection : Connection,
                       plugins : Plugins,
                       options : options,
                       sessionId : default,
        /// <summary>
        /// Creates a <see cref="ServiceBusSessionReceiver"/> instance that can be used for receiving
        /// and settling messages from a specific session-enabled subscription. It uses <see cref="ReceiveMode"/> to specify
        /// how messages are received. Defaults to PeekLock mode. The <see cref="ReceiveMode"/> is set in <see cref="ServiceBusReceiverOptions"/>.
        /// </summary>
        ///
        /// <param name="topicName">The topic to create a <see cref="ServiceBusSessionReceiver"/> for.</param>
        /// <param name="subscriptionName">The session-enabled subscription to create a <see cref="ServiceBusSessionReceiver"/> for.</param>
        /// <param name="options">The set of <see cref="ServiceBusReceiverOptions"/> to use for configuring the
        /// <see cref="ServiceBusSessionReceiver"/>.</param>
        /// <param name="cancellationToken">An optional <see cref="CancellationToken"/> instance to signal the request to cancel the operation.</param>
        ///
        /// <remarks>Because this is establishing a session lock, this method performs a service call. If the
        /// sessionId parameter is not specified, and there are no available messages in the queue, this will
        /// throw a <see cref="ServiceBusException"/> with <see cref="ServiceBusException.Reason"/> of <see cref="ServiceBusException.FailureReason.ServiceTimeout"/>.
        /// </remarks>
        ///
        /// <returns>A <see cref="ServiceBusSessionReceiver"/> scoped to the specified queue and a specific session.</returns>
        public virtual async Task <ServiceBusSessionReceiver> CreateSessionReceiverAsync(
            string topicName,
            string subscriptionName,
            ServiceBusSessionReceiverOptions options = default,
            CancellationToken cancellationToken      = default)
        {
            ValidateEntityName(topicName);

            return(await ServiceBusSessionReceiver.CreateSessionReceiverAsync(
                       entityPath : EntityNameFormatter.FormatSubscriptionPath(topicName, subscriptionName),
                       connection : Connection,
                       options : options,
                       cancellationToken : cancellationToken).ConfigureAwait(false));
        }
        /// <summary>
        /// Creates a <see cref="ServiceBusSessionReceiver"/> instance that can be used for receiving
        /// and settling messages from a specific session-enabled queue. It uses <see cref="ReceiveMode"/> to specify
        /// how messages are received. Defaults to PeekLock mode. The <see cref="ReceiveMode"/> is set in <see cref="ServiceBusReceiverOptions"/>.
        /// </summary>
        ///
        /// <param name="queueName">The session-enabled queue to create a <see cref="ServiceBusSessionReceiver"/> for.</param>
        /// <param name="sessionId">Gets or sets a session ID to scope the <see cref="ServiceBusSessionReceiver"/> to.</param>
        /// <param name="options">The set of <see cref="ServiceBusReceiverOptions"/> to use for configuring the
        /// <see cref="ServiceBusSessionReceiver"/>.</param>
        /// <param name="cancellationToken">An optional <see cref="CancellationToken"/> instance to signal the request to cancel the operation.</param>
        ///
        /// <remarks>Because this is establishing a session lock, this method performs a service call. If the
        /// sessionId parameter is null, and there are no available messages in the queue, this will
        /// throw a <see cref="ServiceBusException"/> with <see cref="ServiceBusException.Reason"/> of <see cref="ServiceBusFailureReason.ServiceTimeout"/>.
        /// </remarks>
        ///
        /// <returns>A <see cref="ServiceBusSessionReceiver"/> scoped to the specified queue and a specific session.</returns>
        public virtual async Task <ServiceBusSessionReceiver> AcceptSessionAsync(
            string queueName,
            string sessionId,
            ServiceBusSessionReceiverOptions options = default,
            CancellationToken cancellationToken      = default)
        {
            ValidateEntityName(queueName);
            options ??= new ServiceBusSessionReceiverOptions();
            options.SessionId = sessionId;

            return(await ServiceBusSessionReceiver.CreateSessionReceiverAsync(
                       entityPath : queueName,
                       connection : Connection,
                       plugins : Plugins,
                       options : options,
                       cancellationToken : cancellationToken).ConfigureAwait(false));
        }
Esempio n. 11
0
 public SessionReceiverManager(
     ServiceBusSessionProcessor sessionProcessor,
     string sessionId,
     SemaphoreSlim concurrentAcceptSessionsSemaphore,
     EntityScopeFactory scopeFactory,
     bool keepOpenOnReceiveTimeout)
     : base(sessionProcessor.InnerProcessor, scopeFactory)
 {
     _concurrentAcceptSessionsSemaphore = concurrentAcceptSessionsSemaphore;
     _sessionReceiverOptions            = new ServiceBusSessionReceiverOptions
     {
         ReceiveMode   = sessionProcessor.InnerProcessor.Options.ReceiveMode,
         PrefetchCount = sessionProcessor.InnerProcessor.Options.PrefetchCount,
     };
     _sessionId = sessionId;
     _keepOpenOnReceiveTimeout = keepOpenOnReceiveTimeout;
     _sessionProcessor         = sessionProcessor;
 }
        ///  <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);
        }
 public SessionReceiverManager(
     ServiceBusProcessor processor,
     string sessionId,
     SemaphoreSlim concurrentAcceptSessionsSemaphore,
     EntityScopeFactory scopeFactory,
     IList <ServiceBusPlugin> plugins,
     int maxCallsPerSession,
     bool keepOpenOnReceiveTimeout)
     : base(processor, scopeFactory, plugins)
 {
     _concurrentAcceptSessionsSemaphore = concurrentAcceptSessionsSemaphore;
     _maxCallsPerSession     = maxCallsPerSession;
     _sessionReceiverOptions = new ServiceBusSessionReceiverOptions
     {
         ReceiveMode   = processor.Options.ReceiveMode,
         PrefetchCount = processor.Options.PrefetchCount,
     };
     _sessionId = sessionId;
     _keepOpenOnReceiveTimeout = keepOpenOnReceiveTimeout;
 }