Get hands-on experience with 20+ free Google Cloud products and $300 in free credit for new customers.

How to specify pubsub service endpoint using GoLang

Hi,

According to https://cloud.google.com/pubsub/docs/reference/service_apis_overview#service_endpoints, I can specify a service endpoint when using the PubSub service.

I tried this sample command:

CLOUDSDK_API_ENDPOINT_OVERRIDES_PUBSUB=https://us-central1-pubsub.googleapis.com/ \
gcloud pubsub topics publish
test-topic \
--message=“test

It works well.

I could not find any documentation about overriding the pubsub endpoint using GoLang. But I found an API signature that might do the job.

client, err := pubsub.NewClient(ctx, projectId, option.WithEndpoint("https://us-central1-pubsub.googleapis.com/")) 

However, I got a "deadline exceeded" error. Either it is not the right way to override the PubSub endpoint, or the endpoint format is incorrect.

What is the right way to achieve what `CLOUDSDK_API_ENDPOINT_OVERRIDES_PUBSUB` does on the command line but using GoLang?

Thanks

0 1 1,230
1 REPLY 1