使用ASP.NET Core应用程序连接到Google数据存储区模拟器 [英] Connecting to google datastore emulator with ASP.NET Core application

本文介绍了使用ASP.NET Core应用程序连接到Google数据存储区模拟器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试本地配置数据存储模拟器(在Windows上运行)以进行开发和测试,因为更新云中的索引需要花费很多时间.我将逐步完成本指南:

I am trying to configure the datastore emulator locally(running on windows) for development and testing as far as updating indexes in the cloud takes a lot of time. I am going step by step through this guide:

  1. gcloud beta模拟器数据存储区启动
  2. 应配置环境变量:只需逐行手动写设置VARIABLE_NAME = VARIABLE_VALUE
  3. 尝试访问localhost:8081-返回确定
  4. 尝试访问localhost:8081/数据存储-返回未找到
  5. 在本地重新启动应用程序并尝试对数据存储进行一些操作:所有更改都应用在云上,而不是本地上...
  1. gcloud beta emulators datastore start
  2. Should configure environment variables: just writing manually line by line set VARIABLE_NAME=VARIABLE_VALUE
  3. Trying to access localhost:8081 - returns Ok
  4. Trying to access localhost:8081/datastore - returns Not found
  5. Restarted application locally and trying some operations on datastore: all changes are applied on the cloud, not locally...

推荐答案

我遵循了相同的步骤,但是除非我为DataStore的Create调用提供了明确的说明,否则它无法正常工作.

I have followed the same steps, but couldn't get it working unless I provided explicit instructions to DataStore's Create call.

您需要区分代码是在GCP还是本地运行.

You need to differentiate whether your code is running in GCP vs Local.

如果您在本地环境中,则需要按以下步骤创建DataStoreDB.

If you are in local environment, you need to create DataStoreDB as follows.

DatastoreDb db = DatastoreDb.Create(projectId, string.Empty, new DatastoreClientImpl(
                new Datastore.DatastoreClient(
                    new Channel("localhost", 8081, ChannelCredentials.Insecure)), new DatastoreSettings()));

我仍在探索您是否可以不专门初始化为localhost

I am still exploring if you could do without initializing specifically to localhost

这篇关于使用ASP.NET Core应用程序连接到Google数据存储区模拟器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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