zoukankan      html  css  js  c++  java
  • 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();
                        }
    
                    }
                }
            }
    

      

  • 相关阅读:
    Xcode 增强开发效率的插件
    svn 常用指令
    初识JFinal
    企业竞争案例分析
    可行性研究5
    可行性研究习题4
    可行性研究课后题
    关于阅读软件工程和计算机科学技术区别的文章来谈谈自己看法
    关于中文编程是解决中国程序员效率的秘密武器的问题思考
    Java ForkJoinPool 用法及原理
  • 原文地址:https://www.cnblogs.com/WQ1992/p/12100854.html
Copyright © 2011-2022 走看看