1

在我的 Mac 10.9.2 中,我安装了沙发基础服务器,它正在运行http://127.0.0.1:8091 它有它的默认存储桶,包括 beer-sample

我将同步服务器启动为

./sync_gateway -bucket="beer-sample" 

在控制台中记录以下内容

14:00:55.903306 ==== Couchbase Sync Gateway/0.94 ====
14:00:55.979850 Configured Go to use all 2 CPUs; setenv GOMAXPROCS to override this
14:00:55.979985 Configured MaxFileDescriptors (RLIMIT_NOFILE) to 5000
14:00:56.005329 Opening db /beer-sample as bucket "beer-sample", pool "default", server <walrus:>
14:00:56.019242 Opening Walrus database beer-sample on <walrus:>
14:00:56.057276 Using default sync function 'channel(doc.channels)' for database "beer-sample"
14:00:56.057549 Starting profile server on 
14:00:56.057680 Starting admin server on 127.0.0.1:4985
14:00:56.090556 Starting server on :4984 ...

在 android 我的复制代码看起来像

Replication pullReplication = database.createPullReplication("http://10.0.2.2:4984");
pullReplication.start();

然后我在模拟器中运行我的 android 应用程序,并在 changeEventListener 中记录了错误

        if (!replication.isRunning()){
            Log.d(TAG, "Replication is not running due to " + replication.getLastError().getMessage());
            Log.d(TAG, "Replication is not running due to " + replication.getLastError().getCause());
            Log.d(TAG, "Replication is not running due to " + replication.getLastError().getStackTrace());
            Log.d(TAG, "Replication is not running due to " + replication.getLastError().toString());
        }

记录的

04-04 14:04:18.402    1622-1644/com.couchbase.replicationsample.replicationsample D/HelloWorld﹕ Replication: Puller[http://10.0.2.2:4984] changed.
04-04 14:04:18.432    1622-1644/com.couchbase.replicationsample.replicationsample D/HelloWorld﹕ Replication is not running due to HTTP/1.1 404 Not Found
04-04 14:04:18.454    1622-1644/com.couchbase.replicationsample.replicationsample D/HelloWorld﹕ Replication is not running due to null
04-04 14:04:18.502    1622-1644/com.couchbase.replicationsample.replicationsample D/HelloWorld﹕ Replication is not running due to [Ljava.lang.StackTraceElement;@414efc88
04-04 14:04:18.502    1622-1644/com.couchbase.replicationsample.replicationsample D/HelloWorld﹕ Replication is not running due to com.couchbase.lite.CouchbaseLiteException: HTTP/1.1 404 Not Found

Note: I am using 10.0.2.2 instead of 127.0.0.1 because i read in forum that's how simulator maps the host machine. But i also tried 127.0.0.1 earlier which also gives the same result.

同时,我在同步网关控制台中看到一个新条目,例如

14:05:13.532393 HTTP:  #006: GET /_changes?feed=normal&heartbeat=300000

我试图在浏览器中重复这个查询

> http://127.0.0.1:4984/_changes?feed=normal&heartbeat=300000

这是显示

{"error":"not_found","reason":"unknown URL"}

我在这里做错了什么?我是沙发基地的新手。

4

2 回答 2

1

设法克服了这个错误:

在https://github.com/couchbaselabs/GrocerySync-Android中找到了一个参考项目

对我的原始步骤/代码所做的主要更改是

  1. 执行同步网关为./sync_gateway -bucket="beer-sample" -url=“http://localhost:8091/beer-sample" -verbose

  2. 在同步 URL 中添加数据库,如“ http://10.0.2.2:4984/beer-sample”,即database.createPullReplication("http://10.0.2.2:4984/beer-sample");

  3. 遇到授权错误。通过在终端中执行以下命令让匿名访问(暂时)启用 GUEST 帐户

    curl -X PUT localhost:4985/beer-sample/_user/GUEST --data '{"disabled":false, "admin_channels":["public"]}'

于 2014-04-04T19:42:59.587 回答
0

或为 sync_gateway 创建一个配置(例如 config.json),如下所示:

{
   "interface":":4984",
   "adminInterface":":4985",
   "log":["REST"],
   "databases":{
      "registratura7":{
         "server":"http://YOUR_IP:8091",
         "bucket":"registratura7",
         "sync":`function(doc) {channel(doc.channels);}`,
         "users": { "GUEST": {"disabled": false, "admin_channels": ["*"] } }
      }
   }
}

然后像这样运行你的sync_gateway:sync_gateway config.json。这将启用 CouchDB 网关上的 GUEST 帐户。

于 2014-11-26T11:52:56.903 回答