/// <summary> /// /// </summary> /// <typeparam name="TResponse"></typeparam> /// <param name="command"></param> /// <param name="cancellationToken">Propagates notification that operations should be canceled.</param> /// <returns></returns> public async Task <TResponse> Dispatch <TResponse>(ICommandRequest <TResponse> command, CancellationToken cancellationToken) { await _executeMiddlewaresService.ExecuteAsync(command, cancellationToken); var wrappedHandlers = GetWrappedHandlers(command); if (wrappedHandlers == null) { throw new CommandNotRegisteredError(command.ToString()); } return(await wrappedHandlers.Handle(command, _serviceProvider, cancellationToken)); }
/// <summary> /// /// </summary> /// <param name="event"></param> /// <param name="cancellationToken">Propagates notification that operations should be canceled.</param> /// <returns></returns> public async Task Publish(DomainEvent @event, CancellationToken cancellationToken) { await _executeMiddlewaresService.ExecuteAsync(@event, cancellationToken); var eventAsString = _domainEventJsonSerializer.Serialize(@event); await _connectionMultiplexer.GetSubscriber().PublishAsync("*", eventAsString); }
public async Task Publish(List <DomainEvent> events, CancellationToken cancellationToken) { if (events == default) { return; } await Task.WhenAll(events.Select(@event => _executeMiddlewaresService.ExecuteAsync(@event, cancellationToken))); events.ForEach(@event => _inMemoryConsumer.Consume(@event)); }
/// <summary> /// /// </summary> /// <typeparam name="TResponse"></typeparam> /// <param name="query"></param> /// <param name="cancellationToken">Propagates notification that operations should be canceled.</param> /// <returns></returns> public async Task <TResponse> Ask <TResponse>(IQueryRequest <TResponse> query, CancellationToken cancellationToken) { await _executeMiddlewaresService.ExecuteAsync(query, cancellationToken); var handler = GetWrappedHandlers(query); if (handler == null) { throw new QueryNotRegisteredError(query.ToString()); } return(await handler.Handle(query, _serviceProvider, cancellationToken)); }
/// <summary> /// /// </summary> /// <param name="event"></param> /// <param name="cancellationToken">Propagates notification that operations should be canceled.</param> /// <returns></returns> public async Task Publish(DomainEvent @event, CancellationToken cancellationToken) { try { await _executeMiddlewaresService.ExecuteAsync(@event, cancellationToken); var serializedDomainEvent = _domainEventJsonSerializer.Serialize(@event); var channel = _config.Channel(); channel.ExchangeDeclare(_rabbitMqParams.Value.ExchangeName, ExchangeType.Topic); var body = Encoding.UTF8.GetBytes(serializedDomainEvent); var properties = channel.CreateBasicProperties(); properties.Headers = new Dictionary <string, object> { { HeaderReDelivery, 0 } }; channel.BasicPublish(_rabbitMqParams.Value.ExchangeName, @event.GetEventName(), properties, body); } catch (RabbitMQClientException) { //await _failOverPublisher.Publish(new List<DomainEvent> {domainEvent}, cancellationToken); } }