/// <inheritdoc/>
        public override async Task <IList <string> > PublishAsync <TEvent>(IList <EventContext <TEvent> > events,
                                                                           EventRegistration registration,
                                                                           DateTimeOffset?scheduled            = null,
                                                                           CancellationToken cancellationToken = default)
        {
            // log warning when trying to publish scheduled message
            if (scheduled != null)
            {
                Logger.LogWarning("Amazon Kinesis does not support delay or scheduled publish");
            }

            using var scope = CreateScope();
            var records = new List <PutRecordsRequestEntry>();

            // work on each event
            foreach (var @event in events)
            {
                using var ms = new MemoryStream();
                await SerializeAsync(body : ms,
                                     @event : @event,
                                     registration : registration,
                                     scope : scope,
                                     cancellationToken : cancellationToken);

                var record = new PutRecordsRequestEntry
                {
                    Data         = ms,
                    PartitionKey = TransportOptions.PartitionKeyResolver(@event),
                };
                records.Add(record);
            }

            // prepare the request
            var streamName = registration.EventName;
            var request    = new PutRecordsRequest
            {
                StreamName = streamName,
                Records    = records,
            };

            // send the events
            Logger.LogInformation("Sending {EventsCount} messages to '{StreamName}'. Scheduled: {Scheduled}. Events:\r\n- {Ids}",
                                  events.Count,
                                  streamName,
                                  scheduled,
                                  string.Join("\r\n- ", events.Select(e => e.Id)));
            var response = await kinesisClient.PutRecordsAsync(request, cancellationToken);

            response.EnsureSuccess();

            // Should we check for failed records and throw exception?

            // return the sequence numbers
            return(response.Records.Select(m => m.SequenceNumber.ToString()).ToList());
        }
        /// <inheritdoc/>
        public override async Task <string> PublishAsync <TEvent>(EventContext <TEvent> @event,
                                                                  EventRegistration registration,
                                                                  DateTimeOffset?scheduled            = null,
                                                                  CancellationToken cancellationToken = default)
        {
            // log warning when trying to publish scheduled message
            if (scheduled != null)
            {
                Logger.LogWarning("Amazon Kinesis does not support delay or scheduled publish");
            }

            using var scope = CreateScope();
            using var ms    = new MemoryStream();
            await SerializeAsync(body : ms,
                                 @event : @event,
                                 registration : registration,
                                 scope : scope,
                                 cancellationToken : cancellationToken);

            // prepare the record
            var streamName = registration.EventName;
            var request    = new PutRecordRequest
            {
                Data         = ms,
                PartitionKey = TransportOptions.PartitionKeyResolver(@event),
                StreamName   = streamName,
            };

            // send the event
            Logger.LogInformation("Sending {Id} to '{StreamName}'. Scheduled: {Scheduled}", @event.Id, streamName, scheduled);
            var response = await kinesisClient.PutRecordAsync(request, cancellationToken);

            response.EnsureSuccess();

            // return the sequence number
            return(scheduled != null ? response.SequenceNumber : null);
        }