由於各種原因,我們只是剛剛開始從Couchbase版本(相當老版本)升級到最新版本。不幸的是,我們目前正在使用Couchbase Client SDK for .NET的v1.1.6。轉向v2.3.4似乎帶來了許多重大改變,目前全部都以配置爲中心。從CouchbaseClientConfiguration遷移到SDK中的ClientConfiguration
我們以前使用舊CouchbaseClientConfiguration
類型,它似乎一直與ClientConfiguration
(也BucketConfiguration
和PoolConfiguration
)現已被取代。我設法遷移了大部分配置本身,但現在不清楚的是超時。
它如何使用掛鉤一個例子:
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,
}
},
},
};
我們用來指定:QueueTimeout
,DeadTimeout
, ReceiveTimeout
,ConnectionTimeout
,RetryTimeout
和RetryCount
。這些遷移到哪裏?我會假設他們在新代碼中有相同的屬性,或者他們周圍的概念已經改變。
另外,在哪裏做Servers
和PoolConfiguration
配置活?它們均可在ClientConfiguration
和BucketConfiguration
上找到。我們只運行一個存儲桶,只有幾個服務器URI,因此總配置並不複雜。