網關的作用除了路由、負載均衡之外,還可以將許多與業務無關的東西都放在網關上處理,比如:異常處理、簽名校驗、權限控制、錯峯限流,協議轉換、容錯、防止雪崩、監控統計、版本控制、防止篡改、參數脫敏等。Spring Cloud提供的網關有zuul和 gateway,後者是前者的升級版本。
網關zuul
雖然在spring cloud中zuul被gateway替換,但是對於老的系統,可能還是在使用zuul,所以先學習一下zuul
zuul網關:https://blog.csdn.net/oural/article/details/100690793
gateway
gateway網關:https://blog.csdn.net/oural/article/details/100713253
注意:
在這裏有一個問題,當zuul啓動的時候可能會報如下錯誤:
Description:
The bean 'counterFactory', defined in class path resource [org/springframework/cloud/netflix/zuul/ZuulServerAutoConfiguration$ZuulCounterFactoryConfiguration.class], could not be registered. A bean with that name has already been defined in class path resource [org/springframework/cloud/netflix/zuul/ZuulServerAutoConfiguration$ZuulMetricsConfiguration.class] and overriding is disabled.
原因:這是因爲Spring Cloud的依賴和Spring Boot的依賴的版本不兼容,具體的版本對應關係可以查看spring官網,也可以查看:https://blog.csdn.net/oural/article/details/94455240