当前位置:   article > 正文

springboot整合dubbo以后将zookeeper注册中心更换为nacos_dubbo zk 切换到nacos

dubbo zk 切换到nacos

依赖

<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-web</artifactId>
    <version>2.4.2</version>
</dependency>
<!--dubbo框架-->
<dependency>
    <groupId>com.alibaba</groupId>
    <artifactId>dubbo</artifactId>
    <version>2.6.4</version>
</dependency>
<!--dubbo的springboot支持-->
<dependency>
    <groupId>com.alibaba.boot</groupId>
    <artifactId>dubbo-spring-boot-starter</artifactId>
    <version>0.2.0</version>
</dependency>
<!--zk依赖-->
<!--<dependency>
    <groupId>org.apache.zookeeper</groupId>
    <artifactId>zookeeper</artifactId>
    <version>3.4.13</version>
</dependency>
&lt;!&ndash;zk客户端,注册到zk需要&ndash;&gt;
<dependency>
    <groupId>com.github.sgroschupf</groupId>
    <artifactId>zkclient</artifactId>
    <version>0.1</version>
</dependency>-->
<!-- 使用Nacos-->
<dependency>
    <groupId>com.alibaba</groupId>
    <artifactId>dubbo-registry-nacos</artifactId>
    <version>2.6.7</version>
</dependency>
<!--开启spring对Nacos的支持-->
<dependency>
    <groupId>com.alibaba.spring</groupId>
    <artifactId>spring-context-support</artifactId>
    <version>1.0.10</version>
</dependency>
<dependency>
    <groupId>io.netty</groupId>
    <artifactId>netty-all</artifactId>
    <version>4.1.32.Final</version>
</dependency>
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46

配置文件
我们注释掉原来的zk依赖换上最后三个依赖就可以了;
配置只需要变更一个
生产者

server.port=38080
dubbo.application.name = demo-server
# 注册中心地址,去哪找服务
#dubbo.registry.address = zookeeper://127.0.0.1:2181
dubbo.registry.address = nacos://159.23.11.316:8848
dubbo.registry.client = zkclient
dubbo.registry.timeout = 60000
dubbo.consumer.timeout = 60000

#qos
dubbo.application.qos.enable=true
dubbo.application.qos.port=33333
dubbo.application.qos.accept.foreign.ip=false
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13

消费者

server.port=38081
#要把那些服务注册到注册中心
dubbo.scan.basePackages = com.doria.provider
dubbo.application.name = demo-provider
# rpc通讯名称
dubbo.protocol.name = dubbo
# rpc通讯端口
dubbo.protocol.port = -1
# 注册中心地址,把服务注册到哪
#dubbo.registry.address = zookeeper://localhost:2181
dubbo.registry.address = nacos://159.23.11.316:8848
dubbo.registry.client = zkclient
dubbo.registry.timeout = 10000


  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15

zookeeper://127.0.0.1:2181 变更为nacos://159.23.11.316:8848

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/IT小白/article/detail/284220
推荐阅读
相关标签
  

闽ICP备14008679号