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
     };
 }
예제 #2
0
 public ReceiverManager(
     ServiceBusConnection connection,
     string fullyQualifiedNamespace,
     string entityPath,
     string identifier,
     ServiceBusProcessorOptions processorOptions,
     Func <ProcessMessageEventArgs, Task> messageHandler,
     Func <ProcessErrorEventArgs, Task> errorHandler,
     EntityScopeFactory scopeFactory,
     IList <ServiceBusPlugin> plugins)
 {
     _connection = connection;
     _fullyQualifiedNamespace = fullyQualifiedNamespace;
     _entityPath       = entityPath;
     _processorOptions = processorOptions;
     _receiverOptions  = new ServiceBusReceiverOptions
     {
         ReceiveMode   = _processorOptions.ReceiveMode,
         PrefetchCount = _processorOptions.PrefetchCount
     };
     _maxReceiveWaitTime = _processorOptions.MaxReceiveWaitTime;
     _identifier         = identifier;
     _plugins            = plugins;
     Receiver            = new ServiceBusReceiver(
         connection: _connection,
         entityPath: _entityPath,
         isSessionEntity: false,
         plugins: _plugins,
         options: _receiverOptions);
     _errorHandler   = errorHandler;
     _messageHandler = messageHandler;
     _scopeFactory   = scopeFactory;
 }
예제 #3
0
 public ReceiverManager(
     ServiceBusProcessor processor,
     EntityScopeFactory scopeFactory,
     IList <ServiceBusPlugin> plugins)
 {
     Processor        = processor;
     ProcessorOptions = processor.Options;
     _receiverOptions = new ServiceBusReceiverOptions
     {
         ReceiveMode   = ProcessorOptions.ReceiveMode,
         PrefetchCount = ProcessorOptions.PrefetchCount,
         // Pass None for subqueue since the subqueue has already
         // been taken into account when computing the EntityPath of the processor.
         SubQueue = SubQueue.None
     };
     _maxReceiveWaitTime = ProcessorOptions.MaxReceiveWaitTime;
     _plugins            = plugins;
     Receiver            = new ServiceBusReceiver(
         connection: Processor.Connection,
         entityPath: Processor.EntityPath,
         isSessionEntity: false,
         isProcessor: true,
         plugins: _plugins,
         options: _receiverOptions);
     _scopeFactory = scopeFactory;
 }
예제 #4
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="topicName"></param>
 /// <param name="subscriptionName"></param>
 /// <param name="options"></param>
 /// <returns></returns>
 public ServiceBusProcessor GetProcessor(
     string topicName,
     string subscriptionName,
     ServiceBusProcessorOptions options) =>
 new ServiceBusProcessor(
     entityPath: EntityNameFormatter.FormatSubscriptionPath(topicName, subscriptionName),
     connection: Connection,
     isSessionEntity: false,
     options: options);
예제 #5
0
 /// <summary>
 ///
 /// </summary>
 /// <returns></returns>
 public ServiceBusProcessor GetSessionProcessor(
     string queueName,
     ServiceBusProcessorOptions options = default,
     string sessionId = default,
     CancellationToken cancellationToken = default) =>
 new ServiceBusProcessor(
     entityPath: queueName,
     connection: Connection,
     isSessionEntity: true,
     sessionId: sessionId,
     options: options ?? new ServiceBusProcessorOptions());
예제 #6
0
        /// <summary>
        /// Creates a <see cref="ServiceBusProcessor"/> instance that can be used to process messages using
        /// event handlers that are set on the processor.
        /// </summary>
        ///
        /// <param name="queueName">The queue to create a <see cref="ServiceBusProcessor"/> for.</param>
        /// <param name="options">The set of <see cref="ServiceBusProcessorOptions"/> to use for configuring the
        /// <see cref="ServiceBusProcessor"/>.</param>
        ///
        /// <returns>A <see cref="ServiceBusProcessor"/> scoped to the specified queue.</returns>
        public ServiceBusProcessor CreateProcessor(
            string queueName,
            ServiceBusProcessorOptions options)
        {
            ValidateEntityName(queueName);

            return(new ServiceBusProcessor(
                       entityPath: queueName,
                       connection: Connection,
                       isSessionEntity: false,
                       options: options));
        }
예제 #7
0
 /// <summary>
 ///
 /// </summary>
 /// <returns></returns>
 public ServiceBusProcessor GetSessionProcessor(
     string topicName,
     string subscriptionName,
     ServiceBusProcessorOptions options = default,
     string sessionId = default,
     CancellationToken cancellationToken = default) =>
 new ServiceBusProcessor(
     entityPath: EntityNameFormatter.FormatSubscriptionPath(topicName, subscriptionName),
     connection: Connection,
     isSessionEntity: true,
     sessionId: sessionId,
     options: options ?? new ServiceBusProcessorOptions());
예제 #8
0
        /// <summary>
        /// Creates a <see cref="ServiceBusSessionProcessor"/> instance that can be used to process session messages using
        /// event handlers that are set on the processor.
        /// </summary>
        ///
        /// <param name="queueName">The queue to create a <see cref="ServiceBusSessionProcessor"/> for.</param>
        /// <param name="options">The set of <see cref="ServiceBusProcessorOptions"/> to use for configuring the
        /// <see cref="ServiceBusSessionProcessor"/>.</param>
        /// <param name="sessionId">An optional session ID to scope the <see cref="ServiceBusSessionProcessor"/> to.
        /// If left blank, the next available session returned from the service will be used.</param>
        /// <returns>A <see cref="ServiceBusSessionProcessor"/> scoped to the specified queue.</returns>
        public ServiceBusSessionProcessor CreateSessionProcessor(
            string queueName,
            ServiceBusProcessorOptions options = default,
            string sessionId = default)
        {
            ValidateEntityName(queueName);

            return(new ServiceBusSessionProcessor(
                       entityPath: queueName,
                       connection: Connection,
                       sessionId: sessionId,
                       options: options ?? new ServiceBusProcessorOptions()));
        }
예제 #9
0
        /// <summary>
        /// Creates a <see cref="ServiceBusProcessor"/> instance that can be used to process messages using
        /// event handlers that are set on the processor.
        /// </summary>
        ///
        /// <param name="topicName">The topic to create a <see cref="ServiceBusProcessor"/> for.</param>
        /// <param name="subscriptionName">The subcription to create a <see cref="ServiceBusProcessor"/> for.</param>
        /// <param name="options">The set of <see cref="ServiceBusProcessorOptions"/> to use for configuring the
        /// <see cref="ServiceBusProcessor"/>.</param>
        ///
        /// <returns>A <see cref="ServiceBusProcessor"/> scoped to the specified topic and subscription.</returns>
        public ServiceBusProcessor CreateProcessor(
            string topicName,
            string subscriptionName,
            ServiceBusProcessorOptions options)
        {
            ValidateEntityName(topicName);

            return(new ServiceBusProcessor(
                       entityPath: EntityNameFormatter.FormatSubscriptionPath(topicName, subscriptionName),
                       connection: Connection,
                       isSessionEntity: false,
                       options: options));
        }
 internal ServiceBusSessionProcessor(
     ServiceBusConnection connection,
     string entityPath,
     ServiceBusProcessorOptions options,
     string sessionId = default)
 {
     _innerProcessor = new ServiceBusProcessor(
         connection,
         entityPath,
         true,
         options,
         sessionId);
 }
예제 #11
0
 internal ServiceBusSessionProcessor(
     ServiceBusConnection connection,
     string entityPath,
     ServiceBusProcessorOptions options,
     params string[] sessionIds)
 {
     _innerProcessor = new ServiceBusProcessor(
         connection,
         entityPath,
         true,
         options,
         sessionIds);
 }
예제 #12
0
        /// <summary>
        ///   Initializes a new instance of the <see cref="ServiceBusProcessor"/> class.
        /// </summary>
        ///
        /// <param name="connection">The <see cref="ServiceBusConnection" /> connection to use for communication with the Service Bus service.</param>
        /// <param name="entityPath">The queue name or subscription path to process messages from.</param>
        /// <param name="isSessionEntity">Whether or not the processor is associated with a session entity.</param>
        /// <param name="plugins">The set of plugins to apply to incoming messages.</param>
        /// <param name="options">The set of options to use when configuring the processor.</param>
        /// <param name="sessionIds">An optional set of session Ids to limit processing to.
        /// Only applies if isSessionEntity is true.</param>
        /// <param name="maxConcurrentSessions">The max number of sessions that can be processed concurrently.
        /// Only applies if isSessionEntity is true.</param>
        /// <param name="maxConcurrentCallsPerSession">The max number of concurrent calls per session.
        /// Only applies if isSessionEntity is true.</param>
        internal ServiceBusProcessor(
            ServiceBusConnection connection,
            string entityPath,
            bool isSessionEntity,
            IList <ServiceBusPlugin> plugins,
            ServiceBusProcessorOptions options,
            string[] sessionIds              = default,
            int maxConcurrentSessions        = default,
            int maxConcurrentCallsPerSession = default)
        {
            Argument.AssertNotNullOrWhiteSpace(entityPath, nameof(entityPath));
            Argument.AssertNotNull(connection, nameof(connection));
            Argument.AssertNotNull(connection.RetryOptions, nameof(connection.RetryOptions));
            connection.ThrowIfClosed();

            _options    = options?.Clone() ?? new ServiceBusProcessorOptions();
            _connection = connection;
            EntityPath  = entityPath;
            Identifier  = DiagnosticUtilities.GenerateIdentifier(EntityPath);

            ReceiveMode   = _options.ReceiveMode;
            PrefetchCount = _options.PrefetchCount;
            MaxAutoLockRenewalDuration   = _options.MaxAutoLockRenewalDuration;
            MaxConcurrentCalls           = _options.MaxConcurrentCalls;
            MaxConcurrentSessions        = maxConcurrentSessions;
            MaxConcurrentCallsPerSession = maxConcurrentCallsPerSession;
            _sessionIds = sessionIds ?? Array.Empty <string>();

            int maxCalls = isSessionEntity ?
                           (_sessionIds.Length > 0 ?
                            Math.Min(_sessionIds.Length, MaxConcurrentSessions) :
                            MaxConcurrentSessions) * MaxConcurrentCallsPerSession :
                           MaxConcurrentCalls;

            MessageHandlerSemaphore = new SemaphoreSlim(
                maxCalls,
                maxCalls);
            var maxAcceptSessions = Math.Min(maxCalls, 2 * Environment.ProcessorCount);

            MaxConcurrentAcceptSessionsSemaphore = new SemaphoreSlim(
                maxAcceptSessions,
                maxAcceptSessions);

            MaxReceiveWaitTime = _options.MaxReceiveWaitTime;
            AutoComplete       = _options.AutoComplete;

            EntityPath         = entityPath;
            IsSessionProcessor = isSessionEntity;
            _scopeFactory      = new EntityScopeFactory(EntityPath, FullyQualifiedNamespace);
            _plugins           = plugins;
        }
예제 #13
0
        /// <summary>
        /// Creates a <see cref="ServiceBusSessionProcessor"/> instance that can be used to process
        /// messages using event handlers that are set on the processor.
        /// </summary>
        ///
        /// <param name="topicName">The topic to create a <see cref="ServiceBusSessionProcessor"/> for.</param>
        /// <param name="subscriptionName">The subcription to create a <see cref="ServiceBusSessionProcessor"/> for.</param>
        /// <param name="options">The set of <see cref="ServiceBusSessionProcessor"/> to use for configuring the
        /// <see cref="ServiceBusSessionProcessor"/>.</param>
        /// <param name="sessionId">An optional session ID to scope the <see cref="ServiceBusSessionProcessor"/> to.
        /// If left blank, the next available session returned from the service will be used.</param>
        /// <returns>A <see cref="ServiceBusProcessor"/> scoped to the specified topic and subscription.</returns>
        public ServiceBusSessionProcessor CreateSessionProcessor(
            string topicName,
            string subscriptionName,
            ServiceBusProcessorOptions options = default,
            string sessionId = default)
        {
            ValidateEntityName(topicName);

            return(new ServiceBusSessionProcessor(
                       entityPath: EntityNameFormatter.FormatSubscriptionPath(topicName, subscriptionName),
                       connection: Connection,
                       sessionId: sessionId,
                       options: options ?? new ServiceBusProcessorOptions()));
        }
예제 #14
0
 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)
     : base(connection, fullyQualifiedNamespace, entityPath, identifier, processorOptions, default, errorHandler)
 {
     _sessionId           = sessionId;
     _sessionInitHandler  = sessionInitHandler;
     _sessionCloseHandler = sessionCloseHandler;
     _messageHandler      = messageHandler;
     _concurrentAcceptSessionsSemaphore = concurrentAcceptSessionsSemaphore;
 }
예제 #15
0
 public ReceiverManager(
     ServiceBusProcessor processor,
     EntityScopeFactory scopeFactory,
     IList <ServiceBusPlugin> plugins)
 {
     Processor        = processor;
     ProcessorOptions = processor.Options;
     _receiverOptions = new ServiceBusReceiverOptions
     {
         ReceiveMode   = ProcessorOptions.ReceiveMode,
         PrefetchCount = ProcessorOptions.PrefetchCount,
     };
     _maxReceiveWaitTime = ProcessorOptions.MaxReceiveWaitTime;
     _plugins            = plugins;
     Receiver            = new ServiceBusReceiver(
         connection: Processor.Connection,
         entityPath: Processor.EntityPath,
         isSessionEntity: false,
         plugins: _plugins,
         options: _receiverOptions);
     _scopeFactory = scopeFactory;
 }
예제 #16
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="queueName"></param>
 /// <param name="options"></param>
 /// <returns></returns>
 public ServiceBusProcessor GetProcessor(string queueName, ServiceBusProcessorOptions options) =>
 new ServiceBusProcessor(
     entityPath: queueName,
     connection: Connection,
     isSessionEntity: false,
     options: options);