public MsgSendInfo[] SendMessage(SkyWebMessage msg) { if (msg == null) { throw new WebMessagingException(StringConsts.ARGUMENT_ERROR + "{0}.SendMessage(null)".Args(GetType().Name)); } var deliveryList = new List <MsgSendInfo>(); var idx = -1; var matchedAll = true; foreach (var adr in msg.AddressToBuilder.All) { idx++; var channel = m_Channels[adr.ChannelName]; if (channel == null) { matchedAll = false; deliveryList.Add(new MsgSendInfo(MsgChannelWriteResult.Gateway, null, idx)); continue; } try { var result = channel.Write(deliveryList, idx, adr.ChannelAddress, msg); if (result < 0) { deliveryList.Add(new MsgSendInfo(result, null, idx)); } // TODO: instrumentation by result, etc. } catch (Exception error) { log(Azos.Log.MessageType.Critical, "sndmsg.chn.wrt", "Channel '{0}' leaked:".Args(channel.Name, error.ToMessageWithType()), error); deliveryList.Add(new MsgSendInfo(MsgChannelWriteResult.ChannelError, null, idx)); } } //route to gateway if (!matchedAll) { m_Gateway.SendMsg(msg); } return(deliveryList.ToArray()); }
public Task <string> SendAsync(Message message, MessageProps props) { //1. Validate var ve = message.NonNull(nameof(message)).Validate(); if (ve != null) { throw ve; } //2. Save message into document storage, getting back a unique Id //which can be later used for query/retrieval message.ArchiveId = Guid.NewGuid().ToString(); //await m_DocStorage.PutMessageAsync(message.NonNull(nameof(message)), props); //3. Route message for delivery //the router implementation is 100% asynchronous by design m_Router.SendMsg(message); return(Task.FromResult <string>(null)); //message.ArchiveId; }