Code Monkey home page Code Monkey logo

appenginequeuedemo's Introduction

Appengine Queue + Task + Worker Demo

I have put this code here for two reasons:

    1. to help others get started on the very useful feature of Tasks and Workers connected by Queues
    1. slightly suprised at the lack of complete code java examples for appengine queues.

What is a Task + Queue + Worker ?

The whole concept is similar to a producer + consumer pattern, connected by a queue. Only the Task = producer, the Worker = Consumer.

This is a nice way of doing threads without the boiler plate thread code. Rather it's kept to http.

Run it up

To run on the command line:

ensure you are running java 7 !!!

>mvn appengine:devserver

Fire in a HTTP POST to

http://localhost:8080/custom/queueTask?message=hello

You will observe the logs come out in a non sequential (different) order ! And there you have a more responsive design. So the worker could be used for sending emails, or sending an sms via a third party.

Analysis

Firstly, look at the web.xml, and take note of the servlet mappings for QueueMailTaskServlet and SendConfirmationLLServlet.

Now, take a look at QueueMailTaskServlet

This is the route in, so that when you call it via a HTTP GET, it will create a Task to be POSTed to /mail/low-level as well as a parameter named message, to be placed on the default queue.

Note, there is no knowledge of the receiving servlet, just the queue and the url (/mail/low-level). This is the glue that connects the call to the worker. They are both nicely decoupled from each other.

Now, look at the SendConfirmationLLServlet, it will act when POSTed to, and will write out a message.

If this was synchronous, then the last thing being written out to the console would be "doing something else now". But it is not.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.