How do I access Google Cloud Datastore emulator using .Net Core?

278 views Asked by At

I have this simple console program in .Net Core v3.1:

static void Main(string[] args)
{
    var db = new DatastoreDbBuilder 
    {
        ProjectId = "simple-proj",
        EmulatorDetection = EmulatorDetection.EmulatorOnly
    }.Build();

    var keyFactory = db.CreateKeyFactory("Simple");
    using (var transaction = db.BeginTransaction())
    {
        transaction.Insert(new Entity { Key = keyFactory.CreateIncompleteKey(), ["Message"] = "Hello" });
        transaction.Commit();
    }
}

I'm using the the Google.Cloud.Datastore.V1 v3.0.0 library to access the Datastore from my C# code. I started the emulator and set the environment variables using $(gcloud beta emulators datastore env-init) as the documentation says. I get an OK message back from the emulator endpoint (http://localhost:8081) when I access it via the browser. Everything seems to be in order.

This is the stack dump I get on my .Net console:

Unhandled exception. Grpc.Core.RpcException: Status(StatusCode=Unavailable, Detail="failed to connect to all addresses")
   at Grpc.Core.Internal.AsyncCall`2.UnaryCall(TRequest msg)
   at Grpc.Core.Calls.BlockingUnaryCall[TRequest,TResponse](CallInvocationDetails`2 call, TRequest req)
   at Grpc.Core.DefaultCallInvoker.BlockingUnaryCall[TRequest,TResponse](Method`2 method, String host, CallOptions options, TRequest request)
   at Grpc.Core.Interceptors.InterceptingCallInvoker.<BlockingUnaryCall>b__3_0[TRequest,TResponse](TRequest req, ClientInterceptorContext`2 ctx)
   at Grpc.Core.ClientBase.ClientBaseConfiguration.ClientBaseConfigurationInterceptor.BlockingUnaryCall[TRequest,TResponse](TRequest request, ClientInterceptorContext`2 context, BlockingUnaryCallContinuation`2 continuation)
   at Grpc.Core.Interceptors.InterceptingCallInvoker.BlockingUnaryCall[TRequest,TResponse](Method`2 method, String host, CallOptions options, TRequest request)
   at Google.Cloud.Datastore.V1.Datastore.DatastoreClient.BeginTransaction(BeginTransactionRequest request, CallOptions options)
   at Google.Api.Gax.Grpc.ApiCall.GrpcCallAdapter`2.CallSync(TRequest request, CallSettings callSettings)
   at Google.Api.Gax.Grpc.ApiCallRetryExtensions.<>c__DisplayClass1_0`2.<WithRetry>b__0(TRequest request, CallSettings callSettings)
   at Google.Api.Gax.Grpc.ApiCall`2.<>c__DisplayClass10_0.<WithCallSettingsOverlay>b__1(TRequest req, CallSettings cs)
   at Google.Api.Gax.Grpc.ApiCall`2.Sync(TRequest request, CallSettings perCallCallSettings)
   at Google.Cloud.Datastore.V1.DatastoreClientImpl.BeginTransaction(BeginTransactionRequest request, CallSettings callSettings)
   at Google.Cloud.Datastore.V1.DatastoreClient.BeginTransaction(String projectId, CallSettings callSettings)
   at Google.Cloud.Datastore.V1.DatastoreDbImpl.BeginTransaction(CallSettings callSettings)
   at simple.Simple.Main(String[] args) in /Users/wreid/git/leapsystems/research/console-reports/Simple.cs:line 20

And this is the corresponding Datastore emulator console message:

[datastore] Jul 24, 2020 5:48:42 PM io.gapi.emulators.grpc.GrpcServer$3 operationComplete
[datastore] INFO: Adding handler(s) to newly registered Channel.
[datastore] Jul 24, 2020 5:48:42 PM io.gapi.emulators.netty.HttpVersionRoutingHandler channelRead
[datastore] INFO: Detected non-HTTP/2 connection.
[datastore] Jul 24, 2020 5:48:42 PM io.gapi.emulators.netty.NotFoundHandler handleRequest
[datastore] INFO: Unknown request URI: /bad-request

Am I missing something obvious somewhere either in my code or the setup of the emulator?

0

There are 0 answers