Example #1
0
        public bool HandleInventoryReleasedEvent(InventoryReleasedEvent evt)
        {
            Console.WriteLine($"Handling inventory released event - {evt.EventId}");
            var activity = new ProductActivity
            {
                OrderId      = evt.OrderId,
                SKU          = evt.SKU,
                Quantity     = (int)evt.Quantity,
                ActivityId   = evt.EventId,
                CreatedOn    = DateTime.UtcNow.Ticks,
                ActivityType = Entities.ActivityType.Released
            };
            var result = this.repository.PutActivity(activity);

            return(result != null);
        }
Example #2
0
        public bool HandleInventoryReleasedEvent(InventoryReleasedEvent evt)
        {
            Console.WriteLine($"Handling inventory released event - {evt.EventID}");
            ProductActivity activity = new ProductActivity
            {
                OrderID      = evt.OrderID,
                SKU          = evt.SKU,
                Quantity     = (int)evt.Quantity,
                ActivityID   = evt.EventID,
                CreatedOn    = DateTime.UtcNow.Ticks,
                ActivityType = PartialFoods.Services.InventoryServer.Entities.ActivityType.Released
            };
            var result = repository.PutActivity(activity);

            return(result != null);
        }
        public void Consume()
        {
            Task.Run(() =>
            {
                Console.WriteLine($"Starting Kafka subscription to {topic}");
                using (var consumer = new Consumer <Null, string>(config, null, new StringDeserializer(Encoding.UTF8)))
                {
                    //consumer.Assign(new List<TopicPartitionOffset> { new TopicPartitionOffset(topic, 0, 0) });
                    consumer.Subscribe(new[] { topic });

                    while (true)
                    {
                        Message <Null, string> msg;
                        if (consumer.Consume(out msg, TimeSpan.FromSeconds(1)))
                        {
                            string rawJson = msg.Value;
                            try
                            {
                                InventoryReleasedEvent evt = JsonConvert.DeserializeObject <InventoryReleasedEvent>(rawJson);
                                eventProcessor.HandleInventoryReleasedEvent(evt);
                                var committedOffsets = consumer.CommitAsync(msg).Result;
                                if (committedOffsets.Error.HasError)
                                {
                                    Console.WriteLine($"Failed to commit offsets : {committedOffsets.Error.Reason}");
                                }
                            }
                            catch (Exception ex)
                            {
                                Console.WriteLine(ex.StackTrace);
                                Console.WriteLine($"Failed to handle inventory released event : ${ex.ToString()}");
                            }
                        }
                    }
                }
            });
        }