如何连接到本地谷歌云数据存储区数据库? [英] How to connect to the local google cloud Datastore db?

本文介绍了如何连接到本地谷歌云数据存储区数据库?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有GAE应用程序,它在Google Cloud Datastore中创建一些数据,并将一些二进制文件存储到Google Cloud Storage中 - 让我们称之为 WebApp
现在我有一个不同的应用程序在Google计算引擎上运行。让我们调用应用程序 ComputeApp



ComputeApp 是一个后端进程,用于处理由 Web应用程序即可。我在这里问了这个问题 a>以前可以使用哪些API与 ComputeApp 中的数据存储进行通信。正如@proppy所建议的那样,我使用 Google Cloud Datastore API实施 Datastore 通信

就Google云中的数据存储进行通信而言,一切正常。我正在使用服务帐户身份验证。



现在我需要在我的开发PC上本地运行我的ComputeApp,这样我就可以获取由本地 WebApp 并存储到本地调试数据存储中。我需要它,因为我想有一个测试环境,所以我可以在本地调试GAE应用程序。



如何修改我的 ComputeApp 代码强迫它连接到我的本地调试数据存储而不是连接到Google云端?



我搜索了很多,没有找到任何建议也不例如。只有可能的方式,我发现我应该完全重写我的代码并使用不同的API来完成此操作。这就是Datastore Remote API。
这真的是唯一的方法吗?我是否应该重写整个ComputeApp以连接到本地数据库?
真的吗?



我希望我忽略了一些重要的东西,这不是真的...

解决方案

Google Cloud Datastore有一个您可以使用的本地开发服务器: https://developers.google.com/datastore/docs/tools/devserver



您可以使用gcd创建和启动本地数据存储如果您使用 DatastoreHelper.getDatastoreFromEnv(); 来构建您的工具,那么您可以使用数据存储,您可以通过导出env变量 DATASTORE_HOST 来告诉它连接到本地数据库:

  export DATASTORE_HOST = http:// localhost:8080 


I've GAE application which creates some data in the Google Cloud Datastore and stores some binary files into the Google Cloud Storage - let's call the application WebApp. Now I have a different application running on the Google compute engine. Let's call the application ComputeApp.

The ComputeApp is a backend process which is processing data created by the WebApp. I asked here in this question previously which API can I use to communicate with Datastore from the ComputeApp. As suggested by @proppy, I implemented the Datastore communication using of the Google Cloud Datastore API.

Everything works fine as far as I'm communicating with the Datastore in the Google cloud. I'm using the service account authentication.

Now I need to run my ComputeApp locally, on my development PC so I'll take data created by my local WebApp and stored into the local debug Datastore. I need it because I want to have a testing environment so I can debug may GAE app locally.

How should I modify my ComputeApp code to force it to connect to my local debug Datastore instead of connect to the Google cloud?

I googled a lot and didn't find any advice nor example. Only possible way I found that I should rewrite my code completely and use a different API to do that. Such is Datastore Remote API. Is this really only way? Should I really rewrite whole ComputeApp to connect to the local DB? Really?

I hope that I just overlooked something important and It's not true...

解决方案

Google Cloud Datastore has a local development server that you can use: https://developers.google.com/datastore/docs/tools/devserver

You can create and start the local datastore using the gcd tool which is linked to in the doc above.

If you use DatastoreHelper.getDatastoreFromEnv(); to build your Datastore, you can tell it to connect to your local database by exporting the env variable DATASTORE_HOST:

export DATASTORE_HOST=http://localhost:8080

这篇关于如何连接到本地谷歌云数据存储区数据库?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆