通过Cloud Datastore API连接到开发中的AppEngine数据存储 [英] Connecting to AppEngine datastore in development via Cloud Datastore API
问题描述
我们目前正在运行一个AppEngine / GCE组合应用程序,并且迄今为止在AppEngine方面保留了我们所有的数据存储访问权限。现在我们正在探索允许我们的GCE实例对(共享)数据存储进行一些查询。首先,我试图找出如何在本地运行的东西。到目前为止:
我看过一些文档,但他们(a)只谈论Python& Java和(b)讨论连接到(独立的)开发数据存储服务器,而不是嵌入在AppEngine的devappserver中的数据存储(如果这些数据存储甚至不同?)。在StackOverflow中也有以下答案,但它又讨论了连接到独立开发数据存储服务器的问题:
任何指针都会非常感谢!
$ b
目前在开发环境中这是不可能的,原因有几个。 Google Cloud Datastore工具( gcd.sh )使用java开发服务器。但是,在开发App Engine时,您需要使用具有不同底层存储的python开发服务器。在 github页面上跟踪此问题存在一个错误。
您仍然可以开发Google Cloud Datastore应用程序,但有当前go客户端库中的许多错误。不幸的是,开发服务器目前不支持JSON API,这是go库使用的(参见 )。
更新:我想确保proppy的评论被看作是其中的一部分回答。他的建议确实提供了一种使用API协议版本的方法,该版本可能比上面的go客户端库更稳定。它也可以让你使用 gcd.sh
工具在开发服务器中测试它。您将不得不自己制作HTTP请求,并且您将无法在应用程序和开发中的Cloud Datastore之间共享数据存储区中的数据。然而,它绝对是一种很好的解决方法,可让您使用Cloud Datastore API,因为它开发的工作比其他解决方法更易于使用。
来自proppy:
请注意,Go仍可以使用Cloud Datastore Protobuf HTTP API。 protobuf定义在GitHub上可用,您可以使用Go protobuf编译器插件将其编译为Go代码,然后将POST HTTP请求发送到
/ datastore / {version} / datasets / {datasetId} / {method}
。
We are currently running a combined AppEngine / GCE app and thus far have kept all of our datastore access on the AppEngine side of things. Now we are exploring also allowing our GCE instance to make some queries into the (shared) datastore. To start, I'm trying to figure out how to run things locally. What we have so far:
- A Go devappserver running
- A Go standalone binary that wants to issues queries to the devappserver datastore.
- We installed ('go get') google-api-go-client/datastore/v1beta2 so that we can use an API instead of issuing direct HTTP calls. However we are definitely willing to issue direct HTTP calls if this API library won't work in development.
- We have service accounts set up (we already access GCS from GCE) but I doubt that's relevant for running locally...
I've seen some docs but they (a) only talk about Python & Java, and (b) discuss connecting to the (standalone) development datastore server, as opposed to the datastore embedded in AppEngine's devappserver (if those are even different?). There is also the following answer here on StackOverflow, but again it discusses connecting to the standalone development datastore server:
How to connect to the local google cloud Datastore db?
Any pointers would be much appreciated!
- Ian
Currently this is not possible in the development environment for several reasons. The Google Cloud Datastore tool (gcd.sh) uses the java development server. However when developing go for App Engine you use the python development server, which has different underlying storage. There is a bug to track this issue on the github page.
You can still develop a Google Cloud Datastore application in go however there are many bugs in the current go client library. Unfortunately, the development server does not currently support the JSON API, which the go library uses (see the note at the top of the page).
Update: I wanted to make sure proppy's comment was seen as part of the answer. His suggestion does provide a way to use the protocol version of the API, which is probably more stable than the go client library above. It could also let you use the gcd.sh
tool to test this in the development server. You will have to craft the HTTP requests yourself though, and you won't be able to share the data in the datastore between your application and the Cloud Datastore in development. However it is definitely a good workaround and lets you use the Cloud Datastore API, which as it develops will be easier to work with than other workarounds.
From proppy:
Note that you can still use Cloud Datastore Protobuf HTTP API with Go. The protobuf definition is available on GitHub, you can compile it to Go code using the Go protobuf compiler plugin and then send POST HTTP requests to
/datastore/{version}/datasets/{datasetId}/{method}
.
这篇关于通过Cloud Datastore API连接到开发中的AppEngine数据存储的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!