예제 #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;
            }
        }
예제 #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;
            }
        }
예제 #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;
            }
        }