Git Product home page Git Product logo

demo-springboot-microservices's Introduction

Demo-SpringBoot-Microservices

Author: Dr. YUHANG ZHAO

Introduction: In this demo we illustrate how to build microservices with Spring Boot and Spring cloud.

Reference: "Spring Boot Microservices Level 1" by Java Brains

Overview:

  1. In general, microservice changes what happens in the runtime, not only the architecture? but also the thinking of programming.

    We'll be creating a few microservices and then have them communicated with each other. In the process, we'll understand how inter-service communication work, and we'll implement "service discovery" with Eureka to facilitate services discoverying each other to communicate.

    Spring Cloud is one way to do microservice.

  2. Advantage is independent, scalability; disadvantage is the problems in general such as "load balancing".

    In other words, monolith: "complexity hidden with"; microservice: "complexity between microservices".

  3. Monolith -> pieces (microservices); service discovery; how to communicate each other.

  4. Spring Cloud is one way to do microservice.

    Prerequisites for this demo: Java and Spring Boot, since microservice is a SpringBoot app.

    Demo: a movie catalog API application.

  5. Each microservice is a spring boot project.

  6. So far we have constructed 3 applications independently with hard-coded data.

    Discuss we are going to call each other programatically through REST APIs using REST client library. Spring Boot has one client (to do REST API calls) already in your classpath - RestTemplate, we use it to call an external microservice API.

  7. Implement using RestTemplate to call an external microservice API - movie info service.

  8. Use @Bean for RestTemplate.

  9. Use webClient (asynchronous) to make API calls instead of RestTemplate (synchronous).

  10. Make an API accepting user ID and returns a list of movie ID.

  11. Why should avoid returning list in APIs? and how?: use object to wrap list of objects.

  12. Dynamic url in cloud; load balancing needed; Then how to? the discovery server, which is like a phone book. Spring Boot and Spring Cloud use Client side discovery, which requests the discovery server and jump to the supplied url.

    Eureka, as Ribbon, Hysterix, Zuul, belongs to Netflix OSS.

  13. Discuss we will set up Eureka server, register the 3 microservices in it as Eureka clients. Also, who needs Eureka services is also an Eureka client.

  14. Start up a Eureka server: Spring Boot Starter Project using Eureka Server; @EnableEurekaServer; check port 8761 for Dashboard; Error in console solved by adding in application properties that stop acting as a client.

  15. Have microservices registered (publish) using Eureka client: Add dependency; Add application name in application.properties.

  16. Have microservices located (consume) using Eureka client: @LoadBalanced which does everything including locating and load balancing; Replace the hard coded URL by the registered microservice name; Fixed error caused by application name diff to the registered name.

  17. Load balancing: How to duplicate a microservice? through java -Dserver.port=? -jar X.jar

Level 2:

  1. User themovieDB.org to get movie info by making external RESTful API calls.

demo-springboot-microservices's People

Contributors

yuhang2685 avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.