【问题标题】:Migrating from CouchbaseClientConfiguration to ClientConfiguration in the SDK在 SDK 中从 CouchbaseClientConfiguration 迁移到 ClientConfiguration
【发布时间】:2016-07-26 09:31:21
【问题描述】:

出于各种原因,我们现在才开始从我们使用的(相当旧的)Couchbase 版本升级到最新版本。不幸的是,我们目前使用的是用于 .NET 的 Couchbase Client SDK v1.1.6。迁移到 v2.3.4 似乎带来了很多重大变化,目前都以配置为中心。

我们曾经使用旧的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,所以总体配置并不复杂。

【问题讨论】:

    标签: c# couchbase


    【解决方案1】:

    据我所知,我以前很接近。我最终得到的是这样的:

    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.WaitTimeoutBucketConfiguration.DefaultOperationLifespanClientConfiguration.ViewRequestTimeout。我对此最没有信心,因为它是一个配置映射到三个似乎具有相似行为的新配置选项。

    其余的几乎是一对一的。

    忽略奇怪的(int)TimeSpan.TotalMilliseconds 废话,这是对我们指定配置的当前方式的回归。未来需要改变。

    当我根据上述方法验证我的假设时,我将重新审视这个答案。我还没有弄清楚为什么相同的配置存在多个级别 - 我希望您可以默认然后覆盖值。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2016-11-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-06-24
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多