当前位置:   article > 正文

微服务框架-dubbo整合nacos框架

dubbo整合nacos

一、前言:

       dubbo框架,注册中心的技术选型常见有redis,zookeeper ,本篇文章介绍如何整理当前比较火热的nacos框架。

      nacos框架安装,可以参考:CSDN

二、框架整合:

     1) 服务端改造:

      使用nacos

      <dubbo:registry  address="nacos://192.168.213.102:8848" timeout="10000"/>

  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <beans xmlns="http://www.springframework.org/schema/beans"
  3. xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  4. xmlns:dubbo="http://code.alibabatech.com/schema/dubbo"
  5. xsi:schemaLocation="http://www.springframework.org/schema/beans
  6. http://www.springframework.org/schema/beans/spring-beans.xsd
  7. http://code.alibabatech.com/schema/dubbo
  8. http://code.alibabatech.com/schema/dubbo/dubbo.xsd">
  9. <dubbo:application name="dubbo-server"/>
  10. <!--dubbo:registry address="zookeeper://192.168.213.102:2181" timeout="10000"/-->
  11. <dubbo:registry address="nacos://192.168.213.102:8848" timeout="10000"/>
  12. <dubbo:protocol name="dubbo" port="20880"/>
  13. <!--dubbo:registry address="N/A"/--><!-- 如果不用注册中心,可以这样设置。无需注册到服务注册中心-->
  14. <dubbo:service interface="org.example.ILoginService" ref="loginService"/>
  15. <bean id="loginService" class="org.example.LoginServiceImpl"/>
  16. </beans>

  pom.xml文件,增加依赖的文件:

  1. <dependency>
  2. <groupId>org.apache.dubbo</groupId>
  3. <artifactId>dubbo</artifactId>
  4. <version>2.7.8</version>
  5. </dependency>
  6. <dependency>
  7. <groupId>org.apache.dubbo</groupId>
  8. <artifactId>dubbo-dependencies-zookeeper</artifactId>
  9. <version>2.7.8</version>
  10. <type>pom</type>
  11. </dependency>
  12. <dependency>
  13. <groupId>com.alibaba.nacos</groupId>
  14. <artifactId>nacos-client</artifactId>
  15. <version>1.2.1</version>
  16. </dependency>

2)客户端改造:

  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <beans xmlns="http://www.springframework.org/schema/beans"
  3. xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  4. xmlns:dubbo="http://code.alibabatech.com/schema/dubbo"
  5. xsi:schemaLocation="http://www.springframework.org/schema/beans
  6. http://www.springframework.org/schema/beans/spring-beans.xsd
  7. http://code.alibabatech.com/schema/dubbo
  8. http://code.alibabatech.com/schema/dubbo/dubbo.xsd">
  9. <dubbo:application name="dubbo-server"/>
  10. <!--dubbo:registry address="N/A"/--><!-- 无需注册到服务注册中心-->
  11. <!--dubbo:registry address="zookeeper://192.168.213.102:2181" timeout="10000"/-->
  12. <dubbo:registry address="nacos://192.168.213.102:8848" timeout="10000"/>
  13. <!--dubbo:reference id="loginService" interface="org.example.ILoginService" url="dubbo://192.168.117.1:20880/org.example.ILoginService"/-->
  14. <!--使用注册中心后,就可以不用配置URL,默认跟interface去注册中心寻找-->
  15. <dubbo:reference id="loginService" interface="org.example.ILoginService"/>
  16. </beans>

  pom.xml,增加依赖的文件:

  1. <dependency>
  2. <groupId>org.apache.dubbo</groupId>
  3. <artifactId>dubbo</artifactId>
  4. <version>2.7.8</version>
  5. </dependency>
  6. <dependency>
  7. <groupId>org.apache.dubbo</groupId>
  8. <artifactId>dubbo-dependencies-zookeeper</artifactId>
  9. <version>2.7.8</version>
  10. <type>pom</type>
  11. </dependency>
  12. <dependency>
  13. <groupId>com.alibaba.nacos</groupId>
  14. <artifactId>nacos-client</artifactId>
  15. <version>1.2.1</version>
  16. </dependency>

三、nacos平台,查看注册的服务信息:

服务列表

服务详情:

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

闽ICP备14008679号