Skip to content

el-moudni-hicham/microservices-spring-cloud-angular

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

27 Commits
 
 
 
 
 
 
 
 

Repository files navigation

🌱 Microservices with Spring Cloud

 • Spring Cloud Gateway
 • Eureka Discovery
 • Open Feign Rest Client
 • Hystrix DashBoard 

Project Class Diagram

Table of contents

Customer Service

Create a new Spring project :

project example

Selected dependencies

• Spring Web 
• Spring Data JPA 
• H2 Database
• Rest Repositories 
• Lombok
• Spring Boot DevTools
• Eureka Discovery Client
• Spring Boot Actuator 

Application Configuration application.properties

spring.application.name=customer-service
spring.datasource.url=jdbc:h2:mem:customers-db
spring.cloud.discovery.enabled=true
#management.endpoints.web.exposure.include=*
server.port=8888

Steps :

1. Create Customer entity

package ma.enset.customermicroservice.entites;

import jakarta.persistence.Entity;
import jakarta.persistence.GeneratedValue;
import jakarta.persistence.GenerationType;
import jakarta.persistence.Id;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.ToString;

@Entity
@Data @NoArgsConstructor @AllArgsConstructor @ToString
public class Customer {
  @Id @GeneratedValue(strategy = GenerationType.IDENTITY)
  private Long id;
  private String name;
  private String email;
}

2. Create CustomerRepository Spring Data based interface

package ma.enset.customermicroservice.repository;

import ma.enset.customermicroservice.entites.Customer;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.rest.core.annotation.RepositoryRestResource;

@RepositoryRestResource
public interface CustomerRepository extends JpaRepository<Customer, Long> {
}

3. Deploy Restful API of microservice with Spring Data Rest

4. Microservice test

Customers

project example

Find Customer By Id

project example

Actuator

project example

Actuator Health

project example

Database H2

project example

Inventory Service

Application Configuration application.properties

spring.application.name=inventory-service
spring.datasource.url=jdbc:h2:mem:products-db
spring.cloud.discovery.enabled=true
server.port=8889

Steps :

  1. Create Product entity
  2. Create ProductRepository Spring Data based interface
  3. Deploy Restful API of microservice with Spring Data Rest
  4. Microservice test

All Products
project example

Database

Gateway Service

Selected dependencies

• Gateway 
• Spring Boot Actuator
• Hystrix 
• Eureka Discovery Client 

1. Static routes configuration : application.yml / application.properties

application.properties

spring.application.name=gateway-service
spring.cloud.discovery.enabled=true
server.port=8890

application.yml

spring:
  cloud:
    gateway:
      routes:
        - id : r1
          uri : http://localhost:8888/
          predicates :
            - Path= /customers/**
        - id : r2
          uri : http://localhost:8889/
          predicates :
            - Path= /products/**

Access to All Customers from Gateway
project example

Access to All Products from Gateway

2. Static routes configuration : Java Config Class

    @Bean
    RouteLocator routeLocator(RouteLocatorBuilder builder){
        return builder.routes()
                .route("r1", (r) -> r.path("/customers/**").uri("http:https://localhost:8888/"))
                .route("r2", (r) -> r.path("/products/**").uri("http:https://localhost:8889/"))
                .build();
    }

Access to All Customers from Gateway
project example

Access to All Products from Gateway

3. Eureka Discovery Service : Dynamic Routing

Eureka Discovery Service

Selected dependencies

• Eureka Server

EnableEurekaServer

@SpringBootApplication
@EnableEurekaServer
public class EurekaDiscoveryApplication {
    public static void main(String[] args) {
        SpringApplication.run(EurekaDiscoveryApplication.class, args);
    }
}

application.properties

server.port=8761
# dont register server itself as a client.
eureka.client.fetch-registry=false
# Does not register itself in the service registry.
eureka.client.register-with-eureka=false

Eureka Spring

Static routes configuration with Discovery Service

    @Bean
    RouteLocator routeLocator(RouteLocatorBuilder builder){
        return builder.routes()
                .route("r1", (r) -> r.path("/customers/**").uri("lb:https://CUSTOMER-SERVICE"))
                .route("r2", (r) -> r.path("/products/**").uri("lb:https://INVENTORY-SERVICE"))
                .build();
    }

Access to All Customers from Gateway
project example

Access to All Products from Gateway

Dynamic routes configuration with Discovery Service

    @Bean
    DiscoveryClientRouteDefinitionLocator definitionLocator(ReactiveDiscoveryClient rdc,
                                                            DiscoveryLocatorProperties dlp){
        return new DiscoveryClientRouteDefinitionLocator(rdc, dlp);
    }

Access to All Customers from Gateway
project example

Access to All Products from Gateway

Billing Service

Selected dependencies

• OpenFeign 
• Spring HATEOAS

Service Test

Bill Complet Informations
project example

Bill Complet Informations
project example

Access to All Products from Gateway

II - Front End Part with Angular :

Link to Front End part.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages