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)
| 283 | // The second return value is a function that can be called to clean up |
| 284 | // the connection opened by Dial. |
| 285 | func 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. |
| 304 | func dialEmulator(ctx context.Context, e string) (*grpc.ClientConn, error) { |