一,建立server
1,匯入依賴
2,編寫配置檔案
3,啟動類#服務名稱
spring::
name
: qf-spring-cloud-server
server
:port
:8761
eureka
:instance
:hostname
: localhost
client
:#這個false為不向註冊中心註冊自己,在非集群的操作下 都為false
registerwitheureka
:false
#該項配置說明,註冊中心只要維護微服務例項清單,非集群環境下,不需要作檢索服務,所有也設定為false
fetchregistry
:false
serviceurl
:defaultzone
:#客戶端發現server路徑
二,建立service1,匯入依賴@enableeurekaserver
//開啟server
public
class
}

2,編寫配置檔案
3,建立介面
延申:@restcontroller
public
class
mycontroller")
private string port;
("/hi"
)public string sayhi
(@requestparam
(value =
"message"
)string message)
}
string.fomat("%s 哈哈哈哈 %s",a,b)4,啟動類結果:a哈哈哈哈b
省去了字串拼接造成多個物件的建立
三,建立consumer(ribbon)@enableeurekaclient
//這個註解為客戶端,也可用@enableeurekaserver 這樣方便分清
public
class
}

2,編寫配置檔案
3,編寫配置類
4,編寫service@configuration
public
class
myconfig
@bean
//負載均衡策略 預設為輪詢
public irule getround()
}
這裡用程式名代替具體的uri位址,在ribbon中它會根據服務來選擇具體的服務實列,根據服務實列在請求的時候用具體的uri替換掉服務名。@service
public
class
myservice
}
5,建立controller
四,建立consumer(feign)1,匯入依賴@restcontroller
public
class
mycontroller
}

因為feign是建立在ribbon的基礎上的,所以這兩個依賴都需要導上去。
2,編寫配置檔案
3,建立feign介面
通過//指定呼叫的服務
@feignclient
(value =
"hello-spring-cloud-service-admin"
)public
inte***ce
adminservice
@feignclient("服務名")
註解來指定呼叫哪個服務
4,建立controller
5,啟動類@enablediscoveryclient@restcontroller
public
class
admincontroller
}
//開啟客戶端
@enablefeignclients
//開啟feign
public
class
}
SpringCloud服務調服務
org.springframework.cloud spring cloud starter feign enablefeignclients configuration public class mybatisplusconfig 資料許可權外掛程式 return datascopeinterce...
springcloud 服務降級
降級就是將一些不常用的服務停掉從而釋放更多的資源來 一些主要的服務使用 1.服務降級中有很多的方法,最好的方式就是利用 docker 來實現,當 需要對某個服務進行降級時可以直接將這個服務的容器停掉,等到需要使用時在把這個服務重啟就行。2.通過api閘道器的方式進行降級這樣我們的就可以將前台的一切請...
springcloud(服務通訊)
1.1.建立工程 1.2.user common公共模組中建立userpublic class user public user long id,string username,string desc 省略getter,setter.2.1.依賴公共模組 cn.itsource.springclou...