dubbo的简单使用

整个过程大致是这样的
1.注册中心使用zookeeper,地址为192.168.192.128:2181!

2.首先服务方
所在的服务器是127.0.0.1:8081
服务方提供的接口:
public interface ITestTbService {
void insertTestTb(TestTb testTb);
}
接口的实现类
@Service("testTbService")
@Transactional
public class TestTbServiceImpl implements ITestTbService {
@Resource
private TestTbMapper testTbMapper;
@Override
public void insertTestTb(TestTb testTb) {
testTbMapper.insertSelective(testTb);
//throw new RuntimeException();
}
}
dubbo-provider.xml
<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-4.0.xsd
http://code.alibabatech.com/schema/dubbo
http://code.alibabatech.com/schema/dubbo/dubbo.xsd">
<!-- 提供方应用信息,用于计算依赖关系 -->
<dubbo:application name="service-provider"/>
<!-- 使用zookeeper注册中心暴露服务地址 -->
<dubbo:registry address="192.168.198.128:2181" protocol="zookeeper"/>
<!-- 用dubbo协议在20880端口暴露服务 -->
<dubbo:protocol port="20880" name="dubbo"/>
<!-- 声明需要暴露的服务接口 -->
<dubbo:service interface="com.winner.service.ITestTbService" ref="testTbService"/>
</beans>
3.服务消费方
所在的服务器是127.0.0.1:8080
<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-4.0.xsd
http://code.alibabatech.com/schema/dubbo
http://code.alibabatech.com/schema/dubbo/dubbo.xsd">
<!-- 消费方应用信息,用于计算依赖关系 -->
<dubbo:application name="service-consumer"/>
<!-- 使用zookeeper注册中心暴露服务地址 -->
<dubbo:registry address="192.168.198.128:2181" protocol="zookeeper"/>
<!-- 声明需要暴露的服务接口 -->
<dubbo:reference interface="com.winner.service.ITestTbService" id="testTbService"/>
</beans>
在消费服务器端:
@Controller
public class CenterController {
@Resource
private ITestTbService testTbService;
@RequestMapping("/test/index.do")
public String index() {
TestTb testTb = new TestTb();
testTb.setName("zhangsan");
testTb.setBirthday(new Date());
testTbService.insertTestTb(testTb);
return "index";
}
}
可以看到,我们直接用@Resource注入进来这个接口的实现,注意,这个接口的实现是在另外一台服务器上哟(此处只是用不同的端口模拟)!
注意事项:
Dubbo消费方及提供方传递的参数必须实现序列化接口!
public class TestTb implements Serializable
dubbo的简单使用的更多相关文章
- dubbo+zookeeper简单环境搭建
dubbo+zoopeeper例子 [TOC] 标签(空格分隔): 分布式 dubbo dubbo相关 dubbo是目前国内比较流行的一种分布式服务治理方案.还有一种就是esb了.一般采用的是基于Ap ...
- dubbo的简单实现
一 是什么 一般网站架构随着业务的发展,逻辑越来越复杂,数据量越来越大,交互越来越多,dubbo使前后端分离,完成负载均衡. dubbo架构图 节点角色说明: Provider: 暴露服务的服务提供方 ...
- dubbo的简单应用
一. dubbo简介 dubbo是一个分布式服务框架,致力于提供高性能和透明化的RPC远程服务调用方案,是阿里巴巴SOA服务化治理方案的核心框架. 二. 架构 引用dubbo的架构图: Provide ...
- dubbo服务简单搭建
一.初识dubbo: 架构图: Provider: 暴露服务的服务提供方. Consumer: 调用远程服务的服务消费方. Registry: 服务注册与发现的注册中心. Monitor: 统计服务的 ...
- MAC环境下idea:maven+Spring+Dubbo+Zookeeper简单工程搭建
: 一:安装软件:tomcatZookeeperDubbo+admin 二:工程: 总工程 API Pom.xml:不用引用任何东西 Provider Pom.xml:要denpend ...
- springboot整合dubbo的简单案例
使用框架: jdk 1.8 springboot-2.1.3 dubbo-2.6 spring-data-jpa-2.1.5 一.开发dubbo服务接口: 按照Dubbo官方开发建议,创建一个接口项目 ...
- springboot搭建dubbo+zookeeper简单案例
背景:只是自己使用单机版zookeeper搭建dubbo的一个学习案例,记录成功的过程 1.搭建zookeeper坏境 使用docker来构建环境 1.1 拉取镜像:docker pull zooke ...
- Maven配置dubbo环境简单例子
环境准备: 1.zookeeper:zookeeper-3.4.6版本 2.maven:apache-maven-3.3.9版本 3.dubbo监控工具:dubbo-admin-2.5.4-SNAPS ...
- Dubbo + Zookeeper 简单配置
Dubbo + Zookeeper Zookeeper 下载及配置 下载到本机/usr/local目录 wget https://mirrors.tuna.tsinghua.edu.cn/apache ...
随机推荐
- Hashtable和Dictionary<T,K>的使用
由于Hashtable内部自带有排序(根据Key的HashCode来进行的),因此有时在使用Hashtable时就会造成数据顺序不可控的情况,有两种办法可以解决, 测试代码: Dictionary&l ...
- 【C语言】08-数组
为了让大家更好地学习和理解数组,我们先来认识一下内存中的"地址". 地址 1.计算机中的内存是以字节为单位的存储空间.内存的每一个字节都有一个唯一的编号,这个编号就称为地址.凡存放 ...
- css教程如何修改留言板程序
error_reporting(0);$conn = new com("adodb.connection"); $conn->open("driver={micro ...
- T-SQL查询进阶--深入浅出视图
视图可以看作定义在SQL Server上的虚拟表.视图正如其名字的含义一样,是另一种查看数据的入口.常规视图本身并不存储实际的数据,而仅仅存储一个Select语句和所涉及表的metadata. 视图简 ...
- Win7 桌面应用图标不见了
taskkill /im explorer.exe /f cd /d %userprofile%\appdata\local del iconcache.db /a start explorer.ex ...
- 课堂Scrum站立会议演示
组名:连连看 组长:张政 组员:张金生.李权.武志远 时间:2016.10.13 20:20--20:40 会议内容: 已完成的内容: 1.选定编译语言,安装软件并配置环境,完成了游戏的基本模型. ...
- 连连看的设计与实现——四人小组项目(GUI)
项目GUI界面经过简单设计,整理如下:(图片截取致宠物连连看3.1) 点开游戏后界面显示: 点击菜单游戏—>初级 后显示 -------------------------- > 当游戏时 ...
- Sql Server 2008:调试
调试T-SQL语句: 1.Debug普通T-SQL语句: SQL代码如下: use northwind go declare @i int ,@j int,@k int set @i = 1; set ...
- 2016.10.08,英语,《Verbal Advantage》Level1 Unit1-4
这本书学的很辛苦,总共10个Level,每个Level有5个Unit,每个Unit10个单词,实际上自己差不多一天才能学完1个Unit10个单词.(当然,一天我只能花大约1个小时左右在英语上) 而且跟 ...
- Apache Spark源码走读之11 -- sql的解析与执行
欢迎转载,转载请注明出处,徽沪一郎. 概要 在即将发布的spark 1.0中有一个新增的功能,即对sql的支持,也就是说可以用sql来对数据进行查询,这对于DBA来说无疑是一大福音,因为以前的知识继续 ...