private void SendReplayCommand() { ICommandSender commandSender = _context.CreateCommandSender(); ReplayEventsCommand replayEventsCommand = new ReplayEventsCommand() { ExchangeName = NameConstants.BestelServiceEventReplayExchange, EventType = NameConstants.CatalogusServiceCategorieAanCatalogusToegevoegdEvent }; commandSender.SendCommandAsync(new RequestCommandMessage( message: JsonConvert.SerializeObject(replayEventsCommand), type: NameConstants.AuditlogReplayCommandType, correlationId: "", routingKey: NameConstants.AuditlogQueue )); }
private void SendReplayCommand(string eventType) { ICommandSender commandSender = _context.CreateCommandSender(); ReplayEventsCommand replayEventsCommand = new ReplayEventsCommand() { ExchangeName = NameConstants.BffWebshopEventReplayExchange, Topic = eventType }; commandSender.SendCommandAsync(new RequestCommandMessage( message: JsonConvert.SerializeObject(replayEventsCommand), type: NameConstants.AuditlogReplayCommandType, correlationId: "", routingKey: NameConstants.AuditlogQueue )); }
/// <summary> /// Publish a domain command with a specific return result /// </summary> public virtual async Task <TReturn> PublishAsync <TReturn>(DomainCommand domainCommand) { _logger.LogTrace( $"Publishing domain command with type {domainCommand.GetType().Name} and ID {domainCommand.Id}"); var json = JsonConvert.SerializeObject(domainCommand); _logger.LogDebug($"Publishing domain command {domainCommand.Id} with body: {json}"); var message = new CommandMessage { Timestamp = domainCommand.Timestamp, CorrelationId = domainCommand.Id, EventType = domainCommand.GetType().Name, Body = Encoding.Unicode.GetBytes(json), DestinationQueue = domainCommand.DestinationQueue }; var result = await _sender.SendCommandAsync(message); try { string jsonBody = Encoding.Unicode.GetString(result?.Body); return((TReturn)JsonConvert.DeserializeObject(jsonBody, typeof(TReturn))); } catch (ArgumentNullException exception) { _logger.LogError( $"Deserializing response from queue {domainCommand.DestinationQueue} ended with an ArgumentNullException"); throw new DestinationQueueException( $"ArgumentNullException was thrown, most likely because the destination queue {domainCommand.DestinationQueue} replied with an empty body.", exception, "Unknown", domainCommand.DestinationQueue, domainCommand.Id); } }
private Task VerlaagVoorraad(Bestelling bestelling) { var tasks = new List <Task>(); foreach (var regel in bestelling.BestelRegels) { var body = new HaalVoorraadUitMagazijnCommand { Artikelnummer = (int)regel.Artikelnummer, Aantal = regel.Aantal }; var request = new RequestCommandMessage( message: JsonConvert.SerializeObject(body), type: NameConstants.MagazijnServiceHaalVoorraadUitMagazijnCommand, correlationId: "", routingKey: NameConstants.MagazijnServiceCommandQueue ); tasks.Add(_commandSender.SendCommandAsync(request)); } return(Task.WhenAll(tasks)); }