Skip to content

Commit

Permalink
fix(pubsub): respect gRPC dial option when PUBSUB_EMULATOR_HOST is set (
Browse files Browse the repository at this point in the history
#10040)

Co-authored-by: Alex Hong <9397363+hongalex@users.noreply.github.com>
  • Loading branch information
toga4 and hongalex committed May 6, 2024
1 parent 0183dd5 commit 95bf6b2
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions pubsub/pubsub.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import (
"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"
)
Expand Down Expand Up @@ -143,12 +144,14 @@ func NewClientWithConfig(ctx context.Context, projectID string, config *ClientCo
// 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 {
Expand Down

0 comments on commit 95bf6b2

Please sign in to comment.