2016-07-26 42 views
1

由於各種原因,我們只是剛剛開始從Couchbase版本(相當老版本)升級到最新版本。不幸的是,我們目前正在使用Couchbase Client SDK for .NET的v1.1.6。轉向v2.3.4似乎帶來了許多重大改變,目前全部都以配置爲中心。從CouchbaseClientConfiguration遷移到SDK中的ClientConfiguration

我們以前使用舊CouchbaseClientConfiguration類型,它似乎一直與ClientConfiguration(也BucketConfigurationPoolConfiguration)現已被取代。我設法遷移了大部分配置本身,但現在不清楚的是超時。

它如何使用掛鉤一個例子:

var clientConfiguration = new CouchbaseClientConfiguration() 
    { 
     Bucket = MembaseBucketName, 
     BucketPassword = MembaseBucketPassword 
    }; 

foreach (string host in root.Elements("servers").Elements("add").Attributes("uri")) 
{ 
    clientConfiguration.Servers.Add(new Uri(host)); 
} 

// <servers retryCount="3" retryTimeout="00:00:30" > 
clientConfiguration.RetryTimeout = TimeSpan.Parse(root.Element("servers").Attribute("retryTimeout").Value); 
clientConfiguration.RetryCount = Convert.ToInt32(root.Element("servers").Attribute("retryCount").Value); 

// <socketPool minPoolSize="10" maxPoolSize="10" connectionTimeout="00:00:30" deadTimeout="00:00:30" queueTimeout="00:00:30" receiveTimeout="00:00:30" />  
clientConfiguration.SocketPool.MinPoolSize = 
    Convert.ToInt32(root.Element("socketPool").Attribute("minPoolSize").Value); 
clientConfiguration.SocketPool.MaxPoolSize = 
    Convert.ToInt32(root.Element("socketPool").Attribute("maxPoolSize").Value); 
clientConfiguration.SocketPool.ConnectionTimeout = 
    TimeSpan.Parse(root.Element("socketPool").Attribute("connectionTimeout").Value); 
clientConfiguration.SocketPool.DeadTimeout = 
    TimeSpan.Parse(root.Element("socketPool").Attribute("deadTimeout").Value); 
clientConfiguration.SocketPool.QueueTimeout = 
    TimeSpan.Parse(root.Element("socketPool").Attribute("queueTimeout").Value); 
clientConfiguration.SocketPool.ReceiveTimeout = 
    TimeSpan.Parse(root.Element("socketPool").Attribute("receiveTimeout").Value); 

而這就是我已經設法到目前爲止翻譯:

var clientConfiguration = new ClientConfiguration 
{ 
    BucketConfigs = new Dictionary<string, BucketConfiguration> 
    { 
     { 
      MembaseBucketName, 
      new BucketConfiguration 
      { 
       BucketName = MembaseBucketName, 
       Password = MembaseBucketPassword, 
       Servers = root.Elements("servers").Elements("add").Attributes("uri").ToList(_ => new Uri(_.Value)), 
       PoolConfiguration = new PoolConfiguration 
       { 
        MinSize = Convert.ToInt32(root.Element("socketPool").Attribute("minPoolSize").Value), 
        MaxSize = Convert.ToInt32(root.Element("socketPool").Attribute("maxPoolSize").Value), 
        ConnectTimeout = (int)TimeSpan.Parse(root.Element("socketPool").Attribute("connectionTimeout").Value).TotalMilliseconds, 
        WaitTimeout = (int)TimeSpan.Parse(root.Element("socketPool").Attribute("queueTimeout").Value).TotalMilliseconds, 
       }, 
       DefaultOperationLifespan = (uint)TimeSpan.Parse(root.Element("socketPool").Attribute("receiveTimeout").Value).TotalMilliseconds, 
      } 
     }, 
    }, 
}; 

我們用來指定:QueueTimeoutDeadTimeoutReceiveTimeoutConnectionTimeoutRetryTimeoutRetryCount。這些遷移到哪裏?我會假設他們在新代碼中有相同的屬性,或者他們周圍的概念已經改變。

另外,在哪裏做ServersPoolConfiguration配置活?它們均可在ClientConfigurationBucketConfiguration上找到。我們只運行一個存儲桶,只有幾個服務器URI,因此總配置並不複雜。

回答

2

盡我所能說,我之前非常接近。我結束了是這樣的:

var clientConfiguration = new ClientConfiguration 
{ 
    BucketConfigs = new Dictionary<string, BucketConfiguration> 
    { 
     { 
      MembaseBucketName, 
      new BucketConfiguration 
      { 
       BucketName = MembaseBucketName, 
       Password = MembaseBucketPassword, 
       Servers = root.Elements("servers").Elements("add").Attributes("uri").ToList(_ => new Uri(_.Value)), 
       PoolConfiguration = new PoolConfiguration 
       { 
        MinSize = Convert.ToInt32(root.Element("socketPool").Attribute("minPoolSize").Value), 
        MaxSize = Convert.ToInt32(root.Element("socketPool").Attribute("maxPoolSize").Value), 
        ConnectTimeout = (int)TimeSpan.Parse(root.Element("socketPool").Attribute("connectionTimeout").Value).TotalMilliseconds, 
        WaitTimeout = (int)TimeSpan.Parse(root.Element("socketPool").Attribute("queueTimeout").Value).TotalMilliseconds, 
        SendTimeout = (int)TimeSpan.Parse(root.Element("socketPool").Attribute("receiveTimeout").Value).TotalMilliseconds, 
       }, 
       DefaultOperationLifespan = (uint)TimeSpan.Parse(root.Element("socketPool").Attribute("receiveTimeout").Value).TotalMilliseconds, // Belt and braces. 
      } 
     }, 
    }, 
    ViewRequestTimeout = (int)TimeSpan.Parse(root.Element("socketPool").Attribute("receiveTimeout").Value).TotalMilliseconds, // Belt and braces. 
}; 

似乎有沒有類似DeadTimeout了,也不RetryCountRetryTimeout,這在archived docs說是:

  • retryCount數次重試失敗嘗試讀取羣集配置
  • retryTimeout(00:00:02)在嘗試讀取羣集配置失敗之間等待的時間量

在目前的文檔中,沒有什麼類似於我能找到的。

ReceiveTimeout似乎與幾件事有關,即PoolConfiguration.WaitTimeout,BucketConfiguration.DefaultOperationLifespanClientConfiguration.ViewRequestTimeout。我對此沒有信心,因爲它是一種映射到三種似乎具有類似行爲的新配置選項的配置。

其餘的幾乎都是一對一的。

忽略奇怪的(int)TimeSpan.TotalMilliseconds廢話,它是我們指定配置的當前方式的倒退。將來需要改變。

我將重新審視這個答案,因爲我根據上面的方法驗證了我的假設。我仍然沒有弄清楚爲什麼相同的配置是在多個層面 - 我希望你可以默認然後覆蓋值。