예제 #1
0
 public ModelWrapper Create()
 {
     foreach (var connection in connections)
     {
         (bool success, ModelWrapper model) = connection.Get();
         if (success)
         {
             return(model);
         }
     }
     semaphoreSlim.Wait();
     try
     {
         if (connections.Count < options.MaxConnection)
         {
             var connection = new ConnectionWrapper(connectionFactory.CreateConnection(options.EndPoints), options);
             (bool success, ModelWrapper model) = connection.Get();
             connections.Add(connection);
             if (success)
             {
                 return(model);
             }
         }
         throw new System.OverflowException(nameof(connections));
     }
     finally
     {
         semaphoreSlim.Release();
     }
 }
예제 #2
0
        public ModelWrapper(
            ConnectionWrapper connectionWrapper,
            IModel model)
        {
            Connection = connectionWrapper;
            Model      = model;
            var consumeRetryTimes    = 0;
            var consumeRetryTimesStr = consumeRetryTimes.ToString();

            persistentProperties            = Model.CreateBasicProperties();
            persistentProperties.Persistent = true;
            persistentProperties.Headers    = new Dictionary <string, object>();
            persistentProperties.Headers.Add(Consts.ConsumerRetryTimesStr, consumeRetryTimesStr);
            noPersistentProperties            = Model.CreateBasicProperties();
            noPersistentProperties.Persistent = false;
            noPersistentProperties.Headers    = new Dictionary <string, object>();
            noPersistentProperties.Headers.Add(Consts.ConsumerRetryTimesStr, consumeRetryTimesStr);
        }