Ejemplo n.º 1
0
 /// <summary>
 /// Cancels a message that was scheduled.
 /// </summary>
 /// <param name="sequenceNumber">The <see cref="ServiceBusMessage.SystemPropertiesCollection.SequenceNumber"/> of the message to be cancelled.</param>
 /// <param name="retryPolicy"></param>
 /// <param name="sendLinkName"></param>
 /// <param name="cancellationToken"></param>
 internal async Task CancelScheduledMessageAsync(
     long sequenceNumber,
     ServiceBusRetryPolicy retryPolicy,
     string sendLinkName = null,
     CancellationToken cancellationToken = default) =>
 await InnerClient.CancelScheduledMessageAsync(sequenceNumber, retryPolicy, sendLinkName, cancellationToken)
 .ConfigureAwait(false);
 internal ServiceBusSession(
     TransportConsumer consumer,
     ServiceBusRetryPolicy retryPolicy)
 {
     _consumer    = consumer;
     _retryPolicy = retryPolicy;
 }
Ejemplo n.º 3
0
        /// <summary>
        ///   Initializes a new instance of the <see cref="ServiceBusSender"/> class.
        /// </summary>
        /// <param name="entityPath">The entity path to send the message to.</param>
        /// <param name="options">The set of <see cref="ServiceBusSenderOptions"/> to use for configuring
        /// this <see cref="ServiceBusSender"/>.</param>
        /// <param name="connection">The connection for the sender.</param>
        ///
        internal ServiceBusSender(
            string entityPath,
            ServiceBusSenderOptions options,
            ServiceBusConnection connection)
        {
            Logger.ClientCreateStart(typeof(ServiceBusSender), 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 ServiceBusSenderOptions();
                EntityPath    = entityPath;
                ViaEntityPath = options.ViaQueueOrTopicName;
                Identifier    = DiagnosticUtilities.GenerateIdentifier(EntityPath);
                _connection   = connection;
                _retryPolicy  = _connection.RetryOptions.ToRetryPolicy();
                _innerSender  = _connection.CreateTransportSender(
                    entityPath,
                    ViaEntityPath,
                    _retryPolicy,
                    Identifier);
                _scopeFactory = new EntityScopeFactory(EntityPath, FullyQualifiedNamespace);
            }
            catch (Exception ex)
            {
                Logger.ClientCreateException(typeof(ServiceBusSender), connection?.FullyQualifiedNamespace, entityPath, ex);
                throw;
            }
            Logger.ClientCreateComplete(typeof(ServiceBusSender), Identifier);
        }
Ejemplo n.º 4
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="message"></param>
 /// <param name="retryPolicy"></param>
 /// <param name="sendLinkName"></param>
 /// <param name="cancellationToken"></param>
 /// <returns></returns>
 internal async Task <long> ScheduleMessageAsync(
     ServiceBusMessage message,
     ServiceBusRetryPolicy retryPolicy,
     string sendLinkName = null,
     CancellationToken cancellationToken = default) =>
 await InnerClient.ScheduleMessageAsync(message, retryPolicy, sendLinkName, cancellationToken)
 .ConfigureAwait(false);
Ejemplo 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="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>
 ///   Creates a consumer strongly aligned with the active protocol and transport, responsible
 ///   for reading <see cref="ServiceBusMessage" /> from a specific Service Bus entity partition, in the context
 ///   of a specific consumer group.
 ///
 ///   A consumer may be exclusive, which asserts ownership over the partition for the consumer
 ///   group to ensure that only one consumer from that group is reading the from the partition.
 ///   These exclusive consumers are sometimes referred to as "Epoch Consumers."
 ///
 ///   A consumer may also be non-exclusive, allowing multiple consumers from the same consumer
 ///   group to be actively reading events from the partition.  These non-exclusive consumers are
 ///   sometimes referred to as "Non-epoch Consumers."
 ///
 ///   Designating a consumer as exclusive may be specified by setting the <paramref name="ownerLevel" />.
 ///   When <c>null</c>, consumers are created as non-exclusive.
 /// </summary>
 ///
 /// <param name="retryPolicy">The policy which governs retry behavior and try timeouts.</param>
 /// <param name="ownerLevel">The relative priority to associate with the link; for a non-exclusive link, this value should be <c>null</c>.</param>
 /// <param name="prefetchCount">Controls the number of events received and queued locally without regard to whether an operation was requested.  If <c>null</c> a default will be used.</param>
 /// <param name="sessionId"></param>
 ///
 /// <returns>A <see cref="TransportConsumer" /> configured in the requested manner.</returns>
 ///
 internal virtual TransportConsumer CreateTransportConsumer(
     ServiceBusRetryPolicy retryPolicy,
     long?ownerLevel    = default,
     uint?prefetchCount = default,
     string sessionId   = default)
 {
     Argument.AssertNotNull(retryPolicy, nameof(retryPolicy));
     return(InnerClient.CreateConsumer(retryPolicy, ownerLevel, prefetchCount, sessionId));
 }
 /// <summary>
 ///
 /// </summary>
 /// <param name="retryPolicy"></param>
 /// <param name="fromSequenceNumber"></param>
 /// <param name="messageCount"></param>
 /// <param name="sessionId"></param>
 /// <param name="receiveLinkName"></param>
 /// <param name="cancellationToken"></param>
 /// <returns></returns>
 internal virtual async Task <IEnumerable <ServiceBusMessage> > PeekAsync(
     ServiceBusRetryPolicy retryPolicy,
     long?fromSequenceNumber,
     int messageCount       = 1,
     string sessionId       = null,
     string receiveLinkName = null,
     CancellationToken cancellationToken = default) =>
 await InnerClient.PeekAsync(retryPolicy, fromSequenceNumber, messageCount, sessionId, receiveLinkName, cancellationToken)
 .ConfigureAwait(false);
Ejemplo n.º 8
0
 /// <summary>
 ///   Creates a consumer strongly aligned with the active protocol and transport, responsible
 ///   for reading <see cref="ServiceBusMessage" /> from a specific Service Bus entity.
 /// </summary>
 ///
 /// <param name="retryPolicy">The policy which governs retry behavior and try timeouts.</param>
 /// <param name="receiveMode">The <see cref="ReceiveMode"/> used to specify how messages are received. Defaults to PeekLock mode.</param>
 /// <param name="prefetchCount">Controls the number of events received and queued locally without regard to whether an operation was requested.  If <c>null</c> a default will be used.</param>
 /// <param name="sessionId"></param>
 /// <param name="isSessionReceiver"></param>
 ///
 /// <returns>A <see cref="TransportConsumer" /> configured in the requested manner.</returns>
 ///
 internal virtual TransportConsumer CreateTransportConsumer(
     ServiceBusRetryPolicy retryPolicy,
     ReceiveMode receiveMode = default,
     uint?prefetchCount      = default,
     string sessionId        = default,
     bool isSessionReceiver  = default)
 {
     Argument.AssertNotNull(retryPolicy, nameof(retryPolicy));
     return(InnerClient.CreateConsumer(retryPolicy, receiveMode, prefetchCount, sessionId, isSessionReceiver));
 }
 internal TransportReceiver CreateTransportReceiver(
     string entityName,
     ServiceBusRetryPolicy retryPolicy,
     ReceiveMode receiveMode,
     uint prefetchCount,
     string sessionId       = default,
     bool isSessionReceiver = default) =>
 _innerClient.CreateReceiver(
     entityName,
     retryPolicy,
     receiveMode,
     prefetchCount,
     sessionId,
     isSessionReceiver);
Ejemplo n.º 10
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;
            }
        }
 internal virtual TransportReceiver CreateTransportReceiver(
     string entityPath,
     ServiceBusRetryPolicy retryPolicy,
     ServiceBusReceiveMode receiveMode,
     uint prefetchCount,
     string identifier,
     string sessionId,
     bool isSessionReceiver) =>
 _innerClient.CreateReceiver(
     entityPath,
     retryPolicy,
     receiveMode,
     prefetchCount,
     identifier,
     sessionId,
     isSessionReceiver);
Ejemplo n.º 12
0
        /// <summary>
        ///   Initializes a new instance of the <see cref="ServiceBusSender"/> class.
        /// </summary>
        /// <param name="entityPath">The entity path to send the message to.</param>
        /// <param name="connection">The connection for the sender.</param>
        ///
        internal ServiceBusSender(
            string entityPath,
            ServiceBusConnection connection)
        {
            Argument.AssertNotNull(connection, nameof(connection));
            Argument.AssertNotNull(connection.RetryOptions, nameof(connection.RetryOptions));
            Argument.AssertNotNullOrWhiteSpace(entityPath, nameof(entityPath));
            connection.ThrowIfClosed();

            EntityPath   = entityPath;
            Identifier   = DiagnosticUtilities.GenerateIdentifier(EntityPath);
            _connection  = connection;
            _retryPolicy = _connection.RetryOptions.ToRetryPolicy();
            _innerSender = _connection.CreateTransportSender(
                entityPath,
                _retryPolicy);
        }
        /// <summary>
        ///   Initializes a new instance of the <see cref="ServiceBusSender"/> class.
        /// </summary>
        /// <param name="connection"></param>
        /// <param name="options">A set of options to apply when configuring the producer.</param>
        /// <param name="entityName"></param>
        /// <remarks>
        ///   If the connection string is copied from the Service Bus entity itself, it will contain the name of the desired Service Bus entity,
        ///   and can be used directly without passing the  name="entityName" />.  The name of the Service Bus entity should be
        ///   passed only once, either as part of the connection string or separately.
        /// </remarks>
        ///
        internal ServiceBusSender(
            ServiceBusConnection connection,
            ServiceBusSenderOptions options,
            string entityName)
        {
            if (entityName == null)
            {
                throw new ArgumentException();
            }

            options           = options?.Clone() ?? new ServiceBusSenderOptions();
            ClientDiagnostics = new ClientDiagnostics(options);
            OwnsConnection    = false;
            EntityName        = entityName;
            _connection       = connection;
            _retryPolicy      = options.RetryOptions.ToRetryPolicy();
            _innerSender      = _connection.CreateTransportSender(
                entityName,
                _retryPolicy);
        }
Ejemplo n.º 14
0
 internal virtual TransportReceiver CreateTransportReceiver(
     string entityPath,
     ServiceBusRetryPolicy retryPolicy,
     ServiceBusReceiveMode receiveMode,
     uint prefetchCount,
     string identifier,
     string sessionId,
     bool isSessionReceiver,
     bool isProcessor,
     CancellationToken cancellationToken) =>
 InnerClient.CreateReceiver(
     entityPath,
     retryPolicy,
     receiveMode,
     prefetchCount,
     identifier,
     sessionId,
     isSessionReceiver,
     isProcessor,
     cancellationToken);
Ejemplo n.º 15
0
 /// <summary>
 ///   Creates a producer strongly aligned with the active protocol and transport,
 ///   responsible for publishing <see cref="ServiceBusMessage" /> to the Service Bus entity.
 /// </summary>
 ///
 /// <param name="retryPolicy">The policy which governs retry behavior and try timeouts.</param>
 ///
 /// <returns>A <see cref="TransportSender"/> configured in the requested manner.</returns>
 ///
 internal virtual TransportSender CreateTransportProducer(ServiceBusRetryPolicy retryPolicy)
 {
     Argument.AssertNotNull(retryPolicy, nameof(retryPolicy));
     return(InnerClient.CreateSender(retryPolicy));
 }
 internal TransportSender CreateTransportSender(string entityName, ServiceBusRetryPolicy retryPolicy) =>
 _innerClient.CreateSender(entityName, retryPolicy);
 internal virtual TransportSender CreateTransportSender(
     string entityPath,
     string viaEntityPath,
     ServiceBusRetryPolicy retryPolicy) =>
 _innerClient.CreateSender(entityPath, viaEntityPath, retryPolicy);
 internal virtual TransportSender CreateTransportSender(
     string entityPath,
     ServiceBusRetryPolicy retryPolicy,
     string identifier) =>
 _innerClient.CreateSender(entityPath, retryPolicy, identifier);
Ejemplo n.º 19
0
 internal virtual TransportRuleManager CreateTransportRuleManager(
     string subscriptionPath,
     ServiceBusRetryPolicy retryPolicy,
     string identifier) =>
 InnerClient.CreateRuleManager(subscriptionPath, retryPolicy, identifier);
 internal virtual TransportRuleManager CreateTransportRuleManager(
     string subscriptionPath,
     ServiceBusRetryPolicy retryPolicy) =>
 _innerClient.CreateRuleManager(subscriptionPath, retryPolicy);