Example #1
0
        /// <summary>
        ///   Creates the AMQP link to be used for producer-related operations and ensures
        ///   that the corresponding state for the producer has been updated based on the link
        ///   configuration.
        /// </summary>
        ///
        /// <param name="timeout">The timeout to apply when creating the link.</param>
        /// <param name="cancellationToken">The cancellation token to consider when creating the link.</param>
        ///
        /// <returns>The AMQP link to use for producer-related operations.</returns>
        ///
        /// <remarks>
        ///   This method will modify class-level state, setting those attributes that depend on the AMQP
        ///   link configuration.  There exists a benign race condition in doing so, as there may be multiple
        ///   concurrent callers.  In this case, the attributes may be set multiple times but the resulting
        ///   value will be the same.
        /// </remarks>
        ///
        protected virtual async Task <SendingAmqpLink> CreateLinkAndEnsureSenderStateAsync(
            TimeSpan timeout,
            CancellationToken cancellationToken)
        {
            SendingAmqpLink link = await _connectionScope.OpenSenderLinkAsync(
                _entityPath,
                timeout,
                cancellationToken).ConfigureAwait(false);

            if (!MaximumMessageSize.HasValue)
            {
                // This delay is necessary to prevent the link from causing issues for subsequent
                // operations after creating a batch.  Without it, operations using the link consistently
                // timeout.  The length of the delay does not appear significant, just the act of introducing
                // an asynchronous delay.
                //
                // For consistency the value used by the legacy Service Bus client has been brought forward and
                // used here.

                await Task.Delay(15, cancellationToken).ConfigureAwait(false);

                MaximumMessageSize = (long)link.Settings.MaxMessageSize;
            }

            return(link);
        }
Example #2
0
        /// <summary>
        ///   Creates the AMQP link to be used for sender-related operations and ensures
        ///   that the corresponding state for the sender has been updated based on the link
        ///   configuration.
        /// </summary>
        ///
        /// <param name="timeout">The timeout to apply when creating the link.</param>
        /// <param name="transactionGroup"></param>
        /// <param name="cancellationToken">The cancellation token to consider when creating the link.</param>
        ///
        /// <returns>The AMQP link to use for sender-related operations.</returns>
        ///
        /// <remarks>
        ///   This method will modify class-level state, setting those attributes that depend on the AMQP
        ///   link configuration.  There exists a benign race condition in doing so, as there may be multiple
        ///   concurrent callers.  In this case, the attributes may be set multiple times but the resulting
        ///   value will be the same.
        /// </remarks>
        ///
        protected virtual async Task <SendingAmqpLink> CreateLinkAndEnsureSenderStateAsync(
            TimeSpan timeout,
            string transactionGroup,
            CancellationToken cancellationToken)
        {
            ServiceBusEventSource.Log.CreateSendLinkStart(_identifier);
            try
            {
                SendingAmqpLink link = await _connectionScope.OpenSenderLinkAsync(
                    entityPath : _entityPath,
                    identifier : _identifier,
                    timeout : timeout,
                    transactionGroup : transactionGroup,
                    cancellationToken : cancellationToken).ConfigureAwait(false);

                if (!MaxMessageSize.HasValue)
                {
                    // This delay is necessary to prevent the link from causing issues for subsequent
                    // operations after creating a batch.  Without it, operations using the link consistently
                    // timeout.  The length of the delay does not appear significant, just the act of introducing
                    // an asynchronous delay.
                    //
                    // For consistency the value used by the legacy Service Bus client has been brought forward and
                    // used here.

                    await Task.Delay(15, cancellationToken).ConfigureAwait(false);

                    MaxMessageSize = (long)link.Settings.MaxMessageSize;
                }
                ServiceBusEventSource.Log.CreateSendLinkComplete(_identifier);
                link.Closed += OnSenderLinkClosed;
                return(link);
            }
            catch (Exception ex)
            {
                ServiceBusEventSource.Log.CreateSendLinkException(_identifier, ex.ToString());
                throw;
            }
        }