Ejemplo n.º 1
0
        public async Task QueueMessageBatchAsync <T>(
            Guid streamGuid,
            string streamNamespace,
            IEnumerable <T> events,
            StreamSequenceToken token,
            Dictionary <string, object> requestContext
            )
        {
            try
            {
                var batch = new KafkaBatchContainer(
                    streamGuid,
                    streamNamespace,
                    events.Cast <object>().ToList(),
                    requestContext,
                    false
                    );

                await _producer.Produce(batch, _options.ProducerTimeout);
            }
            catch (Exception ex)
            {
                _logger.LogError(ex, "Failed to publish message: streamNamespace: {namespace}, streamGuid: {guid}", streamNamespace, streamGuid);
                throw;
            }
        }
Ejemplo n.º 2
0
        public async Task MessagesDeliveredAsync(IList <IBatchContainer> messages)
        {
            KafkaBatchContainer batchWithHighestOffset = null;

            try
            {
                if (!messages.Any())
                {
                    return;
                }

                batchWithHighestOffset = messages
                                         .Cast <KafkaBatchContainer>()
                                         .Max();

                var commitPromise = _consumer.Commit(new[] { batchWithHighestOffset });
                _commitPromise = commitPromise;

                await commitPromise;
            }
            catch (Exception ex)
            {
                _logger.LogError(ex, "Failed to commit message offset: {@offset}", batchWithHighestOffset?.TopicPartitionOffSet);
                throw;
            }
        }
Ejemplo n.º 3
0
        public async Task QueueMessageBatchAsync <T>(
            Guid streamGuid,
            string streamNamespace,
            IEnumerable <T> events,
            StreamSequenceToken token,
            Dictionary <string, object> requestContext
            )
        {
            try
            {
                var eventList = events.Cast <object>().ToList();
                if (eventList.Count == 0)
                {
                    return;
                }

                var batch = new KafkaBatchContainer(
                    streamGuid,
                    streamNamespace,
                    eventList,
                    requestContext
                    );

                await _producer.Produce(batch);
            }
            catch (Exception ex)
            {
                _logger.LogError(
                    ex, "Failed to publish message: streamNamespace: {namespace}, streamGuid: {guid}",
                    streamNamespace,
                    streamGuid.ToString()
                    );

                throw;
            }
        }