Posts

Showing posts from December, 2021

Running two docker container on same Network# Spring boot microservices # Docker # Docker Images #Docker Container

#consumer class TestController{ @Getmapping("data") public String getData(){ RestTemplate  t=new RestTemplate(); t.getforObject( "http://consumer:8080/getdata",String.class); } } FROM openjdk:8 EXPOSE 8080 ADD target/producer.jar producer.jar ENTRYPOINT ["java","-jar", "producer.jar"] #producer class TestController { @Getmapping("getdata") public String getData(){ return "This reponse comming from producer" } } FROM openjdk:8 EXPOSE 7000 ADD target/consumer.jar consumer.jar ENTRYPOINT ["java","-jar", "consumer.jar"] first craete network :   docker   create --network driver=bridge mynetwork (need correction from book) docker build -f  Dockerfile -t consumer (any name its just a tag name) . docker run -p 81:8080 --name=producer --network=mynetwork producer docker build -f  Dockerfile -t producer (any name its just a tag name) . docker run -p 82:7000 --name=consumer --network=mynetwork cons

What is staters ? How they Work ?

Spring boot provides the number of starters that allows us to add jars in classpath. Spring boot build in startes allowes us  develpoemrnt easier and rapid. Spring boot startes are the dependacy discriptor. In spring boot all the startes  follow same naming pattern spring-boot-starter-* Spring boot startes is combine a group of  common or related dependancies into single dependancy. Example :  Supoose if we want to create spring web application  with tomcat web server then we need to add following minimumn depednacies spring core jar, spring web,spring mvc, spring transaction jar  OK So Spring starter componenets combine  all the related jars into the single jar  file depenandcy to our build file  so insted of adding 4 jars we need to add only one jar in our project example spring -boot-startr-web By adding this spring boot automaticlly download all the related dependacies in our classpath

WebConfig Centralized Configuration In Microservices

 POM.xml  :     WebConfig Server :  -------------------------------------------------------------------------------------------------------------- <properties> <java.version>1.8</java.version> <spring-cloud.version>2020.0.3</spring-cloud.version> </properties> <dependencies> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-actuator</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> </dependency> <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-config-server</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-devtools</artifactId> <s