亚洲视频二区_亚洲欧洲日本天天堂在线观看_日韩一区二区在线观看_中文字幕不卡一区

公告:魔扣目錄網為廣大站長提供免費收錄網站服務,提交前請做好本站友鏈:【 網站目錄:http://www.430618.com 】, 免友鏈快審服務(50元/站),

點擊這里在線咨詢客服
新站提交
  • 網站:51998
  • 待審:31
  • 小程序:12
  • 文章:1030137
  • 會員:747

如何集成 Eureka Client

本節將創建一個micro-weather-cureka-client作為客戶端,并演示如何將自身向注冊服務器進行注冊,這樣以便其他服務都能夠通過名稱來訪問服務。該客戶端基于Eureka Client來實現。

micro-weather-eureka-client可以基于micro-weather-eureka-server應用來做更改。

微服務架構開發實戰:如何集成 Eureka Client?

 

所需環境

為了演示本例,需要采用如下開發環境。

.JDK8。

.Gradle 4.0。

Spring Boot 2.0.0.M3。

.Spring Cloud Starter Netflix Eureka Client Finchley.M2。

更改build.gradle配置

與micro-weather-eureka-server相比,micro-weather-eureka-client應用的build.gradle配置的變化,主要是在依賴上面,將Eureka Server的依賴改為Eureka Client即可。

dependencies {
//添加Spring Cloud Starter Netflix Eureka Client依賴compile ('org.springframework.cloud:spring-cloud-starter-netflix-
eureka-client')
//該依賴用于測試階段testCompile('org.springframework.boot:spring-boot-starter-test')
}
微服務架構開發實戰:如何集成 Eureka Client?

 

一個最簡單的Eureka Client

將@EnableEurekaServer注解改為@EnableDiscoveryClient。

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.client.discovery.EnableDiscovery
Client;
/**
*主應用程序.
*
*@since 1-o.0 2017年11月01日
*@author <a href="https://waylau.com">Way Lau</a>
*/
@SpringBootApplication
@EnableDiscoveryClient
public class Application
public static void main(String[] args){SpringApplication.run(Application.class,args);
}}

org.springframework.cloud.client.discovery.EnableDiscoveryClient注解,就是一個自動發現客戶端的實現。

修改項目配置

修改application.properties,修改為如下配置。

spring.application.name: micro-weather-eureka-client

eureka.client.serviceUrl.defaultZone: http://localhost:8761/eureka/

其中:.spring.application.name:指定了應用的名稱;

.eureka.client.serviceUrl.defaultZonet:指明了Eureka Server的位置。

運行和測試

首先運行Eureka Server實例micro-weather-eureka-server,它啟動在8761端口。

而后分別在8081和8082上啟動了Eureka Client實例micro-weather-eureka-client。

JAVA -jar micro-weather-eureka-client-1.0.0.jar--server.port=8081
java -jar micro-weather-eureka-client-1.0.0.jar --server.port=8082

這樣,就可以在Eureka Server 上看到這兩個實例的信息。訪問http:/localhost:8761,可以看到如圖8-2所示的Eureka Server自帶的UI管理界面。

微服務架構開發實戰:如何集成 Eureka Client?

 

從管理界面“Instances currently registered with Eureka”中,能看到每個Eureka Client的狀態,相同的應用(指具有相同的spring.application.name )下,能夠看到每個應用的實例。

如果Eureka Client離線了,Eureka Server也能及時感知到。

不同的應用之間,就能夠通過應用的名稱來互相發現。

其中,從界面上也可以看出,Eureka Server運行的IP為192.168.1.101。

分享到:
標簽:Eureka Client
用戶無頭像

網友整理

注冊時間:

網站:5 個   小程序:0 個  文章:12 篇

  • 51998

    網站

  • 12

    小程序

  • 1030137

    文章

  • 747

    會員

趕快注冊賬號,推廣您的網站吧!
最新入駐小程序

數獨大挑戰2018-06-03

數獨一種數學游戲,玩家需要根據9

答題星2018-06-03

您可以通過答題星輕松地創建試卷

全階人生考試2018-06-03

各種考試題,題庫,初中,高中,大學四六

運動步數有氧達人2018-06-03

記錄運動步數,積累氧氣值。還可偷

每日養生app2018-06-03

每日養生,天天健康

體育訓練成績評定2018-06-03

通用課目體育訓練成績評定