public void Send(string beerId) { if (ConnectionExists()) { using (var channel = _connection.CreateModel()) { channel.QueueDeclare(queue: MessagingConfig.BeerCreatedQueueName, durable: false, exclusive: false, autoDelete: false, arguments: null); var b = new BeerCreatedEvent() { BeerId = beerId, Location = MessagingConfig.BeerCreatedApiPath + beerId }; string message = b.AsJson(); var body = Encoding.UTF8.GetBytes(message); channel.BasicPublish(exchange: MessagingConfig.DefaultExchangeName, routingKey: MessagingConfig.BeerCreatedQueueName, basicProperties: null, body: body); _logger.LogInformation("Message Sent {0}", message); } } }
private void HandleMessage(string msg) { BeerCreatedEvent beerCreatedEvent = JsonSerializer.Deserialize <BeerCreatedEvent>(msg); _logger.LogInformation("Message received: {0}", beerCreatedEvent.AsJson()); Stock stock = new Stock() { BeerId = beerCreatedEvent.BeerId, StockDisponible = 0, StockReserve = 0 }; _stockRepository.CreateStock(stock); }