All Projects → cloudspannerecosystem → spanner-proxy

cloudspannerecosystem / spanner-proxy

Licence: Apache-2.0 License
An easy way to create Google Cloud Spanner proxies.

Programming Languages

go
31211 projects - #10 most used programming language

spanner-proxy

An easy way to create Google Cloud Spanner proxies...

See examples/proxy for an example proxy server.

p := proxy.New()
p.CreateSession = func(ctx context.Context, req *pb.CreateSessionRequest) (*pb.Session, error) {
    // Your own session creation...
    return &pb.Session{
        Name:       "my-first-session",
        CreateTime: ptypes.TimestampNow(),
    }, nil
}
log.Fatal(p.Serve(lis))

Proxy is honored by the official Cloud Spanner libraries automatically if you set SPANNER_EMULATOR_HOST environment variable to the proxy endpoint.

export SPANNER_EMULATOR_HOST=localhost:9777
go run examples/client/main.go

Alternatively, you can use the Cloud Spanner gRPC clients with the proxy endpoint and insecure connection:

conn, err := grpc.Dial("localhost:9777", grpc.WithInsecure())
if err != nil {
    log.Fatal(err)
}
defer conn.Close()

When to write a proxy server?

There are various reasons you might want to write a proxy server. Some examples:

  • To override the behavior of the Cloud Spanner API.
  • To manage connections and sessions outside of application server.
  • To instrument the Cloud Spanner calls in a custom way for monitoring and debugging purposes.
  • To handle the authentication to Cloud Spanner outside of the application servers.
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].