public Envelope Send(Envelope envelope, Uri address, IEnvelopeSerializer serializer, IMessageCallback callback = null) { ITransport transport = null; if (_transports.TryGetValue(address.Scheme, out transport)) { var sending = envelope.Clone(); var channel = TryGetChannel(address); // TODO -- look up channel node modifiers if any // TODO -- there's a little opportunity here to try to reuse the serialization // if you send to more than one channel at a time w/ the same serializer if (sending.Data == null || sending.Data.Length == 0) { serializer.Serialize(sending, channel); } sending.AcceptedContentTypes = AcceptedContentTypes.ToArray(); if (channel != null) { sending.Destination = channel.Destination; sending.ReplyUri = channel.ReplyUri; if (callback == null) { channel.Sender.Send(sending.Data, sending.Headers); } else { callback.Send(sending); } } else { sending.Destination = address; sending.ReplyUri = transport.DefaultReplyUri(); if (callback == null) { transport.Send(sending.Destination, sending.Data, sending.Headers); } else { callback.Send(sending); } } return(sending); } else { throw new InvalidOperationException($"Unrecognized transport scheme '{address.Scheme}'"); } }
private static async Task sendToStaticChannel(IMessageCallback callback, Envelope sending, IChannel channel) { sending.Destination = channel.Destination; sending.ReplyUri = channel.ReplyUri; if (callback == null || !callback.SupportsSend && callback.TransportScheme == sending.Destination.Scheme) { await channel.Send(sending).ConfigureAwait(false); } else { await callback.Send(sending).ConfigureAwait(false); } }
private static async Task sendToDynamicChannel(Uri address, IMessageCallback callback, Envelope sending, ITransport transport) { sending.Destination = address; sending.ReplyUri = transport.DefaultReplyUri(); if (callback == null || !callback.SupportsSend && callback.TransportScheme == sending.Destination.Scheme) { await transport.Send(sending, sending.Destination).ConfigureAwait(false); } else { await callback.Send(sending).ConfigureAwait(false); } }