Esempio n. 1
0
        protected override async Task Handle(S3Event message, ILambdaContext context)
        {
            Logger.Info($"Processing S3Event With {message?.Records?.Count} records.");

            if (message?.Records == null)
            {
                return;
            }
            if (message.Records.Count == 0)
            {
                return;
            }

            using var activity = EventProcessorActivitySource.StartActivity(nameof(Handle));
            activity?.SetTag("S3MessageRecordsCount", message?.Records?.Count);

            foreach (var record in message.Records)
            {
                Logger.Info($"Processing S3Event Version {record.EventVersion}");

                await ProcessMessage(record).ConfigureAwait(false);

                Logger.Info($"Event from S3 processed. Version {record.EventVersion}");
            }
        }
        private async Task <List <DataStream <TBody> > > CreateBatchMessages(IEnumerable <KinesisEvent.KinesisEventRecord> messageRecords)
        {
            using (EventProcessorActivitySource.StartActivity(nameof(ParseRecord)))
            {
                var dataStreams = new List <DataStream <TBody> >();

                foreach (var record in messageRecords)
                {
                    dataStreams.Add(await ParseRecord <DataStream <TBody> >(record).ConfigureAwait(false));
                }

                return(dataStreams);
            }
        }
Esempio n. 3
0
        protected async Task <TBody> ParseRecord(KinesisEvent.KinesisEventRecord record)
        {
            if (record == null)
            {
                throw new ArgumentNullException(nameof(record));
            }
            if (record.Kinesis.Data is null)
            {
                throw new CriticalException($"Kinesis Data for EventId {record.EventId} is null");
            }

            Logger.Info($"Processing Kinesis Event message ID {record.EventId}.");

            using var activity = EventProcessorActivitySource.StartActivity(nameof(ParseRecord));
            activity?.SetTag("Kinesis.EventId", record.EventId);
            activity?.SetTag("Kinesis.EventName", record.EventName);
            activity?.SetTag("Kinesis.EventVersion", record.EventVersion);
            activity?.SetTag("Kinesis.EventSource", record.EventSource);
            activity?.SetTag("Kinesis.PartitionKey", record.Kinesis?.PartitionKey);
            activity?.SetTag("Kinesis.ApproximateArrivalTimestamp", record.Kinesis?.ApproximateArrivalTimestamp);


            Logger.Info("Reading Stream Content.");

            using var reader = new StreamReader(record.Kinesis.Data, Encoding.UTF8);

            var content = await reader.ReadToEndAsync().ConfigureAwait(false);

            Logger.Info("Stream content read finished.");

            Logger.Info("Deserializing Body Message.");

            var body = DeserializeBody(content, record.Kinesis.PartitionKey);

            Logger.Info("Body message deserialized.");

            if (body != null)
            {
                body.EventId = record.EventId;
                body.ApproximateArrivalTimestamp = record.Kinesis.ApproximateArrivalTimestamp;
                body.Partition ??= record.Kinesis.PartitionKey;
                body.TraceId ??= activity?.Id;
            }

            if (body?.TraceId != null && activity?.ParentId is null)
            {
                activity?.SetParentId(body.TraceId);
            }
            return(body);
        }
Esempio n. 4
0
        protected async Task <T> ParseRecord <T>(KinesisEvent.KinesisEventRecord record) where T : IDataStream
        {
            if (record == null)
            {
                throw new ArgumentNullException(nameof(record));
            }

            Logger.Info($"Processing Kinesis Event message ID {record.EventId}.");

            using var activity = EventProcessorActivitySource.StartActivity(nameof(ParseRecord));
            activity?.SetTag("EventId", record.EventId);
            activity?.SetTag("EventName", record.EventName);
            activity?.SetTag("EventVersion", record.EventVersion);
            activity?.SetTag("EventSource", record.EventSource);

            try
            {
                Logger.Info("Reading Stream Content.");

                using var reader = new StreamReader(record.Kinesis.Data, Encoding.UTF8);

                var content = await reader.ReadToEndAsync().ConfigureAwait(false);

                Logger.Info("Stream Content Read.");

                Logger.Info("Creating DataStream Message.");

                var body = DeserializeBody <T>(content, record.Kinesis.PartitionKey);

                if (body != null)
                {
                    body.EventId = record.EventId;
                    body.ApproximateArrivalTimestamp = record.Kinesis.ApproximateArrivalTimestamp;
                }

                Logger.Info("Invoking ProcessMessage.");

                return(body);
            }
            catch (Exception ex)
            {
                Logger.Error(ex,
                             "Error Processing Message from Kinesis Event. Developer, you should take care of it!. Message: Id={EventId}, PartitionKey= {PartitionKey}",
                             record.EventId, record.Kinesis.PartitionKey);
                throw;
            }
        }
Esempio n. 5
0
        protected override async Task Handle(KinesisEvent message, ILambdaContext context)
        {
            Logger.Info($"Processing Kinesis Event With {message?.Records?.Count} records.");

            if (message?.Records == null)
            {
                return;
            }
            if (message.Records.Count == 0)
            {
                return;
            }

            using var activity = EventProcessorActivitySource.StartActivity(nameof(Handle));
            foreach (var record in message.Records)
            {
                Logger.Info($"Processing Kinesis Event message ID {record.EventId}.");

                var body = await base.ParseRecord <DataStream <TBody> >(record).ConfigureAwait(false);

                if (body?.TraceId != null && activity != null)
                {
                    activity.SetParentId(body.TraceId);
                }

                Logger.Info("Invoking ProcessMessage.");

                using var processActivity = EventProcessorActivitySource.StartActivity(nameof(ProcessMessage));
                processActivity?.SetTag("KinesisEventId", record?.EventId);
                processActivity?.SetTag("KinesisEventName", record?.EventName);
                processActivity?.SetTag("KinesisPartitionKey", record?.Kinesis?.PartitionKey);
                processActivity?.SetTag("KinesisApproximateArrivalTimestamp", record?.Kinesis?.ApproximateArrivalTimestamp);
                processActivity?.SetTag("BodyEventId", body?.EventId);
                processActivity?.SetTag("BodyPartition", body?.Partition);
                processActivity?.SetTag("BodyVersion", body?.Version);
                processActivity?.SetTag("BodyVersion", body?.TraceId);

                await ProcessMessage(body).ConfigureAwait(false);
            }
        }
Esempio n. 6
0
        protected override async Task Handle(KinesisEvent message, ILambdaContext context)
        {
            Logger.Info($"Processing Kinesis Event With {message?.Records?.Count} records.");

            if (message?.Records == null)
            {
                return;
            }
            if (message.Records.Count == 0)
            {
                return;
            }

            using var activity = EventProcessorActivitySource.StartActivity(nameof(Handle));
            foreach (var record in message.Records)
            {
                Logger.Info($"Processing Kinesis Event message ID {record.EventId}.");

                try
                {
                    Logger.Info("Reading Stream Content.");

                    var body = await ParseRecord <TBody>(record).ConfigureAwait(false);

                    if (body?.TraceId != null && activity != null)
                    {
                        activity.SetParentId(body.TraceId);
                    }

                    await ProcessMessage(body).ConfigureAwait(false);
                }
                catch (Exception ex)
                {
                    Logger.Error(ex, "Error Processing Message from Kinesis Event. Developer, you should take care of it!. Message: Id={EventId}, PartitionKey= {PartitionKey}",
                                 record.EventId, record.Kinesis.PartitionKey);
                    throw;
                }
            }
        }
        protected override async Task Handle(KinesisEvent message, ILambdaContext context)
        {
            Logger.Info($"Processing Kinesis Event With {message?.Records?.Count} records.");

            if (message?.Records == null)
            {
                return;
            }
            if (message.Records.Count == 0)
            {
                return;
            }

            Logger.Info($"Processing Kinesis Event With {message?.Records?.Count} records.");
            var batchMessages = await CreateBatchMessages(message.Records).ConfigureAwait(false);

            Logger.Info($"Processing Kinesis Event With {message?.Records?.Count} records.");

            using var activity = EventProcessorActivitySource.StartActivity(nameof(ProcessMessage));
            activity?.SetTag("BatchMessagesCount", batchMessages.Count);

            await ProcessMessage(batchMessages).ConfigureAwait(false);
        }