Skip to content

Practicum : Distributed microservices (Customer & Billing) application made using Spring framework, OpenFeign, Eureka discovery, Gateway.

Notifications You must be signed in to change notification settings

n4rk/microservices-synchronous-app

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Microservices - gestion des clients et factures

TP : Application distribuée basée sur deux micro-services (Customer et Billing) en utilisant Spring framework, OpenFeign, Eureka discovery, Gateway.

Customer-service :

customer-service

  • Main
@SpringBootApplication
public class CustomerServiceApplication {

	public static void main(String[] args) {
		SpringApplication.run(CustomerServiceApplication.class, args);
	}

	@Bean
	CommandLineRunner start(CustomerService customerService) {
		return args -> {
			customerService.saveCustomer(new CustomerRequestDTO(UUID.randomUUID().toString(), "Amine", "amine@devhcm.com"));
			customerService.saveCustomer(new CustomerRequestDTO(UUID.randomUUID().toString(), "Hamza", "hamza@test.com"));
			customerService.saveCustomer(new CustomerRequestDTO(UUID.randomUUID().toString(), "Houssine", "houssine@test.com"));
		};
	}
}

customer-service2

Billing-service :

billing-service

  • OpenFeign
@FeignClient(name = "CUSTOMER-SERVICE")
public interface CustomerRestClient {
    @GetMapping(path = "/api/customers/{id}")
    Customer getCustomer(@PathVariable String id);
    @GetMapping(path = "/api/customers")
    List<Customer> allCustomers();
}
  • Main
@SpringBootApplication
@EnableFeignClients
public class BillingServiceApplication {

	public static void main(String[] args) {
		SpringApplication.run(BillingServiceApplication.class, args);
	}

	@Bean
	CommandLineRunner start(InvoiceService invoiceService) {
		return args -> {
			invoiceService.saveInvoice(new InvoiceRequestDTO(BigDecimal.valueOf(Math.random() * 1000), "79de0b79-d6b7-45e7-b355-6015268eb90e"));
			invoiceService.saveInvoice(new InvoiceRequestDTO(BigDecimal.valueOf(Math.random() * 1000), "79de0b79-d6b7-45e7-b355-6015268eb90e"));
			invoiceService.saveInvoice(new InvoiceRequestDTO(BigDecimal.valueOf(Math.random() * 1000), "1c491bfa-8c29-4cfb-8731-681b107b3654"));
			invoiceService.saveInvoice(new InvoiceRequestDTO(BigDecimal.valueOf(Math.random() * 1000), "1c491bfa-8c29-4cfb-8731-681b107b3654"));
		};
	}

}

billing-service2

Eureka-service :

eureka1

eureka2

Gateway :

gateway1

@Configuration
public class GatewayConfig {
    @Bean
    DiscoveryClientRouteDefinitionLocator discoveryClientRouteDefinitionLocator(
            ReactiveDiscoveryClient rdc,
            DiscoveryLocatorProperties dlp
    ) {
        return new DiscoveryClientRouteDefinitionLocator(rdc, dlp);
    }
}

The gateway now allows the 2 micro-services to communicate with each other through port : 9999

About

Practicum : Distributed microservices (Customer & Billing) application made using Spring framework, OpenFeign, Eureka discovery, Gateway.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages