private static void AddValue(object sender, MsgHandlerEventArgs e) { _log.LogInfo(DateTime.Now.TimeOfDay.ToString()); var message = MessageSerializer.Deserializer <AddValueCommand>(e.Message.Data); var value = message.Value; var optionsBuilder = new DbContextOptionsBuilder <TemplateContext>(); optionsBuilder.UseSqlServer(Config.CONNECTION_STRING); try { using (var context = new TemplateContext(optionsBuilder.Options)) { _valueRepository = new ValueRepository(context, _log); var valueToInsert = new Value() { Description = value }; var insertTask = _valueRepository.InsertAsync(valueToInsert); insertTask.Wait(); if (insertTask.IsCompletedSuccessfully) { _log.LogInfo($"Processed message: {message.CorrelationId} at {DateTime.Now.TimeOfDay}"); } else { _log.LogInfo($"Failed to process message: {message.CorrelationId} with value: {value}"); } } } catch (Exception ex) { _log.LogInfo(ex.Message); _log.LogInfo(ex.StackTrace); } }
public void HandleSubscription(object sender, MsgHandlerEventArgs e) { try { var message = MessageSerializer.Deserializer <DomainEvent>(e.Message.Data); Process(message); log.Information("Processed New Customer Event", message); } catch (Exception ex) { log.Information("Unabled to process New Customer Event", MessageSerializer.Deserializer <DomainEvent>(e.Message.Data)); log.Error("Error", ex); throw ex; } }