使用任务队列测试多个 AppEngine 服务

Testing multiple AppEngine services with task queues

我有一个包含 2 个服务的 AppEngine 应用程序,其中服务 A 使用任务(推送)队列为服务 B 排队任务。如何使用开发服务器对此进行测试? 运行多个服务与开发服务器时,每个服务获得唯一的端口号,任务队列无法解析URL,因为目标URL实际上是运行在另一个端口上,即服务 A 在端口 8080 上,服务 B 在端口 8081 上。这在所有内容都在同一端口的生产环境中运行良好,但我如何在本地进行测试?

推送队列配置允许按开发服务器理解的名称指定目标服务。来自 Syntax:

target (push queues)

Optional. A string naming a service/version, a frontend version, or a backend, on which to execute all of the tasks enqueued onto this queue.

The string is prepended to the domain name of your app when constructing the HTTP request for a task. For example, if your app ID is my-app and you set the target to my-version.my-service, the URL hostname will be set to my-version.my-service.my-app.appspot.com.

If target is unspecified, then tasks are invoked on the same version of the application where they were enqueued. So, if you enqueued a task from the default application version without specifying a target on the queue, the task is invoked in the default application version. Note that if the default application version changes between the time that the task is enqueued and the time that it executes, then the task will run in the new default version.

If you are using services along with a dispatch file, your task's HTTP request might be intercepted and re-routed to another service.

例如,一个基本的 queue.yaml 应该是这样的:

queue:

- name: service_a
  target: service_a

- name: service_b
  target: service_b

我不能 100% 确定这是否足够,我个人也在使用 dispatch.yaml 文件,因为我需要路由任务以外的请求。但是为此,您需要在 URL 中有一个定义明确的模式,因为开发服务器不支持基于主机名的模式。例如,如果服务 A 请求使用 /service_a/... 路径而服务 B 使用 /service_b/... 路径,那么这些就可以解决问题:

dispatch:

- url: "*/service_a/*"
  service: service_a

- url: "*/service_b/*"
  service: service_b

在你的情况下,可能可以只用一个调度文件来实现你想要的——即仍然使用默认队列。试一试。