/// <summary> /// Sends a set of events to the associated Event Hub using a batched approach. If the size of events exceed the /// maximum size of a single batch, an exception will be triggered and the send will fail. /// </summary> /// /// <param name="events">The set of event data to send.</param> /// <param name="sendOptions">The set of options to consider when sending this batch.</param> /// <param name="cancellationToken">An optional <see cref="CancellationToken"/> instance to signal the request to cancel the operation.</param> /// public override async Task SendAsync(IEnumerable <EventData> events, SendEventOptions sendOptions, CancellationToken cancellationToken) { Argument.AssertNotNull(events, nameof(events)); Argument.AssertNotClosed(_closed, nameof(AmqpProducer)); AmqpMessage messageFactory() => MessageConverter.CreateBatchFromEvents(events, sendOptions?.PartitionKey); await SendAsync(messageFactory, sendOptions?.PartitionKey, cancellationToken).ConfigureAwait(false); }
/// <summary> /// Sends a set of events to the associated Event Hub using a batched approach. /// </summary> /// /// <param name="eventBatch">The event batch 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> /// /// <remarks> /// The caller is assumed to retain ownership of the <paramref name="eventBatch" /> and /// is responsible for managing its lifespan, including disposal. /// </remarks> /// public override async Task SendAsync(EventDataBatch eventBatch, CancellationToken cancellationToken) { Argument.AssertNotNull(eventBatch, nameof(eventBatch)); Argument.AssertNotClosed(_closed, nameof(AmqpProducer)); // Make a defensive copy of the messages in the batch. AmqpMessage messageFactory() => MessageConverter.CreateBatchFromEvents(eventBatch.AsEnumerable <EventData>(), eventBatch.SendOptions?.PartitionKey); await SendAsync(messageFactory, eventBatch.SendOptions?.PartitionKey, cancellationToken).ConfigureAwait(false); }