/// <summary>
        /// Schedules a message to appear on Service Bus at a later time.
        /// </summary>
        ///
        /// <param name="message">The message to schedule.</param>
        /// <param name="scheduledEnqueueTime">The UTC time at which the message should be available for processing</param>
        /// <param name="cancellationToken">An optional <see cref="CancellationToken"/> instance to signal the request to cancel the operation.</param>
        ///
        /// <remarks>Although the message will not be available to be received until the scheduledEnqueueTime, it can still be peeked before that time.</remarks>
        /// <returns>The sequence number of the message that was scheduled.</returns>
        public virtual async Task <long> ScheduleMessageAsync(
            ServiceBusMessage message,
            DateTimeOffset scheduledEnqueueTime,
            CancellationToken cancellationToken = default)
        {
            Argument.AssertNotNull(message, nameof(message));
            Argument.AssertNotClosed(IsDisposed, nameof(ServiceBusSender));
            cancellationToken.ThrowIfCancellationRequested <TaskCanceledException>();
            Logger.ScheduleMessageStart(Identifier, scheduledEnqueueTime.ToString());
            using DiagnosticScope scope = CreateDiagnosticScope(
                      new ServiceBusMessage[] { message },
                      DiagnosticProperty.ScheduleActivityName);
            scope.Start();

            long sequenceNumber;

            try
            {
                message.ScheduledEnqueueTime = scheduledEnqueueTime.UtcDateTime;
                sequenceNumber = await _innerSender.ScheduleMessageAsync(message, cancellationToken).ConfigureAwait(false);
            }
            catch (Exception exception)
            {
                Logger.ScheduleMessageException(Identifier, exception.ToString());
                scope.Failed(exception);
                throw;
            }

            cancellationToken.ThrowIfCancellationRequested <TaskCanceledException>();
            Logger.ScheduleMessageComplete(Identifier);
            scope.AddAttribute(DiagnosticProperty.SequenceNumbersAttribute, sequenceNumber);
            return(sequenceNumber);
        }
Beispiel #2
0
        /// <summary>
        /// Schedules a message to appear on Service Bus at a later time.
        /// </summary>
        ///
        /// <param name="message">The message to schedule.</param>
        /// <param name="scheduledEnqueueTime">The UTC time at which the message should be available for processing</param>
        /// <param name="cancellationToken">An optional <see cref="CancellationToken"/> instance to signal the request to cancel the operation.</param>
        ///
        /// <remarks>Although the message will not be available to be received until the scheduledEnqueueTime, it can still be peeked before that time.</remarks>
        /// <returns>The sequence number of the message that was scheduled.</returns>
        public virtual async Task <long> ScheduleMessageAsync(
            ServiceBusMessage message,
            DateTimeOffset scheduledEnqueueTime,
            CancellationToken cancellationToken = default)
        {
            Argument.AssertNotNull(message, nameof(message));
            Argument.AssertNotClosed(IsDisposed, nameof(ServiceBusSender));
            cancellationToken.ThrowIfCancellationRequested <TaskCanceledException>();
            ServiceBusEventSource.Log.ScheduleMessageStart(Identifier, scheduledEnqueueTime);

            long sequenceNumber;

            try
            {
                message.ScheduledEnqueueTime = scheduledEnqueueTime.UtcDateTime;
                sequenceNumber = await _innerSender.ScheduleMessageAsync(message, cancellationToken).ConfigureAwait(false);
            }
            catch (Exception ex)
            {
                ServiceBusEventSource.Log.ScheduleMessageException(Identifier, ex);
                throw;
            }

            cancellationToken.ThrowIfCancellationRequested <TaskCanceledException>();
            ServiceBusEventSource.Log.ScheduleMessageComplete(Identifier);
            return(sequenceNumber);
        }
 /// <summary>
 /// Schedules a message to appear on Service Bus at a later time.
 /// </summary>
 /// <param name="message"></param>
 /// <param name="scheduleEnqueueTimeUtc">The UTC time at which the message should be available for processing</param>
 /// <param name="cancellationToken"></param>
 /// <returns>The sequence number of the message that was scheduled.</returns>
 public virtual async Task <long> ScheduleMessageAsync(
     ServiceBusMessage message,
     DateTimeOffset scheduleEnqueueTimeUtc,
     CancellationToken cancellationToken = default)
 {
     //this.ThrowIfClosed();
     Argument.AssertNotNull(message, nameof(message));
     message.ScheduledEnqueueTimeUtc = scheduleEnqueueTimeUtc.UtcDateTime;
     return(await _innerSender.ScheduleMessageAsync(message, cancellationToken).ConfigureAwait(false));
 }