/// <summary>
        ///   Sends a set of messages to the associated Service Bus entity using a batched approach.
        ///   If the size of the messages exceed the maximum size of a single batch,
        ///   an exception will be triggered and the send will fail. In order to ensure that the messages
        ///   being sent will fit in a batch, use <see cref="SendAsync(ServiceBusMessageBatch, CancellationToken)"/> instead.
        /// </summary>
        ///
        /// <param name="messages">The set of messages to send.</param>
        /// <param name="cancellationToken">An optional <see cref="CancellationToken"/> instance to signal the request to cancel the operation.</param>
        ///
        /// <returns>A task to be resolved on when the operation has completed.</returns>
        ///
        public virtual async Task SendAsync(
            IEnumerable <ServiceBusMessage> messages,
            CancellationToken cancellationToken = default)
        {
            Argument.AssertNotNull(messages, nameof(messages));
            Argument.AssertNotClosed(IsDisposed, nameof(ServiceBusSender));
            IList <ServiceBusMessage> messageList = messages.ToList();

            if (messageList.Count == 0)
            {
                return;
            }

            cancellationToken.ThrowIfCancellationRequested <TaskCanceledException>();
            ServiceBusEventSource.Log.SendMessageStart(Identifier, messageCount: messageList.Count);
            try
            {
                await _innerSender.SendAsync(
                    messageList,
                    cancellationToken).ConfigureAwait(false);
            }
            catch (Exception ex)
            {
                ServiceBusEventSource.Log.SendMessageException(Identifier, ex);
                throw;
            }
            cancellationToken.ThrowIfCancellationRequested <TaskCanceledException>();
            ServiceBusEventSource.Log.SendMessageComplete(Identifier);
        }
Пример #2
0
        /// <summary>
        ///   Sends a set of messages to the associated Service Bus entity using a batched approach.
        ///   If the size of the messages exceed the maximum size of a single batch,
        ///   an exception will be triggered and the send will fail. In order to ensure that the messages
        ///   being sent will fit in a batch, use <see cref="SendAsync(ServiceBusMessageBatch, CancellationToken)"/> instead.
        /// </summary>
        ///
        /// <param name="messages">The set of messages to send.</param>
        /// <param name="cancellationToken">An optional <see cref="CancellationToken"/> instance to signal the request to cancel the operation.</param>
        ///
        /// <returns>A task to be resolved on when the operation has completed.</returns>
        ///
        public virtual async Task SendAsync(
            IEnumerable <ServiceBusMessage> messages,
            CancellationToken cancellationToken = default)
        {
            Argument.AssertNotNull(messages, nameof(messages));
            Argument.AssertNotClosed(IsDisposed, nameof(ServiceBusSender));
            IList <ServiceBusMessage> messageList = messages.ToList();

            if (messageList.Count == 0)
            {
                return;
            }

            cancellationToken.ThrowIfCancellationRequested <TaskCanceledException>();
            Logger.SendMessageStart(Identifier, messageCount: messageList.Count);
            using DiagnosticScope scope = CreateDiagnosticScope(messages, DiagnosticProperty.SendActivityName);
            scope.Start();

            try
            {
                await _innerSender.SendAsync(
                    messageList,
                    cancellationToken).ConfigureAwait(false);
            }

            catch (Exception exception)
            {
                Logger.SendMessageException(Identifier, exception.ToString());
                scope.Failed(exception);
                throw;
            }
            cancellationToken.ThrowIfCancellationRequested <TaskCanceledException>();
            Logger.SendMessageComplete(Identifier);
        }
 /// <summary>
 ///   Sends a message to the associated entity of Service Bus.
 /// </summary>
 ///
 /// <param name="message">A messsage to send.</param>
 /// <param name="cancellationToken">An optional <see cref="CancellationToken"/> instance to signal the request to cancel the operation.</param>
 ///
 /// <returns>A task to be resolved on when the operation has completed.</returns>
 ///
 public virtual async Task SendAsync(
     ServiceBusMessage message,
     CancellationToken cancellationToken = default)
 {
     Argument.AssertNotNull(message, nameof(message));
     await _innerSender.SendAsync(message, cancellationToken).ConfigureAwait(false);
 }
Пример #4
0
 /// <summary>
 ///   Sends a message to the associated entity of Service Bus.
 /// </summary>
 ///
 /// <param name="message">A messsage to send.</param>
 /// <param name="cancellationToken">An optional <see cref="CancellationToken"/> instance to signal the request to cancel the operation.</param>
 ///
 /// <returns>A task to be resolved on when the operation has completed.</returns>
 ///
 public virtual async Task SendAsync(
     ServiceBusMessage message,
     CancellationToken cancellationToken = default)
 {
     Argument.AssertNotNull(message, nameof(message));
     Argument.AssertNotClosed(IsDisposed, nameof(ServiceBusSender));
     cancellationToken.ThrowIfCancellationRequested <TaskCanceledException>();
     ServiceBusEventSource.Log.SendMessageStart(Identifier, messageCount: 1);
     try
     {
         await _innerSender.SendAsync(message, cancellationToken).ConfigureAwait(false);
     }
     catch (Exception ex)
     {
         ServiceBusEventSource.Log.SendMessageException(Identifier, ex);
         throw;
     }
     cancellationToken.ThrowIfCancellationRequested <TaskCanceledException>();
     ServiceBusEventSource.Log.SendMessageComplete(Identifier);
 }