MCPcopy Create free account
hub / github.com/google/go-cloud / Dial

Function Dial

pubsub/gcppubsubv2/gcppubsub.go:285–301  ·  view source on GitHub ↗

Dial opens a gRPC connection to the GCP Pub Sub API. The second return value is a function that can be called to clean up the connection opened by Dial.

(ctx context.Context, ts gcp.TokenSource)

Source from the content-addressed store, hash-verified

283// The second return value is a function that can be called to clean up
284// the connection opened by Dial.
285func Dial(ctx context.Context, ts gcp.TokenSource) (*grpc.ClientConn, func(), error) {
286 conn, err := grpc.DialContext(ctx, endPoint,
287 grpc.WithTransportCredentials(credentials.NewClientTLSFromCert(nil, "")),
288 grpc.WithPerRPCCredentials(oauth.TokenSource{TokenSource: ts}),
289 // The default message size limit for gRPC is 4MB, while GCP
290 // PubSub supports messages up to 10MB. Aside from the message itself
291 // there is also other data in the gRPC response, bringing the maximum
292 // response size above 10MB. Tell gRPC to support up to 11MB.
293 // https://github.com/googleapis/google-cloud-node/issues/1991
294 grpc.WithDefaultCallOptions(grpc.MaxCallRecvMsgSize(1024*1024*11)),
295 useragent.GRPCDialOption("pubsub"),
296 )
297 if err != nil {
298 return nil, nil, err
299 }
300 return conn, func() { conn.Close() }, nil
301}
302
303// dialEmulator opens a gRPC connection to the GCP Pub Sub API.
304func dialEmulator(ctx context.Context, e string) (*grpc.ClientConn, error) {

Callers 6

ExampleOpenTopicFunction · 0.92
ExampleOpenSubscriptionFunction · 0.92
BenchmarkGcpPubSubFunction · 0.70
TestOpenTopicFunction · 0.70
TestOpenSubscriptionFunction · 0.70
defaultConnMethod · 0.70

Calls 2

GRPCDialOptionFunction · 0.92
CloseMethod · 0.65

Tested by 5

ExampleOpenTopicFunction · 0.74
ExampleOpenSubscriptionFunction · 0.74
BenchmarkGcpPubSubFunction · 0.56
TestOpenTopicFunction · 0.56
TestOpenSubscriptionFunction · 0.56