private void DoWork(object state) { _iteration++; var greetingEvent = new GreetingEvent { Id = Guid.NewGuid(), Greeting = $"Hello # {_iteration}" }; _processor.Post(greetingEvent); _logger.LogInformation($"Sending message with id {greetingEvent.Id} and greeting {greetingEvent.Greeting}"); }
public async Task <IActionResult> SendMessage() { var greetingAsync = new GreetingAsyncEvent("Hello from the web"); var greeting = new GreetingEvent("Hello from the web"); _context.Greetings.Add(greeting); _context.GreetingsAsync.Add(greetingAsync); await _context.SaveChangesAsync(); _commandProcessor.Post(greeting); await _commandProcessor.PostAsync(greetingAsync); return(View("Index")); }
public async Task <IActionResult> SaveAndRollbackMessage() { var transaction = await _context.Database.BeginTransactionAsync(); // try // { var greetingAsync = new GreetingAsyncEvent("Hello from the web - 1"); var greeting = new GreetingEvent("Hello from the web - 1"); _context.Greetings.Add(greeting); _context.GreetingsAsync.Add(greetingAsync); await _context.SaveChangesAsync(); _commandProcessor.DepositPost(greeting); await _commandProcessor.DepositPostAsync(greetingAsync); //throw new Exception("Something went wrong"); // } // catch (Exception e) // { await transaction.RollbackAsync(); // } var greetingAsync2 = new GreetingAsyncEvent("Hello from the web - 2"); var greeting2 = new GreetingEvent("Hello from the web - 2"); _context.Greetings.Add(greeting2); _context.GreetingsAsync.Add(greetingAsync2); _commandProcessor.DepositPost(greeting2); await _context.SaveChangesAsync(); await _commandProcessor.DepositPostAsync(greetingAsync2); var msgs = new List <Guid>(); // msgs.Add(greeting.Id); // msgs.Add(greetingAsync.Id); msgs.Add(greeting2.Id); msgs.Add(greetingAsync2.Id); await _commandProcessor.ClearOutboxAsync(msgs); return(View("Index")); }
private void DoWork(object state) { _iteration++; var greetingEvent = new GreetingEvent { Id = Guid.NewGuid(), Greeting = $"Hello # {_iteration}" }; try { _processor.Post(greetingEvent); } catch (Exception e) { _logger.LogError($"Kafka Message Generator is stopping due to {e.Message}"); _appLifetime.StopApplication(); } _logger.LogInformation($"Sending message with id {greetingEvent.Id} and greeting {greetingEvent.Greeting}"); }
public GreetingState Apply(GreetingEvent @event) { Greeting = @event.Greeting; return(this); }