Microservices Summary

Summary of MicroServices

Order of Start Services

service-registry Eureka Service Discovery Server http://localhost:8761/
Hystrix-Dashboard(Optional) CirCuit Breaker/ Falut tolrence Dashboard only http://localhost:8788/
IDaamApiGateway Zuul API Gateway http://localhost:8099
Sleuth and Zipkin Distributed Tracing. Just adding dependency logs will generated with TraceID Run Server cd C:\kafka java -jar zipkin.jar http://127.0.0.1:9411/
UserServiceWithKafka UserProisionKafkaser http://localhost:8051/
EDCMicroService   http://localhost:8031/edc/
MIMicroService   http://localhost:8041/mi/
Eureka Service Discovery Server Separate Server Add spring-cloud-starter-netflix-eureka-server dependency Add @EnableEurekaServer to main class Update application.properties with port & other details EDC, MI Microservices End Add the Eureka clinet dependency spring-cloud-eureka-client. Add Eureka Server URL in application.properties eureka.client.service-url.defaultZone=http://localhost:8761/eureka/ By adding this, at start up they will register to eureka servre If EDC has 4 Nodes, MI has 4 nodes Eureka Server will take care about loadbalance. Add @LoadBalanced to SpringBoot Main Class RestTemplete I used to call other MicroService call. The RestTemplate with @LoadBalanced annotation will internally use Ribbon LoadBalancer to resolve the ServiceID and invoke REST endpoint using one of the available servers
Hystrix- Circuit Breaker/ Fault tolerance In above we are calling other microservice using RestTemplete. If microservice down, it will has fallbackmethod to handle those situations. Add Hystrix Dependency : spring-cloud-starter-netflix-hystrix Enable Hystrix functaionlity in our EDC-Microservice, by adding @EnableHystrix on our main SpringBoot main Class Use @HystrixCommand(fallbackMethod = “miReportFallBackMethod”) to define fallback method if called microservice is down or unreachable ResponseEntity r= restTemplate.getForEntity(“http://MI-MICROSERVICE/mi/anthology/all”, Object.class);
Zuul API Gateway Separate Server Add spring-cloud-starter-netflix-zuul dependency Add @EnableZuulProxy to main class Update application.yaml file with Route Details # WITH Eureka Server zuul: routes: edcservice: path: /edc/** serviceId: EDC-MICROSERVICE miservice: path: /mi/** serviceId: MI-MICROSERVICE
Sleuth and Zipkin Distributed Tracing. Just adding dependency logs will generated with TraceID Run Server cd C:\kafka java -jar zipkin.jar Zipkin is UI for log Tracing. We need to following steps in our microservices to push Distributed Trace logs to ZipKin Add spring-cloud-starter-sleuth Dependecy in (EDC, MI) to enable Sleuth Add spring-cloud-starter-zipkin to push logs to ZipKin Update application.props with zipkin server deratils spring.zipkin.base-url=http://localhost:9411/ spring.sleuth.sampler.probability=1
UserServiceWithKafka ProducerService : Add kafka dependencies @EnableKafka in SpringBoot main class. Update application.props with Server Details & Topic name topic.name.producer=user.provision.topic Use kafkaTemplate.send(kafkaTopic, data); to send msg to Topic ConsumerService: Add kafka dependencies @EnableKafka in SpringBoot main class. Update application.props with Server Details & Topic name topic.name.producer=user.provision.topic Use @KafkaListener to listen topic & Consume messages @KafkaListener(topics=”${topic.name.consumer}”, groupId = “group_id”) public void consume(ConsumerRecord<String, String> msg) { System.out.println(“Tópico: {}”+ msg); }
EDCMicroService  
MIMicroService