简体   繁体   English

适用于Java开发服务器(devserver)的Google App Engine任务队列REST API

[英]Google App Engine Task Queue REST API for the Java Development Server (devserver)

I have a GAE app running on the Java Development Server (AKA devserver) on my local machine that defines some Task Queue pull queues. 我在本地计算机上的Java开发服务器(AKA devserver)上运行了一个GAE应用程序,该应用程序定义了一些“任务队列”提取队列。

I want to use the Task Queue REST API from a different standalone Java app, running on my machine, to access these pull queues. 我想使用计算机上运行的其他独立Java应用程序中的Task Queue REST API来访问这些拉入队列。

I tried the sample suggested by Google's documentation that implements leasing tasks. 我尝试 Google 文档中建议的示例该示例实现了租赁任务。 Apparently, it uses the Google API Client Library for Java that requires a client_secrets.json file of the format: 显然,它使用JavaGoogle API客户端库,要求格式为client_secrets.json文件:

{
  "installed": {
    "client_id": "retrieved from creating a Service Account for the project",
    "client_secret": "supposedly appears in the JSON file that's downloaded upon creation of a Service Account for the project"
  }
}

I created a Service Account for the project and a JSON was automatically downloaded, with the following format: 我为该项目创建了一个服务帐户,并使用以下格式自动下载了JSON:

{
  "type": "service_account",
  "project_id": "myProjectId",
  "private_key_id": "some long hexadecimal",
  "private_key": "an even longer encrypted stuff",
  "client_email": "myServiceAccountName@myProjectId.iam.gserviceaccount.com",
  "client_id": "a decimal number",
  "auth_uri": "https://accounts.google.com/o/oauth2/auth",
  "token_uri": "https://accounts.google.com/o/oauth2/token",
  "auth_provider_x509_cert_url": "https://www.googleapis.com/oauth2/v1/certs",
  "client_x509_cert_url": "https://www.googleapis.com/robot/v1/metadata/x509/myServiceAccountName%40myProjectId.iam.gserviceaccount.com"
}

In my client_secrets.json file I used private_key_id as the client_secret value and executed the sample code. 在我的client_secrets.json文件中,我使用private_key_id作为client_secret值并执行了示例代码。

The result was that it opened https://accounts.google.com/o/oauth2/auth in my browser, which displayed an error with status code 400 and the following message: 结果是它在我的浏览器中打开了https://accounts.google.com/o/oauth2/auth ,显示状态码为400的错误和以下消息:

Error: redirect_uri_mismatch Application: My Application The redirect URI in the request: http://localhost:61130/Callback did not match a registered redirect URI. 错误:redirect_uri_mismatch应用程序:我的应用程序请求中的重定向URI: http:// localhost:61130 / Callback与注册的重定向URI不匹配。

I tried Taskqueue.Builder.setRootUrl("http://localhost:8080") , although its javadoc says not to mess with it. 我尝试了Taskqueue.Builder.setRootUrl("http://localhost:8080") ,尽管它的javadoc说不要弄乱它。 It returned 401 Unauthorized . 它返回401 Unauthorized

  1. Is there a way to use the Task Queue REST API from a standalone Java app to access these pull queues? 是否可以通过独立的Java应用程序使用Task Queue REST API来访问这些拉入队列? I prefer using the Java libraries offered by Google but apparently they automatically point to the actual GAE services. 我更喜欢使用Google提供的Java库,但显然它们会自动指向实际的GAE服务。
  2. What should I use as the value of client_secret 1 in the client_secrets.json file when I do want to lease tasks from Google App Engine on the cloud? 当我想从云上的Google App Engine租用任务时,应使用什么作为client_secrets.json文件中client_secret 1的值?

1 When I created the Service Account, since I'm not the owner of the project, I got the following message: 1创建服务帐户时,由于我不是项目所有者,因此收到以下消息:

The service account could not be added to this project's permissions because you are not an owner of the project. 无法将服务帐户添加到该项目的权限中,因为您不是该项目的所有者。 To give the service account access to this project, ask a project owner to add it to the project permissions. 要授予服务帐户对此项目的访问权限,请项目所有者将其添加到项目权限中。

I wonder whether this has something to do with the absence of a client_secret property in the automatically downloaded JSON. 我想知道这是否与自动下载的JSON中缺少client_secret属性有关。

  1. I don't think the dev server will expose the Task Queue API, do your tests against a separate test project that you create. 我认为开发服务器不会公开Task Queue API,而是针对您创建的单独的测试项目进行测试。

  2. You can use the JSON from the service account to connect to the Task Queue API, see service accounts documentation. 您可以使用服务帐户中的JSON连接到Task Queue API,请参阅服务帐户文档。

    GoogleCredential credential = GoogleCredential.fromStream(new FileInputStream("MyProject-1234.json")) .createScoped(Collections.singleton(" https://www.googleapis.com/auth/taskqueue ")); GoogleCredential凭据= GoogleCredential.fromStream(new FileInputStream(“ MyProject-1234.json”)).createScoped(Collections.singleton(“ https://www.googleapis.com/auth/taskqueue ”));

    Taskqueue taskQueue = new Taskqueue.Builder( httpTransport, JSON_FACTORY, credential).setApplicationName(APPLICATION_NAME) .setTaskqueueRequestInitializer(new TaskqueueRequestInitializer() { @Override public void initializeTaskqueueRequest(TaskqueueRequest request) { request.setPrettyPrint(true); } }).build(); Taskqueue taskQueue = new Taskqueue.Builder(httpTransport,JSON_FACTORY,凭据).setApplicationName(APPLICATION_NAME).setTaskqueueRequestInitializer(new TaskqueueRequestInitializer(){ );

    // get queue //获取队列

    com.google.api.services.taskqueue.model.TaskQueue queue = getQueue(taskQueue); com.google.api.services.taskqueue.model.TaskQueue queue = getQueue(taskQueue); System.out.println(queue); System.out.println(queue);

    // lease, execute and delete tasks //租用,执行和删除任务

    Tasks tasks = getLeasedTasks(taskQueue); 任务task = getLeasedTasks(taskQueue);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Java Google App Engine任务队列冻结/停止 - Java Google App Engine Task Queue freezes / stalls 使用Java Google App Engine(GAE)自动运行任务队列 - Run automatically a Task Queue with java Google App Engine (GAE) Google App Engine-任务队列名称和交易 - Google App Engine - Task Queue Names and Transactions 谷歌应用引擎中任务队列的目的是什么 - What is the purpose of Task Queue in google app engine 在Google App Engine中衡量任务队列成本 - Measuring Task Queue Costs in Google App Engine 调用Google Cloud Endpoints API时,Google App Engine任务队列获取404 - Google App Engine Task Queue gets a 404 when invoking Google Cloud Endpoints API Google App Engine JAVA:如何向任务队列添加多个参数? - Google App Engine JAVA: How to add more than one parameter to the Task Queue? 在IntelliJ上进行Google App Engine Java开发吗? - Google App Engine Java development on IntelliJ? 如何使用Google App Engine中的模块并使用Task Queue(Java)向其添加目标? - How to use Modules in Google App Engine and add a target to them using Task Queue (Java)? 使用mvn devserver的Google App Engine Java失败:缺少“guestbook / target / guestbook-1.0-SNAPSHOT” - Google App Engine Java with mvn devserver failed: missing “guestbook/target/guestbook-1.0-SNAPSHOT”
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM