Giter VIP home page Giter VIP logo

demo-loan-application-as-java's Introduction

Loan application DEMO - Java - Event Sourced

Prerequisite

  • Java 11
  • Apache Maven 3.6 or higher
  • Akka Serverless:
  • Docker 20.10.8 or higher (engine and client)
  • Docker Hub account (configured with Docker)
    Access to the gcr.io/akkaserverless-public container registry
    cURL
    IDE / editor

Generate Java project (terminal)

mvn archetype:generate \
  -DarchetypeGroupId=com.akkaserverless \
  -DarchetypeArtifactId=akkaserverless-maven-archetype \
  -DarchetypeVersion=0.10.6
Define value for property 'groupId': io.as
Define value for property 'artifactId': loan-application
Define value for property 'version' 1.0-SNAPSHOT: :
Define value for property 'package' com.example: : io.as.loanapp

Import in IDE

Cleanup (IDE)

Delete:
src/main/proto/io/as/loanapp/counter_api.proto
src/main/proto/io/as/loanapp/domain/counter_domain.proto

API descriptor - endpoints (IDE)

Note: For code snippet insertion use command+J (MAC)

  1. Create file loan_app_api.proto in src/main/proto/io/as/loanapp folder.
  2. Edit src/main/proto/io/as/loanapp/loan_app_api.proto in IDE
  3. Insert header snippet: aheader
  4. Insert commands snippet: acmd
  5. Insert state snippet: astate
  6. Insert service snippet: asrv
  7. Add functions to service snippet (place cursor inside brackets service LoanAppService { }): afunc

API descriptor - domain (IDE)

  1. Create file loan_app_domain.proto in src/main/proto/io/as/loanapp/domain folder.
  2. Edit src/main/proto/io/as/loanapp/domain/loan_app_domain.proto in IDE
  3. Insert header snippet: dheader
  4. Insert events snippet: devts
  5. Insert state snippet: dstate

API descriptor - codegen annotations (IDE)

  1. Edit src/main/proto/io/as/loanapp/loan_app_api.proto
  2. Insert codegen annotations (place cursor under service LoanAppService { ): acodegen

Codegen

  1. Code generation (terminal):
mvn compile
  1. Refresh project (IDE)
  2. Trigger Maven sync (IDE)

Business logic implementation (IDE)

  1. Edit src/main/java/io/as/loanapp/domain/LoanAppEntity class
  2. Delete class body
  3. Insert code snippet (delete everything under constructor): eall

Implement unit test

  1. Edit src/test/java/io/as/loanapp/domain/LoanAppEntityTest class
  2. Delete class body
  3. Insert code snippet: ut

Run unit test (terminal)

mvn test

Implement integration test (IDE)

  1. Edit src/it/java/io/as/loanapp/LoanAppEntityIntegrationTest class
  2. Delete everything under the constructor
  3. Insert code snippet: it

Run integration test (terminal)

mvn -Pit verify

Run locally

??

Package

  1. Edit pom.xml and update my-docker-repo in <dockerImage>my-docker-repo/${project.artifactId}</dockerImage>
  2. Execute in terminal:
mvn package
  1. Push docker image to repository:
mvn docker:push

Deploy to Akka Serverless

  1. Deploy project:
akkasls service deploy loan-application aklikic/loan-application:1.0-SNAPSHOT

Note: replace aklikic as in Package 2. Expose service:

akkasls services expose loan-application
  1. List routes:
akkasls routes list                 
NAME           HOSTNAME                                           PATHS             CORS ENABLED   STATUS          
loan-application    fragrant-mud-9702.us-east1.akkaserverless.app   /->loan-application   false          NotConfigured   

Note: HOSTNAME is dedicated hostname for this service and is publicly accessible on Internet

Test service in production

  1. Submit loan application
curl -XPOST -d '{
  "client_id": "1111",
  "client_monthly_income_cents": 60000,
  "loan_amount_cents": 20000,
  "loan_duration_months": 12
}' https://fragrant-mud-9702.us-east1.akkaserverless.app/loanapp/123456 -H "Content-Type: application/json"
  1. Get loan application:
curl -XGET https://fragrant-mud-9702.us-east1.akkaserverless.app/loanapp/123456 -H "Content-Type: application/json"
  1. Approve:
curl -XPUT https://fragrant-mud-9702.us-east1.akkaserverless.app/loanapp/123456/approve -H "Content-Type: application/json"

Eventing (optional)

  1. Create file loan_app_topic.proto in src/main/proto/io/as/loanapp folder.

  2. Edit src/main/proto/io/as/loanapp/loan_app_topic.proto in IDE

  3. Insert header snippet: dheader

  4. Insert events snippet: devts

  5. Insert service snippet: dsrv

  6. Insert functions snippet (place cursor inside brackets service LoanAppToTopic { }): dfunc

  7. Code generation (terminal):

mvn compile
  1. Refresh project (IDE)
  2. Trigger Maven sync (IDE)
  3. Edit src/main/java/io/as/loanapp/LoanAppToTopicAction class
  4. Delete class body
  5. Insert code snippet: tall

Copy-paste list

mvn archetype:generate \
  -DarchetypeGroupId=com.akkaserverless \
  -DarchetypeArtifactId=akkaserverless-maven-archetype \
  -DarchetypeVersion=0.10.6
io.as
loan-application
io.as.loanapp
loan_app_api.proto
loan_app_domain.proto
mvn compile
mvn test
mvn -Pit verify
mvn package
mvn docker:push
akkasls service deploy loan-application aklikic/loan-application:1.0-SNAPSHOT
curl -XPOST -d '{
  "client_id": "1111",
  "client_monthly_income_cents": 60000,
  "loan_amount_cents": 20000,
  "loan_duration_months": 12
}' https://fragrant-mud-9702.us-east1.akkaserverless.app/loanapp/1234567 -H "Content-Type: application/json"
curl -XGET https://fragrant-mud-9702.us-east1.akkaserverless.app/loanapp/1234567 -H "Content-Type: application/json"
curl -XPUT https://fragrant-mud-9702.us-east1.akkaserverless.app/loanapp/1234567/approve -H "Content-Type: application/json"
loan_app_topic.proto

demo-loan-application-as-java's People

Contributors

aklikic avatar

Watchers

 avatar

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.