Override the default endpoint

The default endpoint is the global endpoint: "pubsub.googleapis.com".

In some cases, you may need to point the client and a regional or locational endpoint, typically designated by some prefix applied to the service name (e.g. "europe-central2-pubsub.googleapis.com". This can be accomplished by using the MakePublisherConnection overload which accepts a location parameter.

In rare cases, you may need to override the global endpoint used by the client library. This typically occurs in testing or Private Google Access cases. Use the google::cloud::EndpointOption when initializing the client library to change this default. For example, this will override the default endpoint for google::cloud::pubsub::Publisher:

  namespace pubsub = ::google::cloud::pubsub;
  using ::google::cloud::Options;
  [](std::string const& project_id, std::string const& topic_id) {
    // This service supports specifying a regional or locational endpoint prefix
    // when creating the SubscriptionAdminConnection.
    // For example, to connect to "europe-central2-pubsub.googleapis.com":
    auto pub = pubsub::Publisher(pubsub::MakePublisherConnection(
        "europe-central2", pubsub::Topic(project_id, topic_id)));

    // This configuration is common with Private Google Access:
    //     https://cloud.google.com/vpc/docs/private-google-access
    auto vpc_pub = pubsub::Publisher(pubsub::MakePublisherConnection(
        pubsub::Topic(project_id, topic_id),
        Options{}.set<google::cloud::EndpointOption>(
            "private.googleapis.com")));
  }

Follow these links to find examples for other *Client classes: