将不同语言服务部署到同一个应用程序 [Google App Engine]

我有两个应用程序,一个是 Python,另一个是 Java.

I have two applications, one in Python and the other one in Java.

在 Python 中,我的应用程序位于 app.yaml 中设置的服务下,cron.yaml 也会调用该服务.

In Python, my application is under a Service which is set in the app.yaml, also the cron.yaml calls the service.

在我的 (Maven) Java 应用程序中,它不在服务下,因此它是默认服务(如果需要我会更改).该应用程序也通过 ../WEB-INF/cron.xml 文件和 ../WEB-INF/appengine-web.xml 中的应用程序信息调用代码>

In my (Maven) Java app, it is not under a Service so it is the default service (which I will change if needed). The app is also called with the ../WEB-INF/cron.xml file and the informations about the app in the ../WEB-INF/appengine-web.xml

目前它们之间没有任何联系,我将这两个应用程序部署到不同的项目中.

For now they have no connection with each other, I deployed both apps to different projects.

我想融合它们并将它们放在同一个项目中:

I would like to fuse them and put them in the same project as:

python-app.project.appspot.com

java-app.project.appspot.com

而不是当前

python-app.project1.appspot.com

project2.appspot.com

我没有尝试使用 app.yaml 和 appengine-web.xml 文件,因为我不知道是否要修改它们.

I didn't try to play around with the app.yaml and appengine-web.xml files because I do not know if those are to be modified or not.

如何使用不同的语言(Python 和 Java)制作不同的服务(模块)

How do I make different services (modules) with differents languages (Python and Java)

推荐答案

appspot.com 上生成的应用程序的命名将与您提到的有点不同,因为 url 路由规则.来自 通过 URL 路由:

The naming of the resulting app on appspot.com will be a bit different than what you mentioned, because of the url routing rules. From Routing via URL:

向默认版本的可用实例发送请求命名服务:

Sends a request to an available instance of the default version of the named service:

https://service-dot-app-id.appspot.com
http://service.my-custom-domain.com

所以,假设你的服务被命名为 pythonjava 并且你的应用被命名为 app 那么你的 appspot.com URL 将是:

So, assuming your services are named python and java and you app is named app then your appspot.com URLs woulds be:

python-dot-app.appspot.com
java-dot-app.appspot.com

但您可以根据需要使用自定义域映射它们.

But you can map them them however you want with custom domains.

至于构建这样的应用程序:

As for building such app:

  • 请记住,我需要的服务之一名为 default(或保持未命名)

  • keep in mind that one of the services needs to me named default (or remain unnamed)

为每个服务创建应用程序子目录(遵循以前推荐的多服务应用程序结构图不再在文档中找到,而是在 可以在 Google 中使用默认服务/模块就文件夹结构而言,App Engine 应用是非默认应用的兄弟吗?)

create app sub-directories for each service (following what used to be recommended multi-service app structure picture no longer found in the docs, but captured in Can a default service/module in a Google App Engine app be a sibling of a non-default one in terms of folder structure?)

将每个服务代码的全部内容复制到各自的子目录中

copy the entire content of each service code into the respective subdir

确定应用级配置文件(cron.yamldispatch.yamlqueue.yamlindex.yaml 或它们的 java 等价物)您拥有并将它们向上移动一级,在应用程序级目录中(如果两个服务中都存在这样的配置文件,您可能需要合并它们).您可能需要为这些文件选择一种语言,我会选择 python.Cron 作业需要配置目标(请参阅 target 行nofollow noreferrer">Cron 作业定义).

identify the app-level configuration files (cron.yaml, dispatch.yaml, queue.yaml and index.yaml or their java equivalents) you have and move them one level up, at the app level directory (you may need to merge them if such config files are present in both services). You may need to choose one language for these files, I'd choose python. Cron jobs would need to have targets configured (see target row in Cron job definitions).

请记住,部署一个/所有模块可能不一定会像您习惯的那样更新这些文件,相反,它们可能需要显式部署 - 检查相应的服务配置文档.部署服务时应注意可能覆盖这些配置,您可能需要制定一定的部署顺序.

Remember that deploying one/all modules might not necessarily update these files as you may be used to, instead they might need to be explicitly deployed - check the respective service configuration docs. You should keep an eye out for potentially overwriting these configs when deploying the services, you may need to come up with a certain deployment sequence.

添加 dispatch.yaml 文件并重新访问/调整服务的请求路径命名空间可能是一个好主意(可能是强制性的),以确保每个请求都正确指向相应的服务.特别注意 cron 作业,来自 target 行">Cron 作业定义:

it's probably a good idea (potentially mandatory) to add a dispatch.yaml file and re-visit/adjust the request path namespaces of the services, to ensure that each request is properly directed to the respective service. Special attention for cron jobs, from the target row in Cron job definitions:

如果您使用 调度文件,您的工作可能会重新路由.为了例如,给定以下 cron.yaml 和 dispatch.yaml文件,作业将在 module2 中运行,即使它的目标是模块1:

If you use a dispatch file, your job might be re-routed. For example, given the following cron.yaml and dispatch.yaml files, the job will run in module2, even though its target is module1:

# cron.yaml
cron:
- description: "test dispatch vs target"
  url: /tasks/hello_module2
  schedule: every 1 mins
  target: module1

# dispatch.yaml:
dispatch:
- url: '*/tasks/hello_module2'
  module: module2

https://cloud.google.com/appengine/docs/python/config/cronref#cron_job_definitions

相关文章