Git Product home page Git Product logo

ftgo-application-fork's Introduction

FTGO example application

This is the example code for my book Microservice patterns.

Microservices Patterns Cover

Please note

  • The code is still work in progress

  • It primarily illustrates the technical aspects of the microservice architecture and so the business logic is minimal

  • The documentation is sparse/non-existent and you will need to look in the book

  • The application consists of many services and so requires a lot of memory. It runs well, for example, on a 16GB Macbook pro.

  • The application’s services and the infrastructure services, such as MySQL and Apache Kafka, are deployed using Docker containers using either Docker Compose or Kubernetes.

Got questions

Please post a message to the book’s discussion forum or create a github issue. I’ll do my best to help you.

Application architecture

Not surprisingly, this application has a microservice architecture. There are the following services:

Service design

Key points:

  • A service consists of a single Gradle module. For example, ftgo-order-service implements the Order Service

  • A service is a Spring Boot application

  • A service has a Swagger UI http://…​/swagger-ui.html. See open-swagger-uis.sh

  • A service typically consists of the following packages:

    • domain - domain logic including aggregates

    • messaging - messaging adapters

    • web - Spring MVC controllers (HTTP adapters)

    • main - the main application

  • The services use the following other frameworks

Chapter by chapter

This section maps the chapters to the code.

Chapter 3 Inter-process communication in a microservice architecture

  • The services have a REST API

  • The services also communicate using the Apache Kafka message broker via the Eventuate Tram framework

Chapter 4 Managing transactions with sagas

The ftgo-order-service uses sagas to maintain data consistency:

The services that participate in these sagas define the following command handlers:

Chapter 5 Designing business logic in a microservice architecture

All the services' business logic is implemented using Domain-Driven design aggregates.

Chapter 6 Developing business logic with event sourcing

Chapter 7 Implementing queries in a microservice architecture

Chapter 8 External API patterns

Building and running the application

Pre-requisites

  • Java 8+

  • Docker and Docker Compose

  • Internet access so that Gradle and Docker can download dependencies and container images

Building

Temporary: Build the Spring Cloud Contracts using this command:

./build-contracts.sh

Build the services using this command:

./gradlew assemble

Setting environment variables

Quick way

A quick way to set the environment variables is to run the script ./set-env.sh

Long way

To run the application you must set the DOCKER_HOST_IP environment variable to the IP address of where the Docker containers are running:

  • Docker toolbox/Virtual machine - IP address of the virtual machine

  • Docker for Windows/Mac/Linux - IP address of your laptop/desktop

Please do NOT set it to the (unresolvable) hostname of your machine, localhost or 127.0.0.1.

You must also set the AWS environment variables.

Running the application

Run the application using this command:

docker-compose up -d

This can take a while.

Using the application

Use the services Swagger UIs to invoke the services.

You can also access the application via the API Gateway at http://${DOCKER_HOST_IP?}:8087. However, currently it doesn’t have a Swagger UI so you will have to use curl, for example.

Stopping the application

Stop the application using this command:

docker-compose down -v

Deploying the application on Kubernetes

You can find Kubernetes YAML files in the following directories: deployment/kubernetes and */src/deployment/kubernetes. There are also some helpful shell scripts.

Deploying services

You can run this command

./deployment/kubernetes/scripts/kubernetes-deploy-all.sh

Undeploying the services

You can run the script to undeploy the services:

./deployment/kubernetes/scripts/kubernetes-delete-all.sh

If you want to delete the persistent volumes for Apache Kafka, Zookeeper and MySQL please run the command:

./deployment/kubernetes/scripts/kubernetes-delete-volumes.sh

ftgo-application-fork's People

Contributors

cer avatar dartartem avatar

Watchers

 avatar  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.