示例#1
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="isSessionEntity"></param>
        /// <param name="options">A set of options to apply when configuring the consumer.</param>
        /// <param name="sessionId"></param>
        ///
        internal ServiceBusReceiver(
            ServiceBusConnection connection,
            string entityPath,
            bool isSessionEntity,
            ServiceBusReceiverOptions options,
            string sessionId = default)
        {
            Argument.AssertNotNull(connection, nameof(connection));
            Argument.AssertNotNull(connection.RetryOptions, nameof(connection.RetryOptions));
            Argument.AssertNotNullOrWhiteSpace(entityPath, nameof(entityPath));
            connection.ThrowIfClosed();

            options           = options?.Clone() ?? new ServiceBusReceiverOptions();
            Identifier        = DiagnosticUtilities.GenerateIdentifier(entityPath);
            _connection       = connection;
            _retryPolicy      = connection.RetryOptions.ToRetryPolicy();
            ReceiveMode       = options.ReceiveMode;
            PrefetchCount     = options.PrefetchCount;
            EntityPath        = entityPath;
            IsSessionReceiver = isSessionEntity;
            InnerReceiver     = _connection.CreateTransportReceiver(
                entityPath: EntityPath,
                retryPolicy: _retryPolicy,
                receiveMode: ReceiveMode,
                prefetchCount: (uint)PrefetchCount,
                identifier: Identifier,
                sessionId: sessionId,
                isSessionReceiver: IsSessionReceiver);
        }
 /// <summary>
 ///
 /// </summary>
 /// <returns></returns>
 internal static ServiceBusReceiver CreateReceiver(
     string queueName,
     ServiceBusConnection connection,
     ServiceBusReceiverOptions options = default)
 {
     options = options?.Clone() ?? new ServiceBusReceiverOptions();
     return(new ServiceBusReceiver(
                connection: connection,
                entityName: queueName,
                isSessionEntity: false,
                options: options));
 }
示例#3
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="isSessionEntity"></param>
        /// <param name="plugins">The 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 scope the receiver to. If not specified,
        /// the next available session returned from the service will be used.</param>
        ///
        internal ServiceBusReceiver(
            ServiceBusConnection connection,
            string entityPath,
            bool isSessionEntity,
            IList <ServiceBusPlugin> plugins,
            ServiceBusReceiverOptions options,
            string sessionId = default)
        {
            Type type = GetType();

            Logger.ClientCreateStart(type, connection?.FullyQualifiedNamespace, entityPath);
            try
            {
                Argument.AssertNotNull(connection, nameof(connection));
                Argument.AssertNotNull(connection.RetryOptions, nameof(connection.RetryOptions));
                Argument.AssertNotNullOrWhiteSpace(entityPath, nameof(entityPath));
                connection.ThrowIfClosed();
                options           = options?.Clone() ?? new ServiceBusReceiverOptions();
                Identifier        = DiagnosticUtilities.GenerateIdentifier(entityPath);
                _connection       = connection;
                _retryPolicy      = connection.RetryOptions.ToRetryPolicy();
                ReceiveMode       = options.ReceiveMode;
                PrefetchCount     = options.PrefetchCount;
                EntityPath        = entityPath;
                IsSessionReceiver = isSessionEntity;
                _innerReceiver    = _connection.CreateTransportReceiver(
                    entityPath: EntityPath,
                    retryPolicy: _retryPolicy,
                    receiveMode: ReceiveMode,
                    prefetchCount: (uint)PrefetchCount,
                    identifier: Identifier,
                    sessionId: sessionId,
                    isSessionReceiver: IsSessionReceiver);
                _scopeFactory = new EntityScopeFactory(EntityPath, FullyQualifiedNamespace);
                _plugins      = plugins;
                if (!isSessionEntity)
                {
                    // don't log client completion for session receiver here as it is not complete until
                    // the link is opened.
                    Logger.ClientCreateComplete(type, Identifier);
                }
            }
            catch (Exception ex)
            {
                Logger.ClientCreateException(type, connection?.FullyQualifiedNamespace, entityPath, ex);
                throw;
            }
        }
        /// <summary>
        ///
        /// </summary>
        /// <returns></returns>
        internal static async Task <ServiceBusReceiver> CreateSessionReceiverAsync(
            string queueName,
            ServiceBusConnection connection,
            string sessionId = default,
            ServiceBusReceiverOptions options   = default,
            CancellationToken cancellationToken = default)
        {
            options = options?.Clone() ?? new ServiceBusReceiverOptions();

            var receiver = new ServiceBusReceiver(
                connection: connection,
                entityName: queueName,
                isSessionEntity: true,
                sessionId: sessionId,
                options: options);
            await receiver.OpenLinkAsync(cancellationToken).ConfigureAwait(false);

            return(receiver);
        }