dubbox 学习
目录
编译源码
dubbox是没有安装包的,所以我们只能先下载源码
直接从最新源码下载的话 可能会有各种问题,所以一定要选择一个发行版来下载 地址:https://github.com/dangdangdotcom/dubbox/releases
下载后就开始编译吧
mvn install maven.test.skip=true
发布dubbo的jar包到私库
dubbo的jar包在 dubbo/target/dubbo-2.x.x.jar (应该是2.8以上的版本)
然后将该jar包发布到私库(关于私库搭建相关参照 如何上传jar包到第三方仓库 )
mvn deploy:deploy-file \
-DgroupId=com.alibaba \
-DartifactId=dubbo \
-Dversion=.x.x \
-Dpackaging=jar \
-Dfile=dubbo/target/dubbo-.x.x.jar \
-Durl=http://192.168.0.170:8081/repository/3rd-part/ \
-DrepositoryId=nexus
然后将项目的maven源改为私库,这样就可以使用dubbox的jar包了
安装dubbo-admin
在dubbo-admin/target下会找到一个war包,这个是dubbox的管理网页,放到tomcat下,启动tomcat会自动解压并运行。
刚安装的tomcat需要设置用户信息才能访问
编辑文件 tomcat/conf/tomcat-users.xml (给tomcat用户添加角色manager-gui)
<role rolename="tomcat"/>
<role rolename="role1"/>
<user username="tomcat" password="tomcat" roles="tomcat,manager-gui"/>
<user username="both" password="tomcat" roles="tomcat,role1"/>
<user username="role1" password="tomcat" roles="role1"/>
</tomcat-users>
我们还需要修改解压后的配置文件:进入解压后的目录,编辑WEB-INF/dubbo.properties
dubbo.registry.address=zookeeper://192.168.0.216,192.168.0.217,192.168.0.218
dubbo.admin.root.password=root
dubbo.admin.guest.password=guest
主要是设置dubbo的注册zookeeper地址和访问网站的登录信息(root:root,guest:guest)
安装monitor
这里可以使用一个开源的修改版 git clone https://git.oschina.net/handu/dubbo-monitor.git
下载之后进入目录,有一个sql文件夹,根据sql内容创建数据库和表
然后编辑文件 src/main/resources/application.properties (设置数据库连接及zookeeper注册地址)
dubbo.application.name=dubbo-monitor
dubbo.application.owner=Ray
dubbo.registry.address=zookeeper://192.168.0.216,192.168.0.217,192.168.0.218
dubbo.protocol.port= # Database Settings
db.url=jdbc:mysql://192.168.0.250:3306/monitor?prepStmtCacheSize=517&cachePrepStmts=true&autoReconnect=true&characterEncoding=utf-8
db.username=root
db.password=
db.maxActive= # System Manager
manager.username=admin
manager.password=admin
Springboot + dubbox + spring-boot-starter-dubbo(provider和customer都是dubbox)
这种方式是最简单粗暴的,本身通过springboot就已经简化了很多配置和操作,再加上某伙计写的starter,更是6的飞起。
这里简单说说主要的代码,后面附上代码(代码来自参考中的文章,稍有改动)
1.api 这个是服务提供者的接口,消费者也需要依赖这个接口。这里就是普通的接口,没有特别的。
2.provider 提供者,需要实现api并指定注册地址及协议、端口等信息
ServiceImpl.java
@Service(version = "1.0.0")
public class BusinessServiceImpl implements BusinessService {
@Override
public BusinessDomain findBusiness(int id, String name) {
return null;
}
}
注意这里的注解 @Service,不是Spring的,而是 com.alibaba.dubbo.config.annotation.Service
通过这个注解可以设定服务的版本、重试次数、甚至是负载均衡策略等。此外,消费端要匹配这个Service中的version
application.yml
server:
port:
spring:
dubbo:
application:
name: business-provider
registry:
protocol: zookeeper
address: node1:,node2:,node3:
protocol:
name: dubbo
port:
host: server1.demo.cn
scan: cn.veryjava.business.provider
protocol.name是提供服务的协议,这里给的是dubbo,当然也可以用其他的如rest
protocol.host是指定部署服务的IP,当然也可以用hostname代替,如localhost;
registry.address是注册地址,即zookeeper集群的节点信息;
3.consumer 消费者
ConsumerController.java
@Controller
public class BusinessConsumerController { @Reference(version = "1.0.0")
public BusinessService businessService; @RequestMapping("/business")
@ResponseBody
public BusinessDomain getBusiness() {
return businessService.findBusiness(1, "businessaaa");
}
}
application.yml
server:
port:
spring:
dubbo:
application:
name: business-consumer
registry:
protocol: zookeeper
address: node1:,node2:,node3:
scan: cn.veryjava.business.consumer.controller
其他
1.Dubbo消费者启动报错 Failed to check the status of the service
出现这个错误的时候,在dubbo admin中查看消费者,显示没有提供者(但提供者运行正常且可访问)
我的原因是消费者没有指定服务版本,在消费者配置文件引用服务的时候加上服务版本即可(提供者的@Service注解)
<dubbo:reference id="testService" version="1.0.0" interface="com.product.service.ITestService" />
参考:
dubbox 学习的更多相关文章
- dubbo学习 三 dubbox概述
当当网根据自身的需求,对dubbo进行了扩展就叫成了dubbox.具体的使用方法可以参照官网各种例子:http://dangdangdotcom.github.io/dubbox/ 支持rest风 ...
- 分布式服务框架 dubbo/dubbox 入门示例
dubbo是一个分布式的服务架构,可直接用于生产环境作为SOA服务框架. 官网首页:http://dubbo.io/ ,官方用户指南 http://dubbo.io/User+Guide-zh.htm ...
- dubbox
github源码: https://github.com/dangdangdotcom/dubbox maven中央仓: 无 获取分支 git clone -b dubbox-2.8.4 https: ...
- dubbox开发rest+json指南【转】
http://dangdangdotcom.github.io/dubbox/rest.html 目录 概述 REST的优点 应用场景 快速入门 标准Java REST API:JAX-RS简介 RE ...
- 分布式服务框架 dubbo/dubbox 入门示例(转)
dubbo是一个分布式的服务架构,可直接用于生产环境作为SOA服务框架. 官网首页:http://dubbo.io/ ,官方用户指南 http://dubbo.io/User+Guide-zh.htm ...
- dubbo和dubboX与微服务架构(dubbo一)
一.传统三层架构模式的缺陷 三层架构(3-tier architecture) 通常意义上的三层架构就是将整个业务应用划分为:界面层(User Interface layer)web.业务逻辑层(Bu ...
- 一个入门rpc框架的学习
一个入门rpc框架的学习 参考 huangyong-rpc 轻量级分布式RPC框架 该程序是一个短连接的rpc实现 简介 RPC,即 Remote Procedure Call(远程过程调用),说得通 ...
- 服务化实战之 dubbo、dubbox、motan、thrift、grpc等RPC框架比较及选型
转自: http://blog.csdn.net/liubenlong007/article/details/54692241 概述 前段时间项目要做服务化,所以我比较了现在流行的几大RPC框架的优缺 ...
- javaWeb后端学习记录
java后端学习重点: 1.java语言特性: 基础知识,集合,多线程,并发,JVM,NIO,网络编程,设计模式. (★★★★★) jdk源码中有大量的数据结构与java语言细节.jdk源码着重看c ...
随机推荐
- Kotlin——中级篇(五):枚举类(Enum)、接口类(Interface)详解
在上一章节中,详细的类(class)做了一个实例讲解,提到了类(class)的实例化.构造函数.声明.实现方式.和Java中类的区别等.但是对于Kotlin中的类的使用还远远不止那些.并且在上文中提到 ...
- CSS如何清除浮动流的多种方案
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- TFS二次开发-基线文件管理器(2)-TFS登录
首先需要做一个TFS的登录. 以前的文章是使用的DomainProjectPicker 最新的VS里面使用的是TeamProjectPicker 首先可以在WinForm程序上写一个Button,然后 ...
- 通过less 计算 得出图片均分布局
<style lang="less"> @import "../style/weui.wxss"; // WXSS · 小程序 https://de ...
- 初学习-python打印乘法表、正方形、三角形
for x in range(1,4): for o in range(0,x-1): print('*',end='') pass pass print('*') print('\n')print( ...
- 二、Nuxt初始化项目
一.快速生成新项目 为了方便大家快速使用,Nuxt提供了一个starter模板,可以直接下载模板的压缩包,或者利用vue-cli来安装 1.压缩包链接:https://github.com/nuxt- ...
- python多进程编程(一)
multiprocessing模块介绍 python中的多线程无法利用多核优势,如果想要充分地使用多核CPU的资源(os.cpu_count()查看),在python中大部分情况需要使用多进程.Pyt ...
- [置顶] 我的Android进阶之旅------>Android解决异常: startRecording() called on an uninitialized AudioRecord.
今天使用AudioRecord进行录音操作时候,报了下面的异常. E/AndroidRuntime(22775): java.lang.IllegalStateException: startReco ...
- 在cli命令行上显示当前数据库,以及查询表的行头信息
在$HIVE_HOME/conf/hive-site.xml文件下加入以下配置文件 <property> <name>hive.cli.print.header</nam ...
- 剑指offer 面试11题
面试11题: 题目: 把一个数组最开始的若干个元素搬到数组的末尾,我们称之为数组的旋转. 输入一个非递减排序的数组的一个旋转,输出旋转数组的最小元素. 例如数组{3,4,5,1,2}为{1,2,3,4 ...