整个过程大致是这样的

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的简单使用的更多相关文章

  1. dubbo+zookeeper简单环境搭建

    dubbo+zoopeeper例子 [TOC] 标签(空格分隔): 分布式 dubbo dubbo相关 dubbo是目前国内比较流行的一种分布式服务治理方案.还有一种就是esb了.一般采用的是基于Ap ...

  2. dubbo的简单实现

    一 是什么 一般网站架构随着业务的发展,逻辑越来越复杂,数据量越来越大,交互越来越多,dubbo使前后端分离,完成负载均衡. dubbo架构图 节点角色说明: Provider: 暴露服务的服务提供方 ...

  3. dubbo的简单应用

    一. dubbo简介 dubbo是一个分布式服务框架,致力于提供高性能和透明化的RPC远程服务调用方案,是阿里巴巴SOA服务化治理方案的核心框架. 二. 架构 引用dubbo的架构图: Provide ...

  4. dubbo服务简单搭建

    一.初识dubbo: 架构图: Provider: 暴露服务的服务提供方. Consumer: 调用远程服务的服务消费方. Registry: 服务注册与发现的注册中心. Monitor: 统计服务的 ...

  5. MAC环境下idea:maven+Spring+Dubbo+Zookeeper简单工程搭建

    : 一:安装软件:tomcatZookeeperDubbo+admin 二:工程: 总工程  API    Pom.xml:不用引用任何东西  Provider    Pom.xml:要denpend ...

  6. springboot整合dubbo的简单案例

    使用框架: jdk 1.8 springboot-2.1.3 dubbo-2.6 spring-data-jpa-2.1.5 一.开发dubbo服务接口: 按照Dubbo官方开发建议,创建一个接口项目 ...

  7. springboot搭建dubbo+zookeeper简单案例

    背景:只是自己使用单机版zookeeper搭建dubbo的一个学习案例,记录成功的过程 1.搭建zookeeper坏境 使用docker来构建环境 1.1 拉取镜像:docker pull zooke ...

  8. Maven配置dubbo环境简单例子

    环境准备: 1.zookeeper:zookeeper-3.4.6版本 2.maven:apache-maven-3.3.9版本 3.dubbo监控工具:dubbo-admin-2.5.4-SNAPS ...

  9. Dubbo + Zookeeper 简单配置

    Dubbo + Zookeeper Zookeeper 下载及配置 下载到本机/usr/local目录 wget https://mirrors.tuna.tsinghua.edu.cn/apache ...

随机推荐

  1. swift -- 学习记录

    先把疯狂的swift这本书大致看了一遍 2016.7.13 因为实在是太闲,所以决定把公司的应用用swift写一遍 然后顺便看看swift的官方文档 这里有一个官文的中文翻译,感动啊 http://w ...

  2. Scala - Spark Lambda“goesto“ => 分析

    /// 定义一个函数AddNoise,参数分别为rdd,Fraction.其中rdd为(BreezeDenseMatrix, BreezeDenseMatrix)元组构成的RDD.Fraction为一 ...

  3. hdu How to Type

    感觉这道dp题还是有点技巧的,此题设置了两个数组:open[]和close[],分别用来记录capslock一直开启状态和一直关闭状态下的最少输入次数.此时只要判断字母的大小写,选用最优子结构即可.状 ...

  4. [MobilewebApp]图片的适配与清晰度

    iPhone4s的屏幕分辨率是640x960,这样就带来一个问题: 原来设计的320x480的设计出来的icon等图片,在高分辨率下就会显得模糊. 在经过讨论.查阅资料和测试后,可以有方法解决哦~ 1 ...

  5. [转]如何:定义和处理 SOAP 标头

    本文转自:http://msdn.microsoft.com/zh-cn/library/vstudio/8728chd5(v=vs.100).aspx 本主题专门介绍一项旧有技术.现在应通过使用以下 ...

  6. 揭开UTF-8的神秘面纱

    UTF-8(8-bit Unicode Transformation Format)是一种针对Unicode的可变长度字符编码,又称万国码.由Ken Thompson于1992年创建.现在已经标准化为 ...

  7. 分布式架构高可用架构篇_02_activemq高可用集群(zookeeper+leveldb)安装、配置、高可用测试

    参考: 龙果学院http://www.roncoo.com/share.html?hamc=hLPG8QsaaWVOl2Z76wpJHp3JBbZZF%2Bywm5vEfPp9LbLkAjAnB%2B ...

  8. EXT.NET入门必读

    Ext.Net是一个对ExtJS进行封装了的.net控件库,可以在ASP.NET WebForm和MVC中使用.从今天开始记录我的学习笔记,这是第一篇,今天学习了如何在WebForm中使用Ext.Ne ...

  9. ajax例子:审核验证用户名;登录界面

    审核验证用户名主页面: <body><div>用户名:<input type="text" id="uid" /><s ...

  10. error: jump to label ‘XXXX’ [-fpermissive]

    http://www.cnblogs.com/foohack/p/4090124.html 下面的类似的源码在MSVC上能正确编译通过.但是gcc/g++上就会错: 1. if(expr)2. got ...