Couchbase Lite 2.1 复制器问题 .net

Posted

技术标签:

【中文标题】Couchbase Lite 2.1 复制器问题 .net【英文标题】:Couchbase Lite 2.1 Replicator Issue .net 【发布时间】:2019-01-10 19:15:11 【问题描述】:

我们刚刚将 SyncGatewaty 升级到 2.1。所以现在我正在重构我们的客户端代码以使用 CouchbaseLite 2.1。当我尝试复制时,我得到了错误:

得到 LiteCore 错误:未找到 (6/404)

我最初在连接到我们的开发服务器时遇到错误,然后在我的笔记本电脑上安装了本地 clean 副本,我在尝试连接时也遇到了同样的错误。

日志:

INFO) Couchbase 2019-01-10T10:56:47.8503147-07:00 (启动) [1] CouchbaseLite/2.1.2 (.NET; Microsoft Windows 10.0.17763) Build/13 LiteCore/ (15) 提交/ 9aebf28

警告)LiteCore 2019-01-10T10:56:48.1943139-07:00 C4SocketImpl#1==> 类 litecore::repl::C4SocketImpl ws://localhost.com:443//_blipsync

警告)LiteCore 2019-01-10T10:56:48.1943139-07:00 C4SocketImpl#1 意外或不干净的套接字断开连接! (原因=WebSocket 状态,代码=404)

错误)同步 2019-01-10T10:56:48.1993137-07:00 Repl#2==> 类 litecore::repl::Replicator c:\temp\content_meta_data.cblite2\ ->ws:// localhost:443//_blipsync

错误)同步 2019-01-10T10:56:48.1993137-0 7:00 Repl#2 出现 LiteCore 错误:未找到 (6/404)

我的代码:

using System;
using System.IO;
using Couchbase.Lite;
using Couchbase.Lite.Support;
using Couchbase.Lite.Sync;
using NLog;

namespace ReplicatorExample

    public class DatabaseManager
    
        private static readonly Logger _log = LogManager.GetCurrentClassLogger();
        public const string BUCKET_CONTENT_META_DATA = "content_meta_data";
        private static DatabaseManager _instance;

        public static DatabaseManager GetInstance()
        
            NetDesktop.Activate();
            NetDesktop.EnableTextLogging("logs");

            return _instance ?? (_instance = new DatabaseManager());
        

        public void InitializeBuckets()
        
            try
            
                var defaultAuthenticator = GetDefaultAuthenticator();

                var dirInfo = new DirectoryInfo($"c:\\temp\\BUCKET_CONTENT_META_DATA");
                if (!dirInfo.Parent.Exists)
                
                    dirInfo.Parent.Create();
                

                var database = new Database(dirInfo.FullName);

                // Create replicator to push and pull changes to and from the cloud
                var targetEndpoint = new URLEndpoint(new Uri("ws://localhost:4985"));
               var replConfig = new ReplicatorConfiguration(database, targetEndpoint)
                
                    Authenticator = defaultAuthenticator,
                    Continuous = true,
                    //Channels = new List<string>
                    //
                    //    "approved",
                    //    
                    //
                ;
                var replicator = new Replicator(replConfig);
                replicator.AddChangeListener((sender, args) =>
                
                    if (args.Status.Error != null)
                    
                        _log.Error($"args.Status.Error");
                    
                    else
                    
                        _log.Debug(args.Status);
                    
                );
                replicator.Start();
            
            catch (Exception e)
            
                _log.Error(e);
            
        

        private Authenticator GetDefaultAuthenticator()
        
            return new BasicAuthenticator("BigD","123456");
        


    

【问题讨论】:

【参考方案1】:

我认为您需要在targetEndpoint 的 URL 中指定数据库名称。

例如:var targetEndpoint = new URLEndpoint(new Uri("ws://localhost:4984/mydatabase"));

【讨论】:

以上是关于Couchbase Lite 2.1 复制器问题 .net的主要内容,如果未能解决你的问题,请参考以下文章

java的CouchBase-lite的初次踩坑

PouchDB 和 CouchBase Lite + LiteGap 的区别

通过 iCloud 同步 CouchBase Lite 数据

在couchbase lite java中保存图像

没有phonegap插件的Couchbase lite

如何从 Android 应用程序将 json 文件格式导入 CouchBase lite