Skip to content

Commit 14beca4

Browse files
author
Jonathan Simon
committed
2 parents 5de7575 + 442536d commit 14beca4

File tree

6 files changed

+411
-1
lines changed

6 files changed

+411
-1
lines changed

appengine/taskqueue/pull/README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Pull task Queue sample for Google App Engine
1+
# Pull Task Queue sample for Google App Engine
22

33
This sample demonstrates how to use [pull task queues][appid] on [Google App
44
Engine][ae-docs].

taskqueue/pull/README.md

+97
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
# Pull Task Queue REST API sample
2+
This sample command line application demonstrates how to access App Engine pull task queues using the Task
3+
Queue REST API and the Google Java API Client Library.
4+
5+
<strong>Important Note:</strong> This sample requires an existing App Engine Pull Task Queue.
6+
Deploy this
7+
[sample App Engine pull task queue app](https://github.com/GoogleCloudPlatform/java-docs-samples/tree/master/appengine/taskqueue/pull)
8+
to create one first and then come back and run this sample.
9+
10+
## Setup Instructions
11+
1. Create or select a project in the Google Cloud Console:
12+
1. Visit the [Cloud Console][2]
13+
1. If this is your first time then click "Create Project," otherwise you can
14+
reuse an existing project by clicking on it.
15+
1. Note: You will need to enable billing for the project to use Compute
16+
Engine.
17+
1. Click "Overview" in the left-side navigation menu and copy your Project ID
18+
for use in step 3.3 below.
19+
20+
1. Authentication instructions to run the sample (on your local machine or on a Compute Engine VM):
21+
* Running the sample locally on your development machine:
22+
1. Install [Google Cloud SDK](https://cloud.google.com/sdk/)
23+
1. Run the following command to authorize the Cloud SDK and configure your project:
24+
<pre>gcloud init</pre>
25+
1. Add your authenticated email account as &lt;user-email&gt; and &lt;writer-email&gt; elements to the queue.xml file of the App Engine app that created the pull queue task you're trying to access. For more details, please see
26+
[Defining Pull Queues](https://cloud.google.com/appengine/docs/java/config/queue#Defining_Pull_Queues)
27+
on the Task Queue configuration page.
28+
* Running the sample on a Google Compute Engine VM using Default Application Credentials:
29+
1. Create a service account and add it to queue.xml
30+
1. In the API Manager > [Credentials](https://pantheon.corp.google.com/apis/credentials)
31+
section click "Create credentials" and choose "Service account key".
32+
1. On the "Create service account key" page, select "Compute Engine default service account" from the "Service Account" drop-down menu. Leave the Key type set to JSON and click the "Create" button.
33+
1. Once the service account is created, click the "Manage service accounts" link and copy the "Service account ID" of the "Compute Engine default service account".
34+
1. Add the "Service account ID" as &lt;user-email&gt; and &lt;writer-email&gt; elements to the queue.xml file of the App Engine app that created the pull queue task you're trying to access. For more details, please see
35+
[Defining Pull Queues](https://cloud.google.com/appengine/docs/java/config/queue#Defining_Pull_Queues)
36+
on the Task Queue configuration page.
37+
38+
1. Create a Compute Engine VM Instance.
39+
1. In the [Cloud Console](https://console.cloud.google.com/project)
40+
go to the Compute > Compute Engine section.
41+
1. Click the "Create instance" button.
42+
1. For the 'Boot Disk' select a Linux machine image like Debian or Ubuntu.
43+
1. In the "Indentity API and Access" section, select "Set access for each API" under the "Access Scopes" subsection and then select the
44+
"Task queue" drop-down menu to set its scope.
45+
* Set the "Task queue" access scope to be "Enabled".
46+
1. Click the "Create" button.
47+
1. Once the VM is created click the VM instance's "SSH" button to ssh in to the newly created VM instance.
48+
49+
1. Code checkout instructions:
50+
1. Prerequisites: install [Java 7 or Java 8 JDK][1], [Git][3], and [Maven][4].
51+
You may need to set your `JAVA_HOME` environment variable as well.
52+
* To install these prerequisites on a Linux (Debian or Ubuntu) based Compute Engine VM
53+
instance, run these commands:
54+
<pre>
55+
sudo apt-get update
56+
sudo apt-get install git maven openjdk-7-jdk -y
57+
</pre>
58+
1. Download the sample code by running the following commands:
59+
<pre>mkdir some_directory
60+
cd some_directory
61+
git clone https://github.com/GoogleCloudPlatform/java-docs-samples.git
62+
cd java-docs-samples/taskqueue/cmdline
63+
</pre>
64+
In a text editor open the `TaskQueueSample.java` file. For example, to edit the file with nano:
65+
<pre>nano src/main/java/TaskQueueSample.java</pre>
66+
67+
1. Specify an 'Application Name' for your app by updating the following line of code:
68+
<pre>private static final String APPLICATION_NAME = "";</pre>
69+
1. Save the changes to the file and exit the text editor.
70+
71+
1. Compile and run the sample:
72+
1. Compile the sample code using Maven by running the following command:
73+
<pre>mvn compile</pre>
74+
1. Execute the sample code using Maven by running the following command,
75+
entering your specific values for the placeholder arguments:
76+
<pre>mvn -q exec:java -Dexec.args="&lt;ProjectId&gt; &lt;TaskQueueName&gt; &lt;LeaseSeconds&gt; &lt;NumberOfTasksToLease&gt;"</pre>
77+
1. Running the sample will first list the pull task queue details and then it will lease, process and delete the number of tasks you specified.
78+
79+
You can verify the details of the pull task queue and the leased tasks by visiting the [App Engine > Task queues](https://pantheon.corp.google.com/appengine/taskqueues)
80+
section of the Developers Console.
81+
1. Importing the code into Eclipse and running it from there:
82+
1. Prerequisites: install [Eclipse][5] and the [Maven plugin for Eclipse][6].
83+
1. Download code as specified above.
84+
1. File -> Import -> Maven -> Existing Maven Projects -> Next.
85+
1. Select your project directory as your "Root Directory," and click "Finish."
86+
1. Right-click on project task-queue-rest-sample.
87+
1. Run As > Java Application.
88+
1. If asked, type or select "TaskQueueSample" and click OK.
89+
1. Application output will display in the Eclipse Console.
90+
91+
[1]: http://java.com/en/download/faq/develop.xml
92+
[2]: https://console.cloud.google.com/project
93+
[3]: http://git-scm.com/downloads
94+
[4]: http://maven.apache.org/download.html
95+
[5]: http://www.eclipse.org/downloads/
96+
[6]: http://download.eclipse.org/technology/m2e/releases/
97+

taskqueue/pull/TaskQueueSample.launch

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
2+
<launchConfiguration type="org.eclipse.jdt.launching.localJavaApplication">
3+
<listAttribute key="org.eclipse.debug.core.MAPPED_RESOURCE_PATHS">
4+
<listEntry value="/taskqueue/cmdline/src/main/java/TaskQueueSample.java"/>
5+
</listAttribute>
6+
<listAttribute key="org.eclipse.debug.core.MAPPED_RESOURCE_TYPES">
7+
<listEntry value="1"/>
8+
</listAttribute>
9+
<stringAttribute key="org.eclipse.jdt.launching.CLASSPATH_PROVIDER" value="org.eclipse.m2e.launchconfig.classpathProvider"/>
10+
<stringAttribute key="org.eclipse.jdt.launching.MAIN_TYPE" value="TaskQueueSample"/>
11+
<stringAttribute key="org.eclipse.jdt.launching.PROJECT_ATTR" value="task-queue-rest-sample"/>
12+
<stringAttribute key="org.eclipse.jdt.launching.SOURCE_PATH_PROVIDER" value="org.eclipse.m2e.launchconfig.sourcepathProvider"/>
13+
<stringAttribute key="org.eclipse.jdt.launching.VM_ARGUMENTS" value="-Djava.util.logging.config.file=${project_loc:task-queue-rest-sample}/logging.properties"/>
14+
</launchConfiguration>

taskqueue/pull/logging.properties

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
2+
# Properties file which configures the operation of the JDK logging facility.
3+
# The system will look for this config file to be specified as a system property:
4+
# -Djava.util.logging.config.file=${project_loc:task-queue-rest-sample}/logging.properties
5+
# Set up the console handler (uncomment "level" to show more fine-grained messages)
6+
handlers = java.util.logging.ConsoleHandler
7+
#java.util.logging.ConsoleHandler.level = CONFIG
8+
# Set up logging of HTTP requests and responses (uncomment "level" to show)
9+
#com.google.api.client.http.level = CONFIG

taskqueue/pull/pom.xml

+95
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
<!--
2+
Copyright 2016 Google Inc. All Rights Reserved.
3+
Licensed under the Apache License, Version 2.0 (the "License");
4+
you may not use this file except in compliance with the License.
5+
You may obtain a copy of the License at
6+
http://www.apache.org/licenses/LICENSE-2.0
7+
Unless required by applicable law or agreed to in writing, software
8+
distributed under the License is distributed on an "AS IS" BASIS,
9+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10+
See the License for the specific language governing permissions and
11+
limitations under the License.
12+
-->
13+
<project>
14+
<modelVersion>4.0.0</modelVersion>
15+
<groupId>com.google.cloud.samples</groupId>
16+
<artifactId>taskqueue</artifactId>
17+
<version>1</version>
18+
<!-- Parent POM defines common plugins and properties. -->
19+
<parent>
20+
<groupId>com.google.cloud</groupId>
21+
<artifactId>doc-samples</artifactId>
22+
<version>1.0.0</version>
23+
<relativePath>../..</relativePath>
24+
</parent>
25+
<build>
26+
<plugins>
27+
<plugin>
28+
<artifactId>maven-compiler-plugin</artifactId>
29+
<version>3.5.1</version>
30+
<configuration>
31+
<source>1.7</source>
32+
<target>1.7</target>
33+
</configuration>
34+
</plugin>
35+
<plugin>
36+
<groupId>org.codehaus.mojo</groupId>
37+
<artifactId>exec-maven-plugin</artifactId>
38+
<version>1.4.0</version>
39+
<executions>
40+
<execution>
41+
<goals>
42+
<goal>java</goal>
43+
</goals>
44+
</execution>
45+
</executions>
46+
<configuration>
47+
<mainClass>TaskQueueSample</mainClass>
48+
<systemProperties>
49+
<systemProperty>
50+
<key>java.util.logging.config.file</key>
51+
<value>logging.properties</value>
52+
</systemProperty>
53+
</systemProperties>
54+
</configuration>
55+
</plugin>
56+
<plugin>
57+
<groupId>org.codehaus.mojo</groupId>
58+
<artifactId>findbugs-maven-plugin</artifactId>
59+
<version>3.0.3</version>
60+
<configuration>
61+
<failOnError>false</failOnError>
62+
</configuration>
63+
<executions>
64+
<execution>
65+
<goals>
66+
<goal>check</goal>
67+
</goals>
68+
</execution>
69+
</executions>
70+
</plugin>
71+
</plugins>
72+
<finalName>${project.artifactId}-${project.version}</finalName>
73+
</build>
74+
<dependencies>
75+
<dependency>
76+
<groupId>com.google.api-client</groupId>
77+
<artifactId>google-api-client</artifactId>
78+
<version>1.21.0</version>
79+
</dependency>
80+
<dependency>
81+
<groupId>com.google.apis</groupId>
82+
<artifactId>google-api-services-taskqueue</artifactId>
83+
<version>v1beta2-rev40-1.21.0</version>
84+
</dependency>
85+
<dependency>
86+
<groupId>commons-codec</groupId>
87+
<artifactId>commons-codec</artifactId>
88+
<version>1.10</version>
89+
</dependency>
90+
</dependencies>
91+
<properties>
92+
<project.compute.version>v1-rev105-1.21.0</project.compute.version>
93+
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
94+
</properties>
95+
</project>

0 commit comments

Comments
 (0)