代码之家  ›  专栏  ›  技术社区  ›  Hypnic Jerk

Couchbase lite未通过同步网关拉通道

  •  1
  • Hypnic Jerk  · 技术社区  · 7 年前

    channels .

    我理解的方式 渠道

    我想做什么

    当我关闭应用程序,删除本地数据库,然后重新打开应用程序时,我希望 渠道 设置为拉动,但没有拉动任何内容。

    安装程序

    我正在使用Couchbase Lite 1.4.0和最新的Sync_网关。

    {
        "databases": {
            "db": {
                "server": "http://127.0.0.1:8091",
                "username": "db",
                "password": "pass",
                "users":{
                    "user1":{
                        "password":"pass"
                    }
                }
            }
        }
    }
    

    我正在Couchbase lite中访问sync gateway,如下所示:

    private String[] docChannels = new String[]{
        "channel1",
        "channel2",
    };
    private String[] configChannels = new String[]{
        "config1",
        "config2",
    };
    
    URL url = null;
    try {
        url = new URL("http://127.0.0.1:4984/db");
        } catch (MalformedURLException e) {
            e.printStackTrace();
        }
    
    Replication push = d.createPushReplication(url);
    Replication pull = d.createPullReplication(url);
    Replication pullConfig = d.createPullReplication(url);
    
    pull.setChannels(Arrays.asList(docChannels));
    pullConfig.setChannels(Arrays.asList(configChannels));
    
    pullConfig.setContinuous(false);
    pull.setContinuous(true);
    push.setContinuous(true);
    
    Authenticator auth = AuthenticatorFactory.createBasicAuthenticator("user1", "pass");
    push.setAuthenticator(auth);
    pull.setAuthenticator(auth);
    pullConfig.setAuthenticator(auth);
    
    push.start();
    
    pullConfig.start();
    pull.start();
    

    每当我创建文档时,我都会添加 值为的键 ["config1"] .

    我的文档的同步信息现在看起来像:

    "_sync": {
        "rev": "1-87cdc8c1fd5e0e4ce1a0897cbd47aca1",
        "sequence": 4,
        "recent_sequences": [
          4
        ],
        "history": {
          "revs": [
            "1-87cdc8c1fd5e0e4ce1a0897cbd47aca1"
          ],
          "parents": [
            -1
          ],
          "channels": [
            [
              "config1"
            ]
          ]
        },
        "channels": {
          "config1": null
        },
        "time_saved": "2017-09-22T13:20:43.6061974-05:00"
      }
    

    我不确定我在这里做错了什么。推送到Couchbase服务器可以很好地工作,但我的拉操作不行。

    1 回复  |  直到 7 年前
        1
  •  1
  •   combinatorial    7 年前

    为了将文档同步到另一个设备,登录用户需要将文档的频道添加到用户的频道列表中。在这种情况下,通过添加 "admin_channels": ["config1"]

    所以同步网关配置如下所示。。。

    {
        "databases": {
            "db": {
                "server": "http://127.0.0.1:8091",
                "username": "db",
                "password": "pass",
                "users":{
                    "user1":{
                        "password":"pass",
                        "admin_channels": ["config1"]
                    }
                }
            }
        }
    }