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