項目使用的 rabbit RabbitMQ.Client, Version=5.0.0.0 json
最近項目用戶量上來後,偶現 None of the specified endpoints were reachable 異常code
解決方案:修改MQ請求的超時時間(參數TimeoutMilliseconds 由以前的30秒改爲默認10秒,個別調用時間5秒) 發佈後系統穩定blog
/// <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(); } } } }