| 1 |
--- |
| 2 |
title: "Order Processor" |
| 3 |
date: 2019-07-09T10:22:39-04:00 |
| 4 |
weight: 5 |
| 5 |
toc: true |
| 6 |
--- |
| 7 |
|
| 8 |
In this tutorial, we will run a Go CDK application called Order Processor |
| 9 |
on a local machine. |
| 10 |
|
| 11 |
<!--more--> |
| 12 |
|
| 13 |
Order Processor is a sample application that lets users place orders to convert |
| 14 |
images to PNG format, and to view the results. The main business logic is |
| 15 |
written in a cloud-agnostic manner using the generic APIs for blob, pubsub and |
| 16 |
docstore. |
| 17 |
|
| 18 |
The Order Processor application has two parts: a web frontend, and an |
| 19 |
image-processing backend called a processor. They communicate over a pubsub |
| 20 |
topic, store order information in a docstore collection, and store image files |
| 21 |
in a blob bucket. |
| 22 |
|
| 23 |
## Prerequisites |
| 24 |
|
| 25 |
You will need to install the following software for this tutorial: |
| 26 |
|
| 27 |
- [Git](https://git-scm.com/) |
| 28 |
- [Go](https://golang.org/doc/install) |
| 29 |
|
| 30 |
Then you need to clone the Go CDK repository. The |
| 31 |
repository contains the Order Processor sample. |
| 32 |
|
| 33 |
```shell |
| 34 |
git clone https://github.com/google/go-cloud.git |
| 35 |
cd go-cloud/samples/order |
| 36 |
``` |
| 37 |
|
| 38 |
## Building |
| 39 |
|
| 40 |
Run the following in the `samples/order` directory: |
| 41 |
|
| 42 |
```shell |
| 43 |
go build |
| 44 |
``` |
| 45 |
|
| 46 |
## Running Locally |
| 47 |
|
| 48 |
If you run `order` with no arguments, both the frontend and the processor will |
| 49 |
run together in the same process. |
| 50 |
|
| 51 |
```shell |
| 52 |
./order |
| 53 |
``` |
| 54 |
The frontend is now running on http://localhost:10538. |
| 55 |
|
| 56 |
Visit the home page in your browser and click "Convert an Image". |
| 57 |
|
| 58 |
Enter an email address (it need not be real) and select any image file from your |
| 59 |
computer. Then click Submit. |
| 60 |
|
| 61 |
Now visit the order list page by returning to the home page and clicking "List |
| 62 |
Conversions". It may take a few seconds to process the order (thanks to an |
| 63 |
artificial delay in the processor), so refresh the page until you see your order |
| 64 |
in the list. |
| 65 |
|
| 66 |
Then click on the output image link to see the converted image in your browser. |
| 67 |
|
| 68 |
## Running on a Cloud Provider |
| 69 |
|
| 70 |
To run the Order Processor application on a cloud provider like Google Cloud |
| 71 |
Platform, Amazon AWS or Microsoft Azure, you will have to provision |
| 72 |
some resources: |
| 73 |
|
| 74 |
- A storage bucket, to hold the image files. (See the |
| 75 |
[`blob` How-To Guide](https://gocloud.dev/howto/blob/).) |
| 76 |
- A Pub/Sub topic and subscription, for requests from the frontend to the |
| 77 |
processor. (See the [`pubsub` How-To Guide](https://gocloud.dev/howto/pubsub/).) |
| 78 |
- A document store collection to store order metadata. (See the [`docstore` How-To |
| 79 |
Guide](https://gocloud.dev/howto/docstore/).) |
| 80 |
|
| 81 |
|
| 82 |
Then launch the `order` program with flags that provide the URLs to your |
| 83 |
resources. Run `order -help` to see the list of flags. |
| 84 |
|