Sign inSign up

chinnonsantos/purchase-service

By chinnonsantos

•Updated over 6 years ago

Purchase microservices demo, usinged by Nudemo mobile app.

Image
0

344

chinnonsantos/purchase-service repository overview

⁠PURCHASE MICROSERVICES DEMO

Travis build status Codecov coverage Clojure version GitHub license Twitter follow Open source Love

This project deals with a purchase microservice created from the leiningen 'compojure⁠' template.

Usinged by Nudemo mobile app⁠.

⁠Prerequisites

You will need Leiningen⁠ 2.9.1 or above installed.

Libraries:

Plugins:

⁠Running server

To start a web server for the application, run:

lein ring server-headless

Default ring port changed from 3000 to 9002

⁠Running tests (TDD)

To test the project, run:

lein midje

To test the project in development stage, run:

lein midje :autotest

Automatically reloading the test with each change

To test only Unit tests of the project, run:

lein midje :filter unit

To test only Assertion tests of the project, run:

lein midje :filter assertion

To check test coverage, run:

lein cloverage --runner :midje

⁠E2E Testing

To perform a quick End-to-End test on this service (with cURL)

  • Check health

    curl http://localhost:9002/
    
  • Get balance

    curl http://localhost:9002/balance/:account-id/
    

    The :account-id is an UUID⁠ informed when creating registration

  • Get purchase list (from account ID)

    curl http://localhost:9002/purchase/from-account/:account-id/?tag=footwear&tag=furniture
    

    The :account-id is an UUID⁠ informed when creating registration Filters have not been implemented yet!

  • Get purchase info (purchase details)

    curl http://localhost:9002/purchase/:purchase-id/
    

    The :purchase-id is an UUID⁠ automatically generated by the service after registration

  • Create a purchase

    curl -X POST \
    -d '{"account-id": "8b84c28c-8947-4e67-87d8-68f65ebca105", "type": "income", "value": 300.00, "origin": {"code": 0, "name": "bill payment"}, "tag": ["bill", "prepayment"]}' \
    -H "Content-Type: application/json" \
    localhost:9002/purchase/
    
  • Hitting an invalid route

    curl http://localhost:9002/invalid/
    

To perform a complete automated End-to-End test on this service I recommend use the Postman⁠

⁠Deployment

To create standalone artifact (.jar)

lein ring uberjar

To run standalone artifact (need Java JRE)

java -jar target/purchase-1.0.2.jar

See all releases of this project here⁠!

⁠Containerization w/ Docker

This project is available in a containerized form on the Docker hub⁠ repository.

To running the container with Docker⁠ commands

sudo docker network create nudemo-services
sudo docker run -d --rm --name purchase --net nudemo-services -p 9002:9002 chinnonsantos/purchase-service:1.0.2

To go up the service manually with Docker⁠ commands

# Ubuntu eoan -> 19.10
sudo docker network create nudemo-services
sudo docker run -it --rm --name purchase --net nudemo-services -p 9002:9002 ubuntu:eoan

## Inside the container... (sudo docker attach purchase-service)
# Updating Ubuntu APT packages
apt update
# Installing Wget package
apt install wget -y
# Installing OpenJDK 11
apt install openjdk-11-jre-headless -y && java --version
# Installing Leiningen
cd /usr/local/bin && wget https://raw.githubusercontent.com/technomancy/leiningen/stable/bin/lein && ls
chmod +x lein && ls && ./lein && lein -v
# Creating app directory
mkdir /home/purchase-service

## Outside the container... (Ctrl+P and Ctrl+Q)
# Copying project files to container ('~/Projects/' change to 'YOUR_PROJECT_FOLDER')
sudo docker cp ~/Projects/purchase-service/src purchase-service:/home/purchase-service/src
sudo docker cp ~/Projects/purchase-service/project.clj purchase-service:/home/purchase-service

## Inside the container... (sudo docker attach purchase-service)
# Downloading Leiningen project dependencies
cd /home/purchase-service
lein deps
# Create standalone artifact (.jar)
lein ring uberjar
# Uninstalling packages and cleaning the system for reduce container size
apt remove wget -y && apt autoremove -y && apt autoclean -y && apt clean -y
cp target/purchase-1.0.2.jar .
rm -rf /var/lib/apt/lists/ /tmp/ /var/tmp/ /root/.lein/ /root/.m2/ /root/.wget-hsts /usr/local/bin/lein /home/purchase-service/project.clj /home/purchase-service/src/ /home/purchase-service/target/ /home/purchase-service/test/
# Starting service (run standalone artifact)
java -jar purchase-1.0.2.jar

To go up the service automatically with Dockerfile⁠

sudo docker build -t chinnonsantos/purchase-service:1.0.2 --no-cache .
sudo docker network create nudemo-services
sudo docker run -d --rm --name purchase --net nudemo-services -p 9002:9002 chinnonsantos/purchase-service:1.0.2

See all images of this project here⁠!

⁠Containerization w/ Docker-compose or Amazon ECS (AWS Fargate)

To set up a local cluster with Docker-compose⁠ or a cluster on Amazon Elastic Container Service (ECS)⁠ with AWS Fargate⁠ for customer-service⁠, account-service⁠ and purchase-service⁠ container images, see the NUDEMO SERVICES⁠ repository.

⁠Origin class codes

Code definition by transaction type (named in brazilian portuguese)

We don't cover system messages in this demo!

⁠License

Copyright © 2019 ~ 2020 | Chinnon Santos | Apache License 2.0

Tag summary

Content type

Image

Digest

Size

159 MB

Last updated

over 6 years ago

docker pull chinnonsantos/purchase-service