Push Queues working in App Engine Standard Local Server in Java

47 views
Skip to first unread message

Azeem Haider

unread,
Nov 26, 2017, 5:19:53 AM11/26/17
to Google App Engine
I'm new in Task Queues. I added one Push queue to test it how it work. 
As mention in documentation I added one task in default queue.

Queue queue = QueueFactory.getDefaultQueue();
queue
.add(TaskOptions.Builder.withUrl("/insertentity"));

Here is insert entity code.

@SuppressWarnings("serial")
@WebServlet(name = "InsertEntity", description = "Insert entries in datastore",
 urlPatterns
= "/insertentity")
public class InsertEntity extends HttpServlet {

   
@Override
     public void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException,
         
ServletException {
     
     
PrintWriter out = resp.getWriter();
       resp
.setContentType("text/plain");

       
Post post = new Post("This is Fourth Post");
       post
.setUserKey(Key.create(User.class, 123));
     
       
ofy().save().entity(post).now();

     
out.print("post is saved \n");

   }
   
}

I'm just saving one entity in datastore to test it. 

After adding Push Queue I checked the dashboard it successfully added there.

I wait more than one minute and after that I checked datastore there is no entity is added. and Task Queue viewer still showing there is one task in queue, why it's not running ?
I click on run button to execute it manually it show the message task is running but if I check datastore there is no entity added and still there is one task in queue Even how many times I click on Run Button to execute it. 

How can I get log message. How I know what's the problem ? 
InsertEntity file work fine If I run it manually it successfully add entity in datastore. 

George (Cloud Platform Support)

unread,
Nov 27, 2017, 3:02:59 PM11/27/17
to Google App Engine
Hello Azeem, 

If you want to get familiar with task queues, you are encouraged to follow a complete example. The one provided in documentation is: "Enqueue.java" on github. Related clarification is provided in the "Creating Tasks" on-line document

In particular, the code portion dealing with task creation is a little more complex: 

import com.google.appengine.api.taskqueue.Queue;
import com.google.appengine.api.taskqueue.QueueFactory;
import com.google.appengine.api.taskqueue.TaskOptions;

Queue queue = QueueFactory.getDefaultQueue();
queue.add(TaskOptions.Builder.withUrl("/worker").param("key", key));

It seems that writing to the datastore fails. It might be advisable to modify the line: 

ofy().save().entity(post).now(); 

and modify it in similar to: 

@Entity
class Car {
    @Id String vin; // Can be Long, long, or String
    String color;
}

that is by creating a class for the entity and instantiating it with a "new" statement: 

ofy().save().entity(new Car("123123", "red")).now(); 

More information is to be found in the github page for Objectify, under "Features". 

You may check your app's logs for relevant messages. If you would like us to examine your project's logs and general settings, you may send us private email with project ID using the drop-down menu at the top right of the edit window. 


Azeem Haider

unread,
Nov 28, 2017, 12:11:21 AM11/28/17
to Google App Engine
Thanks for your time. I found problem by my self. 

If you see file insertentity carefully there is only one method doGet() which receive only Get Requests. 
But sending request with task queue is Post Request by Default. Just add another method doPost() and everything 
is working fine.
OR
send a task queue request with method GET 

George (Cloud Platform Support)

unread,
Nov 28, 2017, 9:39:46 AM11/28/17
to Google App Engine
Glad to hear you have found the proper solution to this issue. For the benefit of the public at large, it would help if you post a detailed description of the solution, with code examples. 
Reply all
Reply to author
Forward
0 new messages