예제 #1
0
        /// <summary>
        ///   Creates a size-constraint batch to which <see cref="ServiceBusMessage" /> may be added using a try-based pattern.  If a message would
        ///   exceed the maximum allowable size of the batch, the batch will not allow adding the message and signal that scenario using its
        ///   return value.
        ///
        ///   Because messages that would violate the size constraint cannot be added, publishing a batch will not trigger an exception when
        ///   attempting to send the messages to the Queue/Topic.
        /// </summary>
        ///
        /// <param name="options">The set of options to consider when creating this batch.</param>
        /// <param name="cancellationToken">An optional <see cref="CancellationToken"/> instance to signal the request to cancel the operation.</param>
        ///
        /// <returns>An <see cref="ServiceBusMessageBatch" /> with the requested <paramref name="options"/>.</returns>
        ///
        /// <seealso cref="CreateBatchAsync(CreateBatchOptions, CancellationToken)" />
        ///
        public virtual async ValueTask <ServiceBusMessageBatch> CreateBatchAsync(
            CreateBatchOptions options,
            CancellationToken cancellationToken = default)
        {
            Argument.AssertNotClosed(IsDisposed, nameof(ServiceBusSender));
            options = options?.Clone() ?? new CreateBatchOptions();
            cancellationToken.ThrowIfCancellationRequested <TaskCanceledException>();
            ServiceBusEventSource.Log.CreateMessageBatchStart(Identifier);
            ServiceBusMessageBatch batch;

            try
            {
                TransportMessageBatch transportBatch = await _innerSender.CreateBatchAsync(options, cancellationToken).ConfigureAwait(false);

                batch = new ServiceBusMessageBatch(transportBatch);
            }
            catch (Exception ex)
            {
                ServiceBusEventSource.Log.CreateMessageBatchException(Identifier, ex);
                throw;
            }
            cancellationToken.ThrowIfCancellationRequested <TaskCanceledException>();
            ServiceBusEventSource.Log.CreateMessageBatchComplete(Identifier);
            return(batch);
        }
        /// <summary>
        ///   Creates a size-constraint batch to which <see cref="ServiceBusMessage" /> may be added using a try-based pattern.  If a message would
        ///   exceed the maximum allowable size of the batch, the batch will not allow adding the message and signal that scenario using its
        ///   return value.
        ///
        ///   Because messages that would violate the size constraint cannot be added, publishing a batch will not trigger an exception when
        ///   attempting to send the messages to the Queue/Topic.
        /// </summary>
        ///
        /// <param name="options">The set of options to consider when creating this batch.</param>
        /// <param name="cancellationToken">An optional <see cref="CancellationToken"/> instance to signal the request to cancel the operation.</param>
        ///
        /// <returns>An <see cref="ServiceBusMessageBatch" /> with the requested <paramref name="options"/>.</returns>
        ///
        /// <seealso cref="CreateBatchAsync(CreateBatchOptions, CancellationToken)" />
        ///
        public virtual async ValueTask <ServiceBusMessageBatch> CreateBatchAsync(
            CreateBatchOptions options,
            CancellationToken cancellationToken = default)
        {
            options = options?.Clone() ?? new CreateBatchOptions();

            TransportMessageBatch transportBatch = await _innerSender.CreateBatchAsync(options, cancellationToken).ConfigureAwait(false);

            return(new ServiceBusMessageBatch(transportBatch));
        }
예제 #3
0
        /// <summary>
        ///   Creates a size-constraint batch to which <see cref="ServiceBusMessage" /> may be added using a try-based pattern.  If a message would
        ///   exceed the maximum allowable size of the batch, the batch will not allow adding the message and signal that scenario using its
        ///   return value.
        ///
        ///   Because messages that would violate the size constraint cannot be added, publishing a batch will not trigger an exception when
        ///   attempting to send the message to the Queue/Topic.
        /// </summary>
        ///
        /// <param name="options">The set of options to consider when creating this batch.</param>
        /// <param name="cancellationToken">An optional <see cref="CancellationToken"/> instance to signal the request to cancel the operation.</param>
        ///
        /// <returns>An <see cref="ServiceBusMessageBatch" /> with the requested <paramref name="options"/>.</returns>
        ///
        public override async ValueTask <TransportMessageBatch> CreateBatchAsync(
            CreateBatchOptions options,
            CancellationToken cancellationToken)
        {
            TransportMessageBatch messageBatch = null;
            Task createBatchTask = _retryPolicy.RunOperation(async(timeout) =>
            {
                messageBatch = await CreateBatchInternalAsync(
                    options,
                    timeout).ConfigureAwait(false);
            },
                                                             _connectionScope,
                                                             cancellationToken);
            await createBatchTask.ConfigureAwait(false);

            return(messageBatch);
        }
 /// <summary>
 ///   Initializes a new instance of the <see cref="ServiceBusMessageBatch"/> class.
 /// </summary>
 ///
 /// <param name="transportBatch">The  transport-specific batch responsible for performing the batch operations.</param>
 /// <param name="entityScope">The entity scope used for instrumentation.</param>
 ///
 /// <remarks>
 ///   As an internal type, this class performs only basic sanity checks against its arguments.  It
 ///   is assumed that callers are trusted and have performed deep validation.
 ///
 ///   Any parameters passed are assumed to be owned by this instance and safe to mutate or dispose;
 ///   creation of clones or otherwise protecting the parameters is assumed to be the purview of the
 ///   caller.
 /// </remarks>
 ///
 internal ServiceBusMessageBatch(TransportMessageBatch transportBatch, EntityScopeFactory entityScope)
 {
     Argument.AssertNotNull(transportBatch, nameof(transportBatch));
     _innerBatch   = transportBatch;
     _scopeFactory = entityScope;
 }
 /// <summary>
 ///   Initializes a new instance of the <see cref="ServiceBusMessageBatch"/> class.
 /// </summary>
 ///
 /// <param name="transportBatch">The  transport-specific batch responsible for performing the batch operations.</param>
 ///
 /// <remarks>
 ///   As an internal type, this class performs only basic sanity checks against its arguments.  It
 ///   is assumed that callers are trusted and have performed deep validation.
 ///
 ///   Any parameters passed are assumed to be owned by this instance and safe to mutate or dispose;
 ///   creation of clones or otherwise protecting the parameters is assumed to be the purview of the
 ///   caller.
 /// </remarks>
 ///
 internal ServiceBusMessageBatch(TransportMessageBatch transportBatch)
 {
     Argument.AssertNotNull(transportBatch, nameof(transportBatch));
     InnerBatch = transportBatch;
 }