springcloud常用元件簡明筆記

2021-10-05 23:25:05 字數 3940 閱讀 5223

>

>

hoxton.sr4spring-cloud.version

>

properties

>

>

>

>

>

org.springframework.cloudgroupid

>

>

spring-cloud-dependenciesartifactid

>

>

$version

>

>

pomtype

>

>

importscope

>

dependency

>

dependencies

>

dependencymanagement

>

1.pom依賴

org.springframework.cloud

spring-cloud-starter-netflix-eureka-server

2.配置

eureka

:instance

:hostname

: eureka8090.com

client

:# 是否將自己註冊到eureka server

register-with-eureka

:false

# 是否從eureka server獲取註冊資訊

fetch-registry

:false

serviceurl

:defaultzone

:

3.註解

@enableeurekaserver
1.pom依賴

>

>

org.springframework.cloudgroupid

>

>

spring-cloud-starter-netflix-eureka-clientartifactid

>

dependency

>

2.配置

eureka

:client

:service-url

:defaultzone

:

3.註解

@enableeurekaclient
需要自己也註冊。

1.pom依賴

spring-cloud-dependencies

spring-cloud-starter-netflix-eureka-client

2.配置

eureka

:client

:service-url

:defaultzone

: http://localhost:8090/eureka

3.註解

@enableeurekaclient

@enablediscoveryclient

4.實現

discoveryclient client
第一種方式ribbon+resttemplate

1.pom依賴

>

>

org.springframework.cloudgroupid

>

>

spring-cloud-starter-netflix-ribbonartifactid

>

dependency

>

2.配置

eureka

:client

:register-with-eureka

:false

serviceurl

:defaultzone

:

@configuration

public

class

restconfig

}

3.註解

@enablediscoveryclient
4.呼叫resttemplate

@service

public

class

ribbonservice

}

第二種方式feign

1.pom依賴

>

>

org.springframework.cloudgroupid

>

>

spring-cloud-starter-openfeignartifactid

>

dependency

>

2.配置

eureka

:client

:register-with-eureka

:false

serviceurl

:defaultzone

:

3.註解

@enablefeignclients

@enablediscoveryclient

4.服務介面

@feignclient

("service-hi"

)public

inte***ce

scheduleservicehi")

string sayhifromclientone

(@pathvariable

("name"

) string name)

;}

5.呼叫服務

@autowired

scheduleservicehi scheduleservicehi;

1.pom依賴

>

>

org.springframework.cloudgroupid

>

>

spring-cloud-starter-netflix-hystrixartifactid

>

dependency

>

2.配置

eureka.client
3.第一種方式ribbon+resttemplate

@hystrixcommand

(fallbackmethod =

"hierror"

)public string getservicehi

(string name)

public string hierror

(string name)

@enablehystrix

@enablediscoveryclient

4.第二種方式feign

feign.hystrix.enabled: true

實現呼叫服務的介面,放入fallback中

在呼叫服務的介面註解上加上fallback

@feignclient(value = "service-hi", fallback = scheduleservicehiimpl.class)

@enablediscoveryclient

@enablefeignclients

Springcloud常用元件

一 eureka netfix下 雲端服務發現,乙個基於 rest 的服務,用於定位服務,以實現雲端中間層服務發現和故障轉移。二 spring cloud config spring下 配置管理工具包,讓你可以把配置放到遠端伺服器,集中化管理集群配置,目前支援本地儲存 git以及subversion...

Spring Cloud常用元件重試總結

ribbon的重試機制是基於spring retry,需要引用相關包 dependency groupid org.springframework.retry groupid artifactid spring retry artifactid dependency ribbon retryable...

springcloud的常用元件,以及它們的用處

1.eureka註冊中心 3.客戶端註冊服務到集群 eureka client service url eurekaserver位址,多個位址以 隔開 defaultzone 4.服務續約 lease renewal interval in seconds 服務續約 renew 的間隔,預設為30秒...