示例#1
0
 /// <summary>
 /// 把用完的连接返回连接池
 /// </summary>
 /// <param name="connection"></param>
 /// <param name="key"></param>
 public static void RelaceConnection(MQConnection connection, string key)
 {
     if (connection != null && connection.Connection.IsOpen)
     {
         lock (root)
         {
             if (dicConnections.ContainsKey(key))
             {
                 var pools = dicConnections[key];
                 pools.Add(new ComboxClass <DateTime, MQConnection>()
                 {
                     V1 = DateTime.Now, V2 = connection
                 });
             }
             else
             {
                 List <ComboxClass <DateTime, MQConnection> > li = new List <ComboxClass <DateTime, MQConnection> >();
                 dicConnections[key] = li;
                 li.Add(new ComboxClass <DateTime, MQConnection>()
                 {
                     V1 = DateTime.Now, V2 = connection
                 });
             }
         }
     }
     else
     {
         connection?.Close(); //不是open的连接就释放
     }
 }
示例#2
0
 protected override bool Run(Func <IModel, bool> fn)
 {
     try
     {
         using (MQConnection connection = MQConnectionManager.GetMqConnection(MQueue.Host.Host, MQueue.Host.Port, MQueue.Host.Username, MQueue.Host.Password))
         {
             using (IModel channel = connection.Connection.CreateModel())
             {
                 return(fn(channel));
             }
         }
     }
     catch (Exception ex)
     {
         logger.LogError(ex, $"消息发送失败,Ip:{MQueue.Host.ToString()}");
         return(false);
     }
 }