使用 Google ESP 代理多个服务

Proxying to multiple services using Google ESP

我一直在审查 Google Cloud Extensible Service Proxy,它承诺是一个无服务器 NGINX 实例,但是我不确定如何通过它代理应用引擎中的多个服务 运行,并基本上将其用作网关。它似乎需要一个大摇大摆的主机 JSON 配置和一个指向端点服务名称的环境变量,我看不出它如何在这个约束条件下代理多个服务。

我的理解是您可以使用 Cloud 运行 托管 Endpoints ESP。然后,这将为您提供一个 URL 来访问它,但如果需要,会启动足够的 ESP 实例。然后,您将向其注册的 Open API 规范文档将包含与您要公开的每个服务实例相对应的路径。然后,对于每条路径,您将定义一个指向服务 URL 的 x-google-backend,每个路径将针对该服务进行解析。

编辑: yaml 文件看起来像这样:

info:
  title: Cloud Endpoints with API Keys
  description: Sample API on Cloud Endpoints with multiple App Engine with IAP backend
  version: 1.0.0
host: <ENDPOINT_URL>
schemes:
  - https
produces:
  - application/json
paths:
  /hello-gae1:
    get:
      summary: Greet a user from App Engine
      operationId: hello_gae
      x-google-backend:
        address: https://<PROJECT_ID>.appspot.com
      parameters:
        - in: query
          name: name
          required: false
          type: string
      responses:
        '200':
          description: A successful response
          schema:
            type: string
  /hello-gae2:
    get:
      summary: Greet a user from App Engine
      operationId: hello_gae
      x-google-backend:
        address: https://<SERVICE-dot-PROJECT_ID>.appspot.com
      parameters:
        - in: query
          name: name
          required: false
          type: string
      responses:
        '200':
          description: A successful response
          schema:
            type: string
  /hello-gae3:
    get:
      summary: Greet a user from App Engine
      operationId: hello_gae
      x-google-backend:
        address: https://<SERVICE-dot-PROJECT_ID>.appspot.com
      parameters:
        - in: query
          name: name
          required: false
          type: string
      responses:
        '200':
          description: A successful response
          schema:
            type: string
securityDefinitions:
  # This section configures basic authentication with an API key.
  api_key:
    type: "apiKey"
    name: "key"
    in: "query"

参考文献: