本頁面說明如何設定 Datastore 模式中的 Firestore 用戶端程式庫,以使用區域或多區域端點。
使用 Firestore (Datastore 模式) 用戶端程式庫時,您可以使用下列任一端點:
全域端點:根據預設,Firestore in Datastore 模式用戶端程式庫會將 API 要求傳送至名為
datastore.googleapis.com的全域服務端點。全域服務端點會將要求轉送至資料庫。在轉送期間,要求可能會通過與資料庫位置不同的伺服器。區域端點:區域端點會強制執行限制,確保資料在指定的 Google Cloud 區域中傳輸、儲存及處理。為確保服務端點在資料庫所在區域處理應用程式的 Firestore in Datastore 模式要求,請在用戶端程式庫中指定區域端點。
多區域端點:多區域端點會強制執行限制,確保資料在指定的 Google Cloud 多區域中傳輸、儲存及處理。為確保服務端點在與資料庫相同的多區域中,處理應用程式的 Datastore 模式 Firestore 要求,請在用戶端程式庫中指定多區域端點。
設定區域或多區域端點
設定區域或多區域端點的方法相同:在初始化用戶端程式庫時提供端點字串。以下範例說明如何使用區域端點 (datastore.us-central1.rep.googleapis.com) 設定端點字串。如要使用多區域端點,請提供與資料庫位置對應的多區域端點字串 (例如 nam5 的 datastore.us.rep.googleapis.com)。
Java
如要瞭解如何安裝及使用 Datastore 模式的用戶端程式庫,請參閱「Datastore 模式用戶端程式庫」。詳情請參閱 Datastore 模式 Java API 參考文件。
如要向 Datastore 模式進行驗證,請設定應用程式預設憑證。詳情請參閱「為本機開發環境設定驗證機制」。
Python
如要瞭解如何安裝及使用 Datastore 模式的用戶端程式庫,請參閱「Datastore 模式用戶端程式庫」。詳情請參閱 Datastore 模式 Python API 參考文件。
如要向 Datastore 模式進行驗證,請設定應用程式預設憑證。詳情請參閱「為本機開發環境設定驗證機制」。
區域和多區域端點語意
區域端點
Datastore 模式的 Firestore 支援「Datastore 模式的 Firestore 位置」所列區域位置的區域端點。
請使用下列格式定義區域端點:
Java
datastore.REGION_NAME.rep.googleapis.com:443
請務必一併定義通訊埠編號和端點。
Python
datastore.REGION_NAME.rep.googleapis.com
Go
datastore.REGION_NAME.rep.googleapis.com:443
請務必一併定義通訊埠編號和端點。
將 REGION_NAME 替換為區域主機名稱。
主機名稱範例如下:
datastore.us-central1.rep.googleapis.comdatastore.europe-west1.rep.googleapis.com
多區域端點
如果是多區域端點,請針對位置 nam5 和 nam7 使用 us,並針對位置 eur3 使用 eu (請參閱「多區域位置」)。
Java
datastore.us.rep.googleapis.com:443
datastore.eu.rep.googleapis.com:443
請務必一併定義通訊埠編號和端點。
Python
datastore.us.rep.googleapis.com
datastore.eu.rep.googleapis.com
Go
datastore.us.rep.googleapis.com:443
datastore.eu.rep.googleapis.com:443
請務必一併定義通訊埠編號和端點。
位置端點 (已淘汰)
位置端點現已淘汰。請改用區域或多區域端點。
Datastore 模式的 Firestore 先前支援下列格式的位置端點:
Java
https://REGION_NAME-datastore.googleapis.com:443
請務必使用完整的 https 網址,並一併定義通訊埠編號和端點。
Python
https://REGION_NAME-datastore.googleapis.com
請務必將完整的 https 網址設為位置端點。
Go
REGION_NAME-datastore.googleapis.com:443
請務必一併定義通訊埠編號和端點。
將 REGION_NAME 替換為區域或多區域主機名稱。
主機名稱範例如下:
eur3-datastore.googleapis.comnam5-datastore.googleapis.comeurope-west6-datastore.googleapis.comasia-northeast2-datastore.googleapis.com
如需多區域和區域主機名稱的完整清單,請參閱「Datastore 模式的 Firestore 位置」。
限制全域 API 端點用量
如要強制使用區域和多區域端點,請使用 constraints/gcp.restrictEndpointUsage 組織政策限制,封鎖對全域 API 端點的要求。詳情請參閱「限制端點用量」。