Ejemplo n.º 1
0
        /// <summary>
        /// Consumer多路复用
        /// </summary>
        /// <param name="uri"></param>
        /// <param name="links"></param>
        /// <param name="timeOut"></param>
        /// <param name="retry"></param>
        ConsumerMultiplexer(Uri uri, int links = 10, int timeOut = 10 * 1000, int retry = 5)
        {
            _uri     = uri;
            _links   = links;
            _timeOut = timeOut;
            _retry   = retry;

            if (!_hashMap.Exits(uri.ToString()))
            {
                for (int i = 0; i < links; i++)
                {
                    var rClient = new RClient(uri, timeOut);

                    rClient.OnDisconnected -= RClient_OnDisconnected;
                    rClient.OnError        -= RClient_OnError;
                    rClient.OnNoticed      -= RClient_OnNoticed;
                    rClient.OnDisconnected += RClient_OnDisconnected;
                    rClient.OnError        += RClient_OnError;
                    rClient.OnNoticed      += RClient_OnNoticed;

                    rClient.Connect();
                    rClient.KeepAlive();

                    _hashMap.Set(uri.ToString(), i, rClient);

                    _myClients.TryAdd(i, rClient);
                }
            }
        }
Ejemplo n.º 2
0
 /// <summary>
 /// 创建多路复用
 /// </summary>
 /// <param name="uri"></param>
 /// <param name="links"></param>
 /// <param name="timeOut"></param>
 /// <returns></returns>
 public static ConsumerMultiplexer Create(Uri uri, int links = 4, int timeOut = 10 * 1000)
 {
     if (!_hashMap.Exits(uri.ToString()))
     {
         for (int i = 0; i < links; i++)
         {
             var rClient = new RClient(uri);
             rClient.Connect();
             rClient.KeepAlive();
             _hashMap.Set(uri.ToString(), i, rClient);
         }
     }
     return(new ConsumerMultiplexer(uri, links, timeOut));
 }
Ejemplo n.º 3
0
 /// <summary>
 /// 创建多路复用
 /// </summary>
 /// <param name="uri"></param>
 /// <param name="links"></param>
 public static ConsumerMultiplexer Create(Uri uri, int links = 4)
 {
     if (!_hashMap.Exits(uri.ToString()))
     {
         for (int i = 0; i < links; i++)
         {
             var rClient = new RClient(uri);
             if (!rClient.Connect())
             {
                 throw new RPCSocketException($"连接到{uri.ToString()}失败");
             }
             rClient.KeepAlive();
             _hashMap.Set(uri.ToString(), i, rClient);
         }
     }
     return(new ConsumerMultiplexer(uri, links));
 }