无法连接到本地数据存储

Can't connect to local Datastore

我在我的 Windows 机器上创建了一个本地 Google 数据库模拟器。当我 运行 模拟器时,我得到以下输出:

C:\Users\susan\AppData\Local\Google\Cloud SDK>gcloud beta emulators datastore start --project=susantestproject
WARNING: Reusing existing data in [C:\Users\susan\AppData\Roaming\gcloud\emulators\datastore].
Executing: cmd /c C:\Users\susan\AppData\Local\Google\Cloud SDK\google-cloud-sdk\platform\gcd\gcd.cmd start --host=localhost --port=8578 --store_on_disk=True --consistency=0.9 --allow_remote_shutdown C:\Users\susan\AppData\Roaming\gcloud\emulators\datastore
[datastore] API endpoint: http://localhost:8578/datastore
[datastore] If you are using a library that supports the DATASTORE_LOCAL_HOST environment variable, run:
[datastore]
[datastore]   export DATASTORE_LOCAL_HOST=localhost:8578
[datastore]
[datastore] Invoking dev_appserver with args: [--disable_update_check --jvm_flag=-Doauth.is_admin=true --property=datastore.index_configuration_format=yaml --port=8578 --address=localhost --property=datastore.force_is_high_replication=true --property=datastore.default_high_rep_job_policy_unapplied_job_pct=10.0 --allow_remote_shutdown C:\Users\susan\AppData\Roaming\gcloud\emulators\datastore].
[datastore] Executing [C:\Program Files\Java\jre1.8.0_74\bin\java, -Doauth.is_admin=true, -javaagent:C:\Users\susan\AppData\Local\Google\Cloud SDK\google-cloud-sdk\platform\gcd\.appengine\lib\agent\appengine-agent.jar, -Xbootclasspath/p:C:\Users\susan\AppData\Local\Google\Cloud SDK\google-cloud-sdk\platform\gcd\.appengine\lib\override\appengine-dev-jdk-overrides.jar, -classpath, C:\Users\susan\AppData\Local\Google\Cloud SDK\google-cloud-sdk\platform\gcd\CloudDatastore.jar;C:\Users\susan\AppData\Local\Google\Cloud SDK\google-cloud-sdk\platform\gcd\.appengine\lib\impl\appengine-api.jar;C:\Users\susan\AppData\Local\Google\Cloud SDK\google-cloud-sdk\platform\gcd\.appengine\lib\appengine-tools-api.jar;C:\Users\susan\AppData\Local\Google\Cloud SDK\google-cloud-sdk\platform\gcd\.appengine\lib\impl\appengine-api-stubs.jar, com.google.appengine.tools.development.DevAppServerMain, --property=kickstart.user.dir=C:\Users\susan\AppData\Local\Google\Cloud SDK, --disable_update_check, --property=datastore.index_configuration_format=yaml, --port=8578, --address=localhost, --property=datastore.force_is_high_replication=true, --property=datastore.default_high_rep_job_policy_unapplied_job_pct=10.0, --allow_remote_shutdown, C:\Users\susan\AppData\Roaming\gcloud\emulators\datastore]
[datastore] Apr 08, 2016 8:14:51 PM java.util.prefs.WindowsPreferences <init>
[datastore] WARNING: Could not open/create prefs root node Software\JavaSoft\Prefs at root 0x80000002. Windows RegCreateKeyEx(...) returned error code 5.
[datastore] Apr 08, 2016 8:14:51 PM com.google.apphosting.utils.jetty.JettyLogger info
[datastore] INFO: Logging to JettyLogger(null) via com.google.apphosting.utils.jetty.JettyLogger                                                       [datastore] Apr 08, 2016 8:14:51 PM com.google.appengine.tools.development.DevAppServerImpl setServerTimeZone                                          [datastore] WARNING: Unable to set the TimeZone to UTC (this is expected if running on JDK 8)
[datastore] Apr 08, 2016 8:14:51 PM com.google.apphosting.utils.jetty.JettyLogger info
[datastore] INFO: jetty-6.1.x
[datastore] Apr 08, 2016 8:14:51 PM com.google.apphosting.utils.jetty.JettyLogger info
[datastore] INFO: Started SelectChannelConnector@localhost:8578
[datastore] Apr 08, 2016 8:14:52 PM com.google.appengine.tools.development.AbstractModule startup
[datastore] INFO: Module instance default is running at http://localhost:8578/
[datastore] Apr 08, 2016 8:14:52 PM com.google.appengine.tools.development.AbstractModule startup
[datastore] INFO: The admin console is running at http://localhost:8578/_ah/admin
[datastore] Apr 08, 2016 8:14:52 PM com.google.appengine.tools.development.DevAppServerImpl doStart
[datastore] INFO: Dev App Server is now running

我还设置了以下环境变量:

set DATASTORE_DATASET=susanproject
set DATASTORE_HOST=http://localhost:8578
set DATASTORE_EMULATOR_HOST=localhost:8578
set DATASTORE_PROJECT_ID=susanproject

在我的代码中有以下代码:

var gcloud = require('gcloud')({
  projectId: 'susantestproject',
});

var datastore = gcloud.datastore({
  apiEndpoint: 'http://localhost:8578'
});

app.get('/', function (req, res) {

// Save data to Datastore.
var blogPostData = {
  title: 'How to make the perfect homemade pasta',
  author: 'Andrew Chilton',
  isDraft: true
};

var blogPostKey = datastore.key('BlogPost');

datastore.save({
  key: blogPostKey,
  data: blogPostData
}, function(err) {
  // `blogPostKey` has been updated with an ID so you can do more operations
  // with it, such as an update.
  blogPostData.isDraft = false;

  datastore.save({
    key: blogPostKey,
    data: blogPostData
  }, function(err) {
    if (!err) {
      // The blog post is now published!
          res.status(200).send('Hello, world! An insert has been made!');

    }

  });
});

当我 运行 代码并点击 localhost:3000(所以它点击 '/' 目录)时,我得到以下输出:

App listening at http://:::3000
E0408 20:14:36.906000000  8752 tcp_client_windows.c:106] on_connect error: No connection could be made because the target machine actively refused it.
E0408 20:14:36.910000000  8752 parsing.c:472] Unknown frame type 50
E0408 20:14:37.909000000  6356 tcp_client_windows.c:106] on_connect error: No connection could be made because the target machine actively refused it.
E0408 20:14:37.913000000  6356 tcp_client_windows.c:106] on_connect error: No connection could be made because the target machine actively refused it.
E0408 20:14:37.917000000  6356 parsing.c:472] Unknown frame type 50

我可以在 http://localhost:8578/_ah/admin 连接到管理控制台,但没有任何内容插入数据存储区。总的来说,我想连接到我的本地模拟器,但无法连接。

更新:

我创建了一个虚拟机,安装了 Ubuntu,并尝试在 linux 中安装 Google 数据存储而不是 Windows 以查看是否这是一个平台问题。

我还恢复到 0.30.0 之前的 gcloud 版本,如果我使用那个 api 一切正常。如果我尝试 0.30.0+,就会出现这些错误。

我发现 v0.30.0 的发行说明中提到了这一点:

Additionally, we are now using gRPC to give a performance boost to your Datastore calls. As of now, the gcloud SDK does not have a gRPC emulator, meaning if you wish to use a localhost backend instead of the upstream API, you will have to use the gcd.sh tool directly.

https://github.com/GoogleCloudPlatform/gcloud-node/releases/tag/v0.30.0

您尝试过使用 gcd.sh 吗?

简要指南:

  • 从他们在发行说明
  • 中提供的 link 下载存档
  • 解压缩 zip
  • 运行 ./gcs.sh 创建 mydatadir
  • 运行 ./gcs.sh 启动 mydatadir

另一个shell 运行:

export DATASTORE_EMULATOR_HOST=localhost:8080
export DATASTORE_HOST=http://localhost:8080

现在 运行 您的应用程序。

有一个 gcs.bat 如果您使用 windows,您可以 运行。

我认为这个 gRPC 数据存储正在进行中。它可能没有 gcloud 的花里胡哨,例如管理控制台。我找不到它的任何文档。

我遇到了同样的问题。

在 linux 我通过 运行:

解决了它
~/apps/google-cloud-sdk/platform/gcd/gcd.sh start --host=localhost --port=8463 --store_on_disk=True --consistency=0.32 --allow_remote_shutdown ~/.config/gcloud/emulators/datastore

您在

获得管理页面
http://localhost:8463/_ah/admin

不知道在其他平台上是否也一样..