Step 01 - Part 1 I and Part 2 ntro to Limits Microservice And Spring Cloud Config Server

 Step 01 - Part 1 Intro to Limits Microservice And Spring Cloud Config Server





In given Above example we have diffrent Envirnmnet and there respecitve environments
Dev Has 1 Environment
QA Has 2 Environment
STAGE has 1 Environment
PROD has 4 Environments

So by given above exmaple we understand like we have Different services Like
CurrencyCalculationService, CurrencyExchangeService, LimitService and 
all each of these has diffrent number of environments for each type of Environment(DEV,QA,STAGE,PROD)

So this type of congifuration managing the individually for each application and each environment is very very difficult, thats where centralized configuration comes into the Picture Spring Cloud Config Server



1. Spring Cloud Config server says you can put all the configuration for your application into GIT Repository
2. and It will take care of managing the configuration and providing it to the specific Microservice
Example: if Limit service says i would want the configuration for dev environment for limit service than Spring Cloud Config Server would be able to provide it to it

so here Spring Cloud Config Server would act as the centralizeed microservice configuration application

STEP 1: Creat Project Limit-Service (MicroService)



Export this project and Import in your Eclipse

To resolve Given Below error 

org.springframework.cloud.commons.ConfigDataMissingEnvironmentPostProcessor$ImportException: No spring.config.import set




Add the Dependancy in Pom.xml

<dependency>

<groupId>org.springframework.cloud</groupId>

<artifactId>spring-cloud-starter-bootstrap</artifactId>

</dependency>


Project Structure




STEP 2: Creat Hard Coded Limit-Service (MicroService)

Our eventual goal with Limit Service is we would want it to connect to the spring Cloud config server

 for that we need to configure a few values in application.properties and expose a service using the limit service to retrieve those values

spring.application.name=limits-service


As we create more and more microservices we would want to give the applications a name so that we can easily identify them.as we have given above example in application.properties file "limits-service"

also we need to configure server.port property if we are go so on other services as we need to deploye other service into diffrents port 

Create Controller Class

@RestController
public class LimitConfigurationController {
@GetMapping("/limits")
public LimitConfiguration retrieveLimitsFromConfigurations() {
return new LimitConfiguration(1000, 1);
}
}

Create Pojo Class

public class LimitConfiguration {

private int maximum;

private int minimum;

protected LimitConfiguration() {

}

public LimitConfiguration(int maximum, int minimum) {

super();

this.maximum = maximum;

this.minimum = minimum;

}

public int getMaximum() {

return maximum;

}

public int getMinimum() {

return minimum;

}

}


Run the Application we will recieve hard code value as given below



Comments

Popular posts from this blog

Microservice with Java Spring Cloud

STEP 10 Configure Porfile for Limit service

STEP 9 Connect Limit service to Spring Cloud Config Server