# Spring Cloud Service Discovery with Nextflix Eureka ###### tags: `Shannon` 主要學習目標是 * create microservice, based on Spring cloud, on Netflix Eureka registry server. * use Netflix Eureka server for building the service registry and Eureka clients which will register themselves and discover other services to call REST APIs. # Overview we will create three microservices * Eureka Service Registry Server: 這個microservice會提供service registry and discovery server. * Student Microservice: 會基於Student Entity提供一些功能 # step01 Creating an instance of WebClient 1. Creating Webclient using the create() method > 產生WebClient的instance ```java WebClient webClient = WebClient.create(); ``` > 如果要使用APIs from a specific service就可以初始化WebClient with the baseUrl ```java WebClient webClient = WebClient.create("https://api.github.com"); ``` 2. Creating WebClient using the WebClient builder WebClient有builder的方法,可以提供給你做一連串的個人設定,像是filters, default headers, cookies, client-connector etc ```java WebClient webClient = WebClient.builder() .baseUrl("https://api.github.com") .defaultHeader(HttpHeaders.CONTENT_TYPE, "application/json") .defaultHeader(HttpHeaders.USER_AGENT, "Spring 5 WebClient") .build(); ``` # step02 Making a Request using WebClient and retrieving the response * 你可以透過WebClient去make a `GET` request ```java public Flux<GithubRepo> listGitghubRepositoryies(String uername, String token){ return webClient.get() .uri("/user/repos") .header("Authorization, "Basic" + Base64Unitls .encodeToString((username+":"+token).getBytes(URF_8))) .retrieve() .bodyToFlux(GithubRepo.class) } ```