RPC服务框架dubbo(四):Dubbo中Provider搭建
1.新建Maven Project, 里面只有接口(dubbo-service)
1.1 为什么这么做?
RPC框架,不希望Consumer知道具体实现.如果实现类和接口在同一个项目中,Consumer依赖这个项目时,就会知道实现类具体实现.
2.新建Maven Project, 写接口的实现类(dubbo-service-impl)
3.在duboo-service-impl中配置pom.xml
3.1 依赖接口
3.2 依赖dubbo,去掉老版本spring
3.3 依赖新版本spring
3.4 依赖zookeeper客户端工具zkClient
<dependencies> <dependency> <groupId>com.bjsxt</groupId> <artifactId>dubbo-service</artifactId> <version>0.0.1-SNAPSHOT</version> </dependency> <dependency> <groupId>com.alibaba</groupId> <artifactId>dubbo</artifactId> <version>2.5.3</version> <exclusions> <exclusion> <artifactId>spring</artifactId> <groupId>org.springframework</groupId> </exclusion> </exclusions> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-webmvc</artifactId> <version>4.1.6.RELEASE</version> </dependency> <!-- 访问zookeeper的客户端jar --> <dependency> <groupId>com.101tec</groupId> <artifactId>zkclient</artifactId> <version>0.10</version> </dependency> </dependencies> |
4.新建实现类,并实现接口方法.
5.新建配置文件applicationContext-dubbo.xml,并配置
5.1 <dubbo:application/> 给provider起名,在monitor或管理工具中区别是哪个provider
5.2 <dubbo:registry/> 配置注册中心
5.2.1 address:注册中心的ip和端口
5.2.2 protocol使用哪种注册中心
5.3 <dubbo:protocol/> 配置协议
5.3.1 name 使用什么协议
5.3.2 port: consumer invoke provider时的端口号
5.4 <dubbo:service/> 注册接口
5.4.1 ref 引用接口实现类<bean>的id值
<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context" 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://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd http://code.alibabatech.com/schema/dubbo http://code.alibabatech.com/schema/dubbo/dubbo.xsd"> <!-- 给当前Provider自定义个名字 --> <dubbo:application name="dubbo-service"/> <!-- 配置注册中心 --> <dubbo:registry address="192.168.139.130:2181" protocol="zookeeper"></dubbo:registry> <!-- 配置端口 --> <dubbo:protocol name="dubbo" port="20888"></dubbo:protocol> <!-- 注册功能 --> <dubbo:service interface="com.bjsxt.service.DemoService" ref="demoServiceImpl"></dubbo:service> <bean id="demoServiceImpl" class="com.bjsxt.service.impl.DemoServiceImpl"></bean> </beans> |
6.启动容器
6.1 通过spring方式启动
6.1.1 applicationContext-dubbo.xml位置没有要求
ClassPathXmlApplicationContext ac = new ClassPathXmlApplicationContext("applicationContext-dubbo.xml"); ac.start(); System.out.println("启动成功"); System.in.read(); |
6.2 使用dubbo提供的方式启动(推荐使用这种方式)
6.2.1 要求applicationContext-dubbo.xml必须放入类路径下/META-INF/spring/*.xml
Main.main(args); |
最新文章
- Mac入门(三)使用brew安装软件
- Linux svn的搭建与使用
- 第50课 关于对话框(About)
- Spring与Quartz的整合实现定时任务调度
- SpringMVC项目接入Springfox实战遇到的问题集合
- (转载)MySQL中执行sql语句反斜杠需要进行转义否则会被吃掉
- BZOJ 1619: [Usaco2008 Nov]Guarding the Farm 保卫牧场
- Python学习-使用matplotlib画动态多图
- 使用Xamarin在Visual Studio中开发Android应用
- html基本标签与属性
- Linux:快速找到占用CPU过高的Thread
- RabbitMQ教程
- vue_组件间通信:自定义事件、消息发布与订阅、槽
- python datetime模块详解
- SQL 中用户定义函数的使用方法
- @ControllerAdvice + @ExceptionHandler 全局处理 Controller 层异常==》记录
- blfs(systemv版本)学习笔记-配置远程访问和管理lfs系统
- The resource configuration is not modifiable in this context.
- 分布式缓存技术redis系列(四)——redis高级应用(集群搭建、集群分区原理、集群操作)
- Jmeter(十九) Md5加密操作之-------BeanShell PreProcessor(转载)
热门文章
- mysql知识点(二)
- oracle维护服务 oracle解决方案 oracle售后服务
- ConnectivityManager详解
- (转)Sql Server 快速查看表结构(表描述及字段说明)
- [Windows]_[删除非空文件夹的注意要点]
- MapReduce调度器
- MySQL: tinyint(1) 和 tinyint(4), char 和varchar
- OpenMP 中的线程任务调度
- tomcat(5)servlet容器
- CAD设置图层透明显示