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