【发布时间】:2016-07-26 09:31:21
【问题描述】:
出于各种原因,我们现在才开始从我们使用的(相当旧的)Couchbase 版本升级到最新版本。不幸的是,我们目前使用的是用于 .NET 的 Couchbase Client SDK v1.1.6。迁移到 v2.3.4 似乎带来了很多重大变化,目前都以配置为中心。
我们曾经使用旧的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,所以总体配置并不复杂。
【问题讨论】: