0
votes

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 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...
2
Did you place the localhost:8081/datastore address in a browser? What is the expected output? Have you run the gcloud beta emulators datastore start command? Have you set the environment variables with export DATASTORE_EMULATOR_HOST=localhost:8432 or similar? Which code lines try to access the datastore? You may check the "Running the Cloud Datastore Emulator" page: cloud.google.com/datastore/docs/tools/datastore-emulatorGeorge
@George, please notice 1,2...5 steps mentioned in my question, I've done all those. And yes I've been guided by this page: cloud.google.com/datastore/docs/tools/datastore-emulatorGrigoryants Artem
How does your code access the datastore emulator, exactly? A few lines may clarify the matter.George
My code knows nothing about emulator, I perform standard connection to datastore and it works fine with cloud datastore, the thing is that after configuring emulator and setting new global config variables the same code that worked with cloud datastore should start working with datastore emulator and it doesn't, please correct me if I am wrong.Grigoryants Artem
Your code should be aware of the environment with statements such as emulator_dataset = os.getenv(GCD_DATASET).George

2 Answers

3
votes

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

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

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()));

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

0
votes

You can use the DatastoreDbBuilder to force the datastore to connect to the emulator:

private DatastoreDb _datastoreDb = new DatastoreDbBuilder
    {
        EmulatorDetection = EmulatorDetection.EmulatorOnly
    }.Build();