赞
踩
dubbo框架,注册中心的技术选型常见有redis,zookeeper ,本篇文章介绍如何整理当前比较火热的nacos框架。
nacos框架安装,可以参考:CSDN
1) 服务端改造:
使用nacos
<dubbo:registry address="nacos://192.168.213.102:8848" timeout="10000"/>
- <?xml version="1.0" encoding="UTF-8"?>
- <beans xmlns="http://www.springframework.org/schema/beans"
- xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
- xmlns:dubbo="http://code.alibabatech.com/schema/dubbo"
- xsi:schemaLocation="http://www.springframework.org/schema/beans
- http://www.springframework.org/schema/beans/spring-beans.xsd
- http://code.alibabatech.com/schema/dubbo
- http://code.alibabatech.com/schema/dubbo/dubbo.xsd">
-
- <dubbo:application name="dubbo-server"/>
-
- <!--dubbo:registry address="zookeeper://192.168.213.102:2181" timeout="10000"/-->
- <dubbo:registry address="nacos://192.168.213.102:8848" timeout="10000"/>
-
- <dubbo:protocol name="dubbo" port="20880"/>
- <!--dubbo:registry address="N/A"/--><!-- 如果不用注册中心,可以这样设置。无需注册到服务注册中心-->
- <dubbo:service interface="org.example.ILoginService" ref="loginService"/>
- <bean id="loginService" class="org.example.LoginServiceImpl"/>
-
- </beans>
pom.xml文件,增加依赖的文件:
- <dependency>
- <groupId>org.apache.dubbo</groupId>
- <artifactId>dubbo</artifactId>
- <version>2.7.8</version>
- </dependency>
- <dependency>
- <groupId>org.apache.dubbo</groupId>
- <artifactId>dubbo-dependencies-zookeeper</artifactId>
- <version>2.7.8</version>
- <type>pom</type>
- </dependency>
- <dependency>
- <groupId>com.alibaba.nacos</groupId>
- <artifactId>nacos-client</artifactId>
- <version>1.2.1</version>
- </dependency>
2)客户端改造:
- <?xml version="1.0" encoding="UTF-8"?>
- <beans xmlns="http://www.springframework.org/schema/beans"
- xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
- xmlns:dubbo="http://code.alibabatech.com/schema/dubbo"
- xsi:schemaLocation="http://www.springframework.org/schema/beans
- http://www.springframework.org/schema/beans/spring-beans.xsd
- http://code.alibabatech.com/schema/dubbo
- http://code.alibabatech.com/schema/dubbo/dubbo.xsd">
-
- <dubbo:application name="dubbo-server"/>
-
- <!--dubbo:registry address="N/A"/--><!-- 无需注册到服务注册中心-->
- <!--dubbo:registry address="zookeeper://192.168.213.102:2181" timeout="10000"/-->
- <dubbo:registry address="nacos://192.168.213.102:8848" timeout="10000"/>
-
- <!--dubbo:reference id="loginService" interface="org.example.ILoginService" url="dubbo://192.168.117.1:20880/org.example.ILoginService"/-->
- <!--使用注册中心后,就可以不用配置URL,默认跟interface去注册中心寻找-->
- <dubbo:reference id="loginService" interface="org.example.ILoginService"/>
-
- </beans>
pom.xml,增加依赖的文件:
- <dependency>
- <groupId>org.apache.dubbo</groupId>
- <artifactId>dubbo</artifactId>
- <version>2.7.8</version>
- </dependency>
- <dependency>
- <groupId>org.apache.dubbo</groupId>
- <artifactId>dubbo-dependencies-zookeeper</artifactId>
- <version>2.7.8</version>
- <type>pom</type>
- </dependency>
- <dependency>
- <groupId>com.alibaba.nacos</groupId>
- <artifactId>nacos-client</artifactId>
- <version>1.2.1</version>
- </dependency>
服务列表
服务详情:
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。