幹貨分享微服務spring-cloud(6.Api網關服務zuul)
阿新 • • 發佈:2018-02-13
依賴 正常 技術 網關 art ans audio style 熔斷器 Spring cloud zuul對Netflix zuul進行了封裝實現 serviceToConsumer
新建spring boot項目demo-springcloud-api-gateway,創建啟動類ZuulApplication,@EnableZuulProxy啟動網關代理的配置,它也是組合註解,啟用了服務註冊發現和熔斷器
項目關鍵依賴spring-cloud-starter-zuul對網關支持
配置文件application.properties,路由配置主要有傳統路由和服務路由,傳統路由就是ip和端口這種,服務路由就是使用服務名作為路由。傳統路由我們配置為/tradition/**,服務路由配置為/serviceToClient和
啟動註冊中心,啟動服務提供者,啟動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)