Пример #1
0
        public override async Task <Response> SendAsync(object message, bool sent)
        {
            //Console.WriteLine("step6:" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff"));
            if (_sendReconnect && !IsConnected)
            {
                await ConnectAsync();
            }
            //Console.WriteLine("step7:" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff"));
            IChannel channel = GetChannel();

            //TODO Can the value returned by getChannel() be null? need improvement.
            if (channel == null || !channel.IsConnected)
            {
                throw new RemotingException(this, "message can not send, because channel is closed . url:" + Url);
            }

            var id = (message as Request)?.Mid ?? 0;

            InvocationUtils.SetInvocation(id, (message as Request)?.Mdata);
            //Console.WriteLine("step8:" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff"));
            var task = RegisterResultCallbackAsync(id);//todo user msg.id

            try
            {
                //Console.WriteLine("step9:" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff"));
                await channel.SendAsync(message, sent);

                // Console.WriteLine("step10:" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff"));
                return(await task);
            }
            catch (Exception e)
            {
                _logger.Error(e);
                throw;
            }
        }