fix(pubsub): respect gRPC dial option when PUBSUB_EMULATOR_HOST is set (#10040)
Co-authored-by: Alex Hong <9397363+hongalex@users.noreply.github.com>
diff --git a/pubsub/pubsub.go b/pubsub/pubsub.go
index 29eea60..e8250a3 100644
--- a/pubsub/pubsub.go
+++ b/pubsub/pubsub.go
@@ -29,6 +29,7 @@
"cloud.google.com/go/pubsub/internal"
gax "github.com/googleapis/gax-go/v2"
"google.golang.org/api/option"
+ "google.golang.org/api/option/internaloption"
"google.golang.org/grpc"
"google.golang.org/grpc/keepalive"
)
@@ -143,12 +144,14 @@
// Environment variables for gcloud emulator:
// https://cloud.google.com/sdk/gcloud/reference/beta/emulators/pubsub/
if addr := os.Getenv("PUBSUB_EMULATOR_HOST"); addr != "" {
- conn, err := grpc.Dial(addr, grpc.WithInsecure())
- if err != nil {
- return nil, fmt.Errorf("grpc.Dial: %w", err)
+ emulatorOpts := []option.ClientOption{
+ option.WithEndpoint(addr),
+ option.WithGRPCDialOption(grpc.WithInsecure()),
+ option.WithoutAuthentication(),
+ option.WithTelemetryDisabled(),
+ internaloption.SkipDialSettingsValidation(),
}
- o = []option.ClientOption{option.WithGRPCConn(conn)}
- o = append(o, option.WithTelemetryDisabled())
+ opts = append(emulatorOpts, opts...)
} else {
numConns := runtime.GOMAXPROCS(0)
if numConns > 4 {