Skip to content
This repository has been archived by the owner on Apr 9, 2022. It is now read-only.

pjdaye/banking-microservices-example

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Banking Microservices Tutorial

Build Status Coverage Status

The Banking Microservices Example project is a small system used to show how microservices can be implemented and tested with Micronaut, Consul, Tyk, and Axon's Event Sourcing framework. The system can be run in multiple configurations using Docker.

Architecture

Build Status

Figure 1: Overall Banking Example architecture.

Build Status

Figure 2: Flow of communication between domain architectures.

Configuration

The services can be configured in three ways, a local default configuration under each project resources/application.yml, a development coniguration under resources/application-dev.yml, and the centralized configuration service.

Requirements

See each services readme for detailed requirement information

Compose

Java 8

Lombok

Running the Project

Start the Microservices

** Build JARs for each project (You will need to build a JAR anytime changes are made to a project, then rebuild either the container or all containers)

# Assemble the binaries
./gradlew assemble
# Start the backing services: service discovery, configuration, authentication, edge service
docker-compose -f docker-compose-backing.yml up
# After the backing services have succesfully loaded, start the domain services
docker-compose up

Start the Microservices with ELK Stack

# Assemble the binaries
gradle assemble
# Start the backing services: service discovery, configuration, authentication, edge service
docker-compse -f docker-compose-backing.yml up
# While the backing services are starting, start the ELK stack, note you will need to also follow the ELK steps below
docker-compose -f elk/docker-compose.yml up
# Once all the supporting services are loaded, start the domain services configured to log to ELK
docker-compose -f docker-compose-elk.yml up

Stop the Containers

docker-compose down
docker-compose -f docker-compose-elk.yml down
docker-compose -f docker-compose-backing.yml down

Rebuild Containers

docker-compose build

Executing Tests

Running Unit and Integration Tests

The Gradle task 'test' executes the JUnit tests for each project.

sh run-unit-tests.sh

Running Code Coverage: Unit and Integration Tests

JaCoCo is used for code coverage and can be run after the unit and integraiton tests for each service have been executed. You can find a JaCoCo coverage report under the "coverage" in transaction service after running the unit tests.

Running Contract Tests

Start the domain services with internal mocks so that only the endpoints will be tested. Internally Mocked Services

docker-compose -f docker-compose-internal-mocked.yml up -d

Start the PactBroker service and check http://localhost:8089 that it is live.

docker-compose -f ./pact-broker/docker-compose.yml up -d

Generate the PACTs and execute them.

sh ./scripts/generate-publish-pact-tests.sh
sh ./scripts/run-pact-tests.sh

Stop the PactBroker.

docker-compose -f ./pact-broker/docker-compose.yml down

Stop the services with internal mocks.

docker-compose -f docker-compose-internal-mocked.yml down

Running Service Isolation Tests

Running Service Isolation Tests with All External Dependencies Mocked

Mocking all external dependencies to the services allows for very rapid execution of tests and alleviates the need for configuring or utilizing resources for the external dependencies. Externally Mocked Services Docker is not required to run these tests as all external dependencies are mocked.

sh isolation-test-mocked.sh

Running Service Isolation Tests with External Dependencies

Here only the calls to other services are mocked, but external dependencies like databases, caches, and discovery services are deployed. Externally Mocked Services Start the external dependencies with Docker Compose.

docker-compose -f docker-compose-backing.yml up

Execute the tests in a new terminal once external dependencies have started.

sh isolation-test.sh

Tear down the external dependencies.

docker-compose -f docker-compose-backing.yml down

Running Service Integration Tests

Coming soon

API Documentation:

These request can be done using an application like postman or insomnia, directly with curl or using the provided swagger UI. Go to the swagger for the port that customer application is running. By default, it is 8082 but it can be changed in the docker-compose files.

alt text

From there click on the customer-controller drop down, expand the post endpoint and click the try it out button: alt text

Then a body can be provided to make a request to the service, here is an example valid body, feel free to put your name here:

{
     "firstName": "John",
     "id": "f6e0ef7e-93af-47e0-b665-e9fbdc184b43",
     "lastName": "Doe"
}

Then click on the execute button

alt text

And scroll down to see what the response was:

alt text Now to create some accounts for this user:

Go to the ui for account-cmd, running on 8089. And open account-controller post endpoint

Put the previous customerId in the body for the request and execute it.

alt text The response should have the generated Id for the account just created. Copy it somewhere, then execute again and copy the second account id too, both will be used for transactions in a moment.

First quickly check the accounts got created checking the account query side

Check the two account ids against the get endpoint, they return a 200 response with the account info and balances of 0. alt text

Now, making some transactions lets first make a deposit

Provide an amount along with the previous obtained ids for account and customer. This will respond with a transaction id that is not important for now. alt text

If the same account is now check on the account query side the balance should shown as the deposited account.

Now, going to the transfer endpoint and making a transaction to pass some of that balance to the other account alt text

Check that the response was a 200 and the balances changed

Running with Centralized Logging (ELK stack)

To run with centralized logging and logging visualizations follow the steps below.

Start the ELK stack

Micronaut Isolation test configs

MICRONAUT_ENVIRONMENTS=test,mock

About

Example project for microservices

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Java 88.5%
  • Groovy 8.2%
  • TypeScript 1.9%
  • Other 1.4%