dubbo搭建例子
现在很多公司用到dubbo,使用起来是很快就学会了。真的要熟悉它还是要花点功夫的。
前面尝试看了些它的源码,这里为了调试源码,先打搭一个能跑的项目,顺别分享出来,以便刚像学习的朋友节约时间,毕竟时间至关重要。

<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>
public interface BuyFoodService {
String doBuy();
}
作为提供方应该实现它:
public class BuyFoodServiceimpl implements BuyFoodService {
public String doBuy() {
System.out.println("mon whant me to buy food");
return "ok";
}
}
提供方的配置:
<?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://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"> <bean id="buyFoodService" class="com.test.dubbo.service.BuyFoodServiceimpl"></bean> <dubbo:registry protocol="zookeeper" address="127.0.0.1:2181" /> <dubbo:protocol accesslog="true" name="dubbo" port="20880" /> <dubbo:application name="son"/> <dubbo:service interface="com.test.dubbo.service.BuyFoodService" ref="buyFoodService"/> </beans>
以上提供方就可以启动将自己的信息注册到zk上了。在zk上可以看到一个叫dubbo的节点,节点里面有个buyFoodService。
<?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: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"> <dubbo:registry protocol="zookeeper" address="127.0.0.1:2181" /> <dubbo:protocol accesslog="true" name="dubbo" port="20880" /> <dubbo:application name="mon"/> <dubbo:reference id="buyFoodService" interface="com.test.dubbo.service.BuyFoodService"/> </beans>
public class Customer {
public static void main(String[] args) {
ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(
"classpath*:spring/provider/applicationContext.xml");
BuyFoodService buyFoodService = (BuyFoodService) context.getBean("buyFoodService");
System.out.println(buyFoodService.doBuy());
}
}
<dependency>
<groupId>com.101tec</groupId>
<artifactId>zkclient</artifactId>
<version>0.10</version>
</dependency>
dubbo搭建例子的更多相关文章
- 【转】Dubbo使用例子并且和Spring集成使用
一.编写客户端和服务器端共用接口类1.登录接口类public interface LoginService { public User login(String name, String psw ...
- IntelliJ IDEA下Maven SpringMVC+Mybatis入门搭建例子
很久之前写了一篇SSH搭建例子,由于工作原因已经转到SpringMVC+Mybatis,就以之前SSH实现简单登陆的例子,总结看看SpringMVC+Mybatis怎么实现. Spring一开始是轻量 ...
- 超详细,新手都能看懂 !使用SpringBoot+Dubbo 搭建一个简单的分布式服务
来自:JavaGuide Github 地址:https://github.com/Snailclimb/springboot-integration-examples 目录: 使用 SpringBo ...
- 使用 SpringBoot+Dubbo 搭建一个简单分布式服务
实战之前,先来看几个重要的概念 开始实战之前,我们先来简单的了解一下这样几个概念:Dubbo.RPC.分布式.由于本文的目的是带大家使用SpringBoot+Dubbo 搭建一个简单的分布式服务,所以 ...
- dubbo入门和springboot集成dubbo小例子
从零开始搭建springboot-dubbo的例子 Dubbo 是一个分布式服务框架,致力于提供高性能和透明化的 RPC 远程服务调用方案,以及 SOA 服务治理方案 一. Dubbo的简单介绍 1. ...
- 本地Windows环境Dubbo搭建测试
Dubbo介绍 Dubbo[]是一个分布式服务框架,致力于提供高性能和透明化的RPC远程服务调用方案,以及SOA服务治理方案. 其核心部分包含: 远程通讯: 提供对多种基于长连接的NIO框架抽象封装, ...
- dubbo 搭建以及使用笔记
公司使用dubbo做为rpc框架,有必要简单学习一番(自己搭建),自己做下学习记录. dubbo认识: dubbo是分布式SOA(面向服务)架构的rpc服务治理框架.可兼容各种rpc,强势的地方主要还 ...
- dubbo 搭建开发环境
本文是基于maven的,预先使用,先装maven. dubbo是一个分布式服务框架,提供一个SOA的解决方案.简单的说,dubbo就像在生产者和消费者中间架起了一座桥梁,使之能透明交互. 本文旨在搭建 ...
- Dubbo搭建HelloWorld-搭建服务提供者与服务消费者并完成远程调用(附代码下载)
场景 Dubbo简介与基本概念: https://blog.csdn.net/BADAO_LIUMANG_QIZHI/article/details/103555224 Dubbo环境搭建-ZooKe ...
随机推荐
- 借用mysql 或者其他数据库 处理MSSQL 2016前处理导入特殊字符
MSSQL 2016支持了utf8编码的文件,之前处理比较麻烦的bcp 方式导入特殊字符一下子就方便了. 但是之前的版本,处理起来还是有一点麻烦.这次处理使用的数据库版本是sql server 201 ...
- nginx四层负载均衡配置
nginx四层负载均衡配置代理Mysql集群 环境如下: ip 192.168.6.203 Nginx ip 192.168.6.*(多台) Mysql 步骤一 查看Nginx是否安装stream模块 ...
- Java基础学习之线程
1.尽量避免直接使用 同步.Thread等原生操作线程的类,可以通过java.util.concurrent下对底层包装好的类进行操作, ReentrantLock:lock trylock unl ...
- 整理一些提高C#编程性能的技巧
1.使用StringBuilder代替使用string 连接符 "+" 说明:String类对象是不可变的(只读),一旦创建该对象,就不能修改该对象的值. 对象String对象的重 ...
- Quirks模式是什么?它和Standards模式有什么区别
从IE6开始,引入了Standards模式,标准模式中,浏览器尝试给符合标准的文档在规范上的正确处理达到在指定浏览器中的程度. 在IE6之前CSS还不够成熟,所以IE5等之前的浏览器对CSS的支持很差 ...
- react-native 学习 ----- React Navigation
很久没有的登陆博客园了,密码都是找回的,从当年的大学生已经正常的走上了程序员的道路,看到之前发的博客还是写的android,现在自己已经在使用了react-native了. 大学毕业了,做了java后 ...
- 流畅的python学习笔记:第五章
在python中一切都可以视作为对象,包括函数.我们来看个例子: def function_try(): '''it is funciton try doc''' print 'fun ...
- ELK-初识Elasticsearch
第一篇:初识Elasticsearch 1.安装 Elasticsearch 要求 java8+的环境,推荐使用 Oracle 1.8.0_131版本的JDK.Java JDK的安装此处不做介绍.这里 ...
- 并归排序 (Java版本,时间复杂度为O(n))
自己上网查了一下并归排序的定义,把两个排序好的数组重新组成一个排序好的数组就是并归排序, 实现的方式有和多种,自己思考了一下,用java实现了一版本,思路如下,既然是排序好的,只需要依次比较两个数组, ...
- angularJS directive详解(自定义指令)
Angularjs指令定义的API AngularJs的指令定义大致如下 其中return返回的对象包含很多参数,下面一一说明 1.restrict (字符串)可选参数,指明指令在DOM里面以什么形式 ...