public async Task <ProductsImportResult> Handle(CreateProductsImport request) { // salva planilha no storage var fileId = Guid.NewGuid(); var fileExtension = Path.GetExtension(request.FileName); var fileNewName = $"{fileId}{fileExtension}"; var result = await _fileService.Upload(fileNewName, request.Data); // registra importação no banco de dados var import = new Import(result.FilePath); await _importRepository.Create(import); // Envia mensagem para o tópico var importCreated = new ImportCreated { Id = import.Id, CreatedAt = import.CreatedAt, SpreadsheetFileUrl = import.SpreadsheetFileUrl }; await SendEvent(importCreated); return(new ProductsImportResult { ImportId = import.Id, FilePath = result.FilePath }); }
public async Task Handle(ImportCreated notification) { _logger.LogInformation($"Evento recebido: {notification.Id}, {notification.CreatedAt}, {notification.SpreadsheetFileUrl}"); // Processa a Planilha await ProcessSpreadsheet(notification.Id, notification.SpreadsheetFileUrl); }
private async Task SendEvent(ImportCreated importCreated) { var config = new ProducerConfig { BootstrapServers = _configuration["Kafka:BootstrapServers"] }; using var producer = new ProducerBuilder <Null, string>(config).Build(); var message = new Message <Null, string> { Value = JsonSerializer.Serialize(importCreated) }; var result = await producer.ProduceAsync("products-import-created", message); }