javascript
SpringCloud Greenwich(五)之nacos、dubbo、Zuul和 gateway集成
本項目是搭建基于nacos注冊中心的springcloud,集成dubbo框架,使用zuul網關和gateway網關
一、框架搭建
(1)項目結構
micro-service??服務提供者
zuul-gateway??zuul網關
springcloud-gateway??gateway網關
class-provider? duboo提供者
user-provider??duboo提供者
duboo-consumer??duboo消費者
dubbo-interface??duboo接口api
?
(2)環(huán)境
nacos 1.4.1
springboot 2.1.9
springcloud?Greenwich
dubbo??2.7.6
注:nacos搭建
?
二、項目配置application.yaml
127.0.0.1為本地nacos地址
(1)micro-service
spring:application:name: micro-serviceprofiles:active: devjackson:time-zone: GMT+8date-format: yyyy-MM-dd HH:mm:ssdefault-property-inclusion: ALWAYScloud:nacos:discovery:server-addr: 127.0.0.1:8848server:port: 8081(2)zuul-gateway
spring:application:name: zuul-gatewayprofiles:active: devjackson:time-zone: GMT+8date-format: yyyy-MM-dd HH:mm:ssdefault-property-inclusion: ALWAYScloud:nacos:discovery:server-addr: 127.0.0.1:8848server:port: 8082zuul:strip-prefix: true #轉發(fā)路徑截斷匹配前綴 # prefix: "/api"add-proxy-headers: falseset-content-length: truesemaphore:max-semaphores: 600hystrix:command:default:execution:isolation:thread:timeoutInMilliseconds: 120000 ribbon:ReadTimeout: 240000ConnectTimeout: 2000MaxAutoRetries: 0MaxAutoRetriesNextServer: 1eager-load:enabled: trueclients: micro-service(3)?springcloud-gateway
spring:application:name: springcloud-gatewayprofiles:active: devjackson:time-zone: GMT+8date-format: yyyy-MM-dd HH:mm:ssdefault-property-inclusion: ALWAYScloud:nacos:discovery:server-addr: 127.0.0.1:8848gateway:discovery:locator:enabled: truelower-case-service-id: truehttpclient:connect-timeout: 60000response-timeout: 5sroutes:- id: micro-service1uri: lb://micro-servicepredicates:- Path=/micro-service1/**filters:- StripPrefix=1 server:port: 8083hystrix:command:default:execution:isolation:thread:timeoutInMilliseconds: 120000 ribbon:ReadTimeout: 240000ConnectTimeout: 2000MaxAutoRetries: 0MaxAutoRetriesNextServer: 1eager-load:enabled: trueclients: micro-service(4)user-provider
dubbo:registry:address: spring-cloud://${spring.cloud.nacos.discovery.server-addr}protocol:name: dubboport: -1scan:base-packages: com.mk.springcloud.dubbocloud:subscribed-services: ''spring:application:name: user-providerprofiles:active: devjackson:time-zone: GMT+8date-format: yyyy-MM-dd HH:mm:ssdefault-property-inclusion: ALWAYSmain:allow-bean-definition-overriding: truecloud:nacos:discovery:server-addr: 172.0.0.1:8848server:port: 8084feign:hystrix:enabled: truelogBack:logPathDir: ${logPathDir:./log/${spring.application.name}}(5)class-provider
dubbo:registry:address: spring-cloud://${spring.cloud.nacos.discovery.server-addr}protocol:name: dubboport: -1scan:base-packages: com.mk.springcloud.dubbocloud:subscribed-services: user-provider # consumer: # check: falsespring:application:name: class-providerprofiles:active: devjackson:time-zone: GMT+8date-format: yyyy-MM-dd HH:mm:ssdefault-property-inclusion: ALWAYSmain:allow-bean-definition-overriding: truecloud:nacos:discovery:server-addr: 172.0.0.1:8848server:port: 8085feign:hystrix:enabled: truelogBack:logPathDir: ${logPathDir:./log/${spring.application.name}}(6)dubbo-consumer
dubbo:registry:address: spring-cloud://${spring.cloud.nacos.discovery.server-addr}protocol:name: dubboport: -1scan:base-packages: com.mk.springcloud.dubbocloud:subscribed-services: user-provider,class-provider # consumer: # check: falsespring:application:name: dubbo-consumerprofiles:active: devjackson:time-zone: GMT+8date-format: yyyy-MM-dd HH:mm:ssdefault-property-inclusion: ALWAYSmain:allow-bean-definition-overriding: truecloud:nacos:discovery:server-addr: 172.0.0.1:8848server:port: 8086logBack:logPathDir: ${logPathDir:./log/${spring.application.name}}dubbo.register配置可以寫成其他方式,程序只取spring-cloud://這個協(xié)議頭,如:
dubbo:registry:address: spring-cloud://localhostdubbo.scan.base-packages必須填寫,否則dubbo不會注冊dubbo接口服務
dubbo:scan:base-packages: com.mk.springcloud.dubbo?
三、dubbo存在的問題
consumer先啟動,provider后啟動無法發(fā)現(xiàn)問題在版本spring-cloud-starter-dubbo 2.2.4.RELEASE已經解決了。
provider重啟后,consumer無法自動發(fā)現(xiàn)provider,官方還沒有給出明確的解決時間。
所以每次重啟provider,都要把consumer重啟一遍才能訪問
?
四、項目地址
https://github.com/90duc/springcloud-nacos-dubbo
?
總結
以上是生活随笔為你收集整理的SpringCloud Greenwich(五)之nacos、dubbo、Zuul和 gateway集成的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 魔兽怀旧服黑上怎么走 魔兽怀旧服黑上走法
- 下一篇: SpringCloud Greenwic