rabbit 在.net 環境下偶現(大概率):None of the specified endpoints were reachable 異常


 

 

 

 

 

項目使用的 rabbit  RabbitMQ.Client, Version=5.0.0.0 

 

最近項目用戶量上來后,偶現 None of the specified endpoints were reachable 異常

解決方案:修改MQ請求的超時時間(參數TimeoutMilliseconds 由之前的30秒改成默認10秒,個別調用時間5秒)  發布后系統穩定

  /// <summary>
        /// 
        /// </summary>
        /// <param name="jsonStr"></param>
        /// <param name="className"></param>
        /// <param name="actionName"></param>
        /// <param name="authCode"></param>
        /// <returns></returns>
public static string SendMessage(string jsonStr, string className, string actionName, string authCode, int timeout = 10000)
        {

            if (cf.HostName == null || string.IsNullOrWhiteSpace(cf.HostName) || cf.HostName == "localhost")
            {
                cf.HostName = hostName;
                cf.VirtualHost = virtualHost;
                cf.UserName = userName;
                cf.Password = password;
            }
using (IConnection conn = cf.CreateConnection())
            {
                using (IModel ch = conn.CreateModel())
                {

                    var requst = new RMQRequest
                    {
                        ClassName = className,
                        ActionName = actionName,
                        JStr = jsonStr,
                        Timestamp = DateTime.Now
                    };
 object[] reqobj = new object[1];

                    reqobj[0] = JsonConvert.SerializeObject(requst);

                    SimpleRpcClient client = new SimpleRpcClient(ch, authCode);
                    client.TimeoutMilliseconds = timeout;
                    client.TimedOut += new EventHandler(TimedOutHandler);
                    client.Disconnected += new EventHandler(DisconnectedHandler);
                    var reply = client.Call(reqobj);
 if (reply == null)
                    {
                        return null;
                    }
                    else
                    {
                        return reply[0].ToString();
                    }

                }
            }
        }

  

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM