public virtual async Task RespondAsync <T>(T message, IPipe <SendContext> sendPipe) where T : class { if (message == null) { throw new ArgumentNullException(nameof(message)); } if (sendPipe == null) { throw new ArgumentNullException(nameof(sendPipe)); } var responsePipe = new ResponsePipe <T>(this, sendPipe); if (ResponseAddress != null) { var endpoint = await GetSendEndpoint(ResponseAddress).ConfigureAwait(false); await ConsumeTask(endpoint.Send(message, responsePipe, CancellationToken)).ConfigureAwait(false); } else { await Publish(message, responsePipe, CancellationToken).ConfigureAwait(false); } }
public virtual async Task RespondAsync(object message, Type messageType, IPipe <SendContext> sendPipe) { if (message == null) { throw new ArgumentNullException(nameof(message)); } if (messageType == null) { throw new ArgumentNullException(nameof(messageType)); } if (sendPipe == null) { throw new ArgumentNullException(nameof(sendPipe)); } var responsePipe = new ResponsePipe(this, sendPipe); if (ResponseAddress != null) { var endpoint = await GetSendEndpoint(ResponseAddress).ConfigureAwait(false); await ConsumeTask(SendEndpointConverterCache.Send(endpoint, message, messageType, responsePipe, CancellationToken)).ConfigureAwait(false); } else { await Publish(message, messageType, responsePipe, CancellationToken).ConfigureAwait(false); } }
protected RequestFuture() { Event(() => CommandCompleted, x => { x.CorrelateById(context => context.RequestId ?? throw new RequestException("RequestId not present")); x.OnMissingInstance(m => m.Fault()); }); Event(() => CommandFaulted, x => { x.CorrelateById(context => context.RequestId ?? throw new RequestException("RequestId not present")); x.OnMissingInstance(m => m.Fault()); }); Initially( When(FutureRequested) .ThenAsync(async context => { ConsumeEventContext <FutureState, TRequest> consumeContext = context.CreateConsumeContext(); var pipe = new ResponsePipe <TCommand>(consumeContext.ReceiveContext.InputAddress, context.Instance.CorrelationId); await SendCommand(consumeContext, pipe).ConfigureAwait(false); }) ); DuringAny( When(CommandCompleted) .SetFutureCompleted(CreateCompleted) .NotifySubscribers(x => GetCompleted(x)) .TransitionTo(Completed), When(CommandFaulted) .SetFutureFaulted(CreateFaulted) .NotifySubscribers(x => GetFaulted(x)) .TransitionTo(Faulted) ); }