Skip to content

accelero-cloud/tutorials

Repository files navigation

Tutorial

The following tutorial contains 4 microservices implemented with the help of appkernel, which together serve as a product order-processing, payment and shipping solution.

microservices

The Order Service is responsible for receiving the original request and orchestrate the process with all the other services:

  1. reserve the products in the Inventory Service;
  2. carry out the payment, using the Payment Service;
  3. request the shipping of the goods at the Shipping Service;
  4. the Shipping Service will finalise the reservation at the Inventory Service;

With a minimal amount code we get logging, configuration, command line management, persistence, REST communication and much more. For more details check out the roadmap.

Run it in your development environment

Install requirements

Docker image for Mongo DB

docker create -v ~/data:/data/db -p 27017:27017 --name mongo mongo
docker start mongo

Virtual environment and required packages

git clone git@github.com:accelero-cloud/tutorials.git
cd tutorials
virtualenv -p python3 venv
source venv/bin/activate
pip install -U appkernel
pip install money

Start the services

python3 order_service_tutorial.py

And call the Order Service endpoint with CURL:

curl -i -X POST -H "Content-Type:application/json" \
   -d '{
    "_type": "tutorials.order_service.Order",
    "delivery_address": {
        "_type": "tutorials.models.Address",
        "city": "Big City",
        "country": "Country",
        "first_name": "John",
        "last_name": "Doe",
        "postal_code": "1234",
        "street": "some address 8"
    },
    "id": "Oc2e5b438-8d12-4533-b085-c38add1e126d",
    "order_date": "2018-09-04T18:51:18.547186",
    "payment_method": {
        "_type": "tutorials.models.Payment",
        "customer_id": "1234567890123456789012",
        "customer_secret": "120",
        "method": "PAYPAL"
    },
    "products": [
        {
            "_type": "tests.test_util.Product",
            "code": "BTX",
            "name": "t-shirt",
            "price": {
                "_type": "money.money.Money",
                "amount": 10,
                "currency": "EUR"
            },
            "size": "M"
        },
        {
            "_type": "tests.test_util.Product",
            "code": "BTX",
            "name": "t-shirt",
            "price": {
                "_type": "money.money.Money",
                "amount": 12,
                "currency": "EUR"
            },
            "size": "L"
        }
    ]
}
' 'http://127.0.0.1:5000/orders/'

You should see the following result

HTTP/1.1 100 Continue

HTTP/1.0 201 CREATED
Content-Type: application/json
Content-Length: 87
Server: Werkzeug/0.14.1 Python/3.7.0
Date: Tue, 11 Sep 2018 14:17:43 GMT

{
  "_type": "OperationResult",
  "result": "Oc2e5b438-8d12-4533-b085-c38add1e126d"
}

Run it as a set of docker services

Check out the details here

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published