1. 程式人生 > >幹貨分享微服務spring-cloud(6.Api網關服務zuul)

幹貨分享微服務spring-cloud(6.Api網關服務zuul)

依賴 正常 技術 網關 art ans audio style 熔斷器

Spring cloud zuulNetflix zuul進行了封裝實現

新建spring boot項目demo-springcloud-api-gateway,創建啟動類ZuulApplication@EnableZuulProxy啟動網關代理的配置,它也是組合註解,啟用了服務註冊發現和熔斷器

技術分享圖片技術分享圖片

項目關鍵依賴spring-cloud-starter-zuul對網關支持

技術分享圖片

配置文件application.properties,路由配置主要有傳統路由和服務路由,傳統路由就是ip和端口這種,服務路由就是使用服務名作為路由。傳統路由我們配置為/tradition/**,服務路由配置為/serviceToClient

serviceToConsumer

技術分享圖片


啟動註冊中心,啟動服務提供者,啟動demo-springcloud-api-gateway,瀏覽器訪問http://localhost:4441/tradition/hello和http://localhost:4441/serviceToClient/hello和http://localhost:4441/serviceToConsumer/hello和http://localhost:4441/demo-springcloud-consumer/hello均正常訪問

技術分享圖片技術分享圖片

幹貨分享微服務spring-cloud(6.Api網關服務zuul)