Skip to content

fedexu/love-article

Repository files navigation

Angular Logo Spring Logo

License: GPL v3 sonar qube

Love Article

This is a tutorial project, the purpose is to show one of the many possible implementation of the Microservice Architecture Pattern by using Spring Boot, Spring Cloud and Docker.

angular-pwa-gif

Functional services

Love Article is created with three core microservices. All of them are developed following the pattern Domain-Driven Design (DDD) and they are independently deployable applications.

functional_schema

Favorites service

Contains the favorite articles and metadata about them.

//TODO API TABLE

Articles service

It's the data service that contains all the articles of the site

//TODO API TABLE

Statistics service

Performs calculations about the favorites articles of all the users and the "Hot topic" on the site. It work on the "tag" on the articels and the number of the favorites topic along with the creation date of the article itself. The data generated it's used to order articles list on the main window.

//TODO API TABLE

Infrastructure architecture

In this project there is some distributed system patterns implemented. Spring cloud enhance Spring Boot applications to implement those patterns and it's used in this project along with some Netflix OSS projects.

infrastructure_architecture

Spring Cloud Config Server [Documentation]

Spring Cloud Config provides server-side and client-side support for externalized configuration in a distributed system. With the Config Server, you have a central place to manage external properties for applications across all environments.

Eureka Server [Documentation]

Eureka is a REST based service that is primarily used for locating services for the purpose of load balancing and failover of middle-tier servers. The client also has a built-in load balancer that does basic round-robin load balancing.

Zuul Gateway [Documentation]

Zuul is the front door for all requests from devices and web sites to the backend services. Is built to enable dynamic routing, monitoring, resiliency and security.

Zipkin [Documentation]

Zipkin is a distributed tracing system. It helps gather timing data needed to troubleshoot latency problems in service architectures. Features include both the collection and lookup of this data. You can search the transactions by use the Trace ID generated by Spring sleuth in the dashboard and analize the calls directly with the UI.

Rabbit Mq - Message broker [Documentation]

RabbitMQ is one of the most famous open source message broker. Why a message broker? Leave ad open door to a message broker service in your architecture help you to go to event-driven programming and solve many problem with this approach instead of REST calling between microservices (that is not a good things...)

Security

Advanced security is out of the scope for this POC (proof-of-concept) project. We use a simply JWT authentication implemented with filters on spring security level. To see more of security topic with spring cloud try to see here.

Local environment run

This project use 9 Spring Boot application, 4 Database instances and RabbitMq. Ensure that you have at least 4 Gb RAM available by running it with Docker-compose. A second options is to run the core services (Gateway, Registry, Config, Auth Service and Functional services ) manually.

Before you start

  • Be sure to clone the project with the command: git clone --recurse-submodules <url>
  • Install Docker along with Docker Compose.
  • Build the project: mvn clean package -DskipTests

Run the app

To run the app simply type docker-compose up --build All the images will be builded locally and runned. If you want to detach the process add -d in the command.

Important endpoints

Run locally with Eclipse/IntelliJ:

Run with docker-compose:

To use api with Postman or other tool remember to do a POST on http://"gateway"/auth/login with payload {"username": "dummy", "password": "dummy"} (or other pre-autorized user created in the Docker scripts), to retrieve a valid JWT toket. Otherwise the Gateway will reject any request except the PWA application static files.

Notes

If you see some error in the startup process, no worries. The Docker compose V3 have removed the depends_on option and the application are resilient to the fail startup.

Discovery Service take a while to register all the applications (default heartbeat is 30s). This service will be the first to start up but you need some time to see all the services register to it.

Help me to get the app famous!

Love Article is open source and want to give to you the basics knowledge about cloud native application with Spring and java technologies. A star to this project will be appreciate!