Used Libraries

  1. Netflix Eureka naming server
  2. Netflix Zuul
  3. Ribbon
  4. Feign

Network Architecture of the system

This Architecture Contains Four Applications

  1. Load balancing application [netflix-eureka-naming-server]
  2. Server application [micro-service-server]
  3. Client application [micro-service-client]
  4. API gateway application [api-gateway-server]

Steps To Run The Applications

  1. Install JDK 11 or latest.
  2. Clone git repository of the project into local.
  3. Github: https://github.com/VishnuViswam/LOAD-BALANCER-WITH-API-GATEWAY.git
  4. Run Load balancing application first.
  5. Run The API gateway application.
  6. Then run Server application in two ports.
  7. At last run Client application.

1) Load Balancing Application

All client server communication will be done through this load balancing server application.

pom.xml

We are using netflix-eureka-server library to enable the communication between client and server.

XML

<properties>
    <java.version>11</java.version>
    <spring-cloud.version>Hoxton.SR4</spring-cloud.version>
</properties>
<dependencies>
  <dependency>
    <groupId>org.springframework.cloud</groupId>
    <artifactId>spring-cloud-starter-config</artifactId>
  </dependency>
  <dependency>
    <groupId>org.springframework.cloud</groupId>
    <artifactId>spring-cloud-starter-netflix-eureka-server</artifactId>
  </dependency>
</dependencies>

application.properties

Properties files

spring.application.name=netflix-eureka-naming-server // application unique name
server.port=8761 // It will be the default port which eureka naming server
eureka.client.register-with-eureka=false
eureka.client.fetch-registry=false

NetflixEurekaNamingServerApplication.java

@EnableEurekaServer  named annotation will allow the eureka server to control this application.

Java

@SpringBootApplication
@EnableEurekaServer // to enable the communication with Eureka server
public class NetflixEurekaNamingServerApplication {
    public static void main(String[] args) {
        SpringApplication.run(NetflixEurekaNamingServerApplication.class, args);
    }
}

After running this application we can access the eureka server dashboard under following URL.

Link: http://localhost:8761

Eureka Server Dashboard

#java #spring boot #rest api #microservice architecture #spring cloud #api gateway #load balancer #web service clients #sample applications

Create an API Gateway with Load Balancer Using Java
23.60 GEEK