Posts

Introduction to API Gateways

 API Gateways: Authenticattion, authorization and security: Microservices need to be auth when called each other Rate Limits: For specific client we would allow only certain number of calls per hour or per day Fault Tolearation: Means should give default response if perticular service is not up and running Service Aggregation: suppose there is external consumer who wants to call 15 different services is part of one process than its better to aggregate those 15 services and provide to the consumer These are the common feature across all the microservices,and these feature are implemented at the level of API Gateways Instead of allowing microservice to call each other directly , we would make all the calls go through a API Gateway Api Gateway will take care of providing common feature like authentication,  making sure the all services are logged making sure the rate limit are there too, making sure that the services are fault tolerant making sure the aggregation also provided by...

Why Need of Naming Server

Image
 Suppose if we are using Ribbon than it needs a configured if any new server comes up  suppose currently only 2 server was there 8001 and 8000  as given below application .properties file only configured with two server now for any new server like 8002 comes up as we didnt configured into the application properties file currency-exchange-service.ribbon.listOfServers = http://localhost:8000,http://localhost:8001 So for dynamicaly increase and decreasing we need naming server( EurekaNamingServer ) All the instances of All Microservices would register with naming server, that is called service Registration whenever service want to talk to another service like CurrencyCalculationService wants to talk to the CurrencyExchangeService, what would do, it would talk to the NameServer, and it would ask the NameServer what are the instances of the currencyExchangeService that are currently running? This is called S ervice Discovery Service Registration: All Microservice Register with...

Setup Client Side Load Balancing With Ribbon

Image
in prvious video we have imvoked the currencyExchangeService From our CurrencyCalculationService  to calculate the Currency by the quentry and there currnecy exchange in last step we added Feign to make calling the currencyExchangeService from  currencyExchangeService  very easily     So in given Above you can see in Currncy Conversion service we have only 1 Prod instance while Currency Exchange Service we have 4 instances so now hile Conversion service trying to call the Exchange  service than we have to load balance means we would need to distribute the load between all these instance  Thats where Ribbon Comes into the Picture We were using Feing to call Currency Exchange Service Ribbon can make use of the Feign Configuration, that we have already done in previous tutotial and Help us Distirubution the calls between diffrent instances (prod1, prod2 , prod3, prod4) of currency exchange prod service When we enable Ribbon we will see the load will...

Using Feign Rest Client for Service invocation

 In this Tutorial will Learn Importatnt Spring Boot Cloud Component Called Feign F-E-I-G-N in previous Code It was Prety complex code we have written to call a REST Service, there was a lot of  manual stuff that we had to do , to call a very very simple service  Map<String, String> uriVariables = new HashMap<String, String>(); uriVariables .put( "from" , from ); uriVariables .put( "to" , to ); ResponseEntity<CurrencyConversionBean> responseEntity = new RestTemplate() .getForEntity( "http://localhost:8000/currency-exchange/from/{from}/to/{to}" , CurrencyConversionBean. class , uriVariables ); CurrencyConversionBean response = responseEntity .getBody(); There is no complexity was there but we had to still write a lot of code for it So if we talk about the Microservices than there will be a lot of calls to other services. so if you want to make your code much simpler than this Than one of the important problem s...

Create New Microservice CurrencyConverser

Image
List of Dependencied for Createing Currency Conversion Service user same Group as  com.khan.microserservices Web DevTools Actuator Config Client Also configure application.properties spring.application.name= currency-conversion-service server.port= 8100 Make sure to add < dependency > < groupId >org.springframework.cloud</ groupId > < artifactId >spring-cloud-starter-bootstrap</ artifactId > </ dependency > in pom.xml to avoid the spring.config.import error   With Currency Calculation we have to calculate the FROM to To like USD to INR and convert how many 1000 USD to INR will be 86000 INR like that simply 1 USD is worth of 86 INR so 1000 USD will be 86000 INR Create Dummy Currency Conversion service STEP 1 Controller Class @RestController public class CurrencyConversionController { @GetMapping ( "/currency-converter/from/{from}/to/{to}/quantity/{quantity}" ) public CurrencyConversionBean convertCurrency( @PathVariable...

Create a JPA Repository

Image
STEP 1:  ExchangeValueRepository interface which extends JpaRepository public interface ExchangeValueRepository extends JpaRepository<ExchangeValue, Long> { //this method will give the implementation of given below method //this is the magic of Spring data JPA, //Once you provide method defination live given below you will get the implementation automaticaly ExchangeValue findByFromAndTo(String from , String to ); } STEP 2: Entity Class    @Entity public class ExchangeValue { @Id private Long id ; @Column (name= "currency_from" ) private String from ; @Column (name= "currency_to" ) private String to ; @Column (name= "conversion_multiple" ) private BigDecimal conversionMultiple ; @Column (name= "port" ) private int port ; //Getter //getter/setter for port //default and param constructor } STEP 3: Controller Class @RestController public class CurrencyExchangeController { @Autowired private Envi...

Spring Boot Microservice Configure JPA and intialize Data

Image
 STEP 1. Add Given below dependacny in your currencyExchangeService Project < dependency > < groupId >org.springframework.boot</ groupId > < artifactId >spring-boot-starter-data-jpa</ artifactId > </ dependency > < dependency > < groupId >com.h2database</ groupId > < artifactId > h2 </ artifactId > </ dependency >  STEP 2. Now Convert your POJO to @Entity Annotation to Entity class and @Id at data member @Entity public class ExchangeValue { @Id private Long id ; private String from ; private String to ; private BigDecimal conversionMultiple ; private int port ; //Getter/Setter //Constructor }  STEP 2. Create Database using file sql file data.sql in your resource folder