public Task RouteEgressMessage <TMessage>( TMessage message, string correlationId = default, string causationId = default, string messageId = default, DateTimeOffset timestamp = default) where TMessage : class { var apis = _router._brokers.SelectMany(broker => broker.Egress.Apis).Where(api => api.MessageTypesRegistry.DoesOwn <TMessage>()) .ToArray(); if (!apis.Any()) { throw new PoezdOperationException($"Unable to find destinations for message of type {message.GetType().FullName}."); } var tasks = apis.Select( async api => { var context = new MessagePublishingContext { Message = message, Broker = _router._brokers.Single(broker => broker.Egress.Apis.Contains(api)), Api = api, CorrelationId = correlationId, CausationId = causationId, MessageId = messageId, Timestamp = timestamp }; var pipeline = BuildEgressPipeline(_router._brokers.Single(broker => broker.Egress.Apis.Contains(api)), api); try { await pipeline.Execute(context); // TODO: Add timeout configuration using router configuration fluent interface. var timeout = new CancellationTokenSource(TimeSpan.FromSeconds(value: 5)).Token; await context.Broker.Publish(context, timeout); } catch (Exception exception) { throw new PoezdOperationException( "An error occurred during message publishing. Inspect the inner exceptions for more details.", exception); } }); return(Task.WhenAll(tasks)); }
/// <inheritdoc /> public Task Publish(MessagePublishingContext context, CancellationToken cancellationToken) => Driver.Publish(context, cancellationToken);
public Task Publish(MessagePublishingContext context, CancellationToken cancellationToken) => throw CreateException();