Dubbox简介
Dubbox是一个分布式服务框架
Dubbox由当当网基于阿里的开源框架dubbo开发并维护
Dubbox常用来管理基于SOA的服务系统
Dubbox原理图
节点角色说明:
1.Provider: 暴露服务的服务提供方。
2.Consumer: 调用远程服务的服务消费方。
3.Registry: 服务注册与发现的注册中心。
4.Monitor: 统计服务的调用次调和调用时间的监控中心。
5.Container: 服务运行容器。
调用关系说明:
1.服务容器负责启动,加载,运行服务提供者。
2.服务提供者在启动时,向注册中心注册自己提供的服务。
3.服务消费者在启动时,向注册中心订阅自己所需的服务。
4.注册中心返回服务提供者地址列表给消费者,如果有变更,注册中心将基于长连接推送变更数据给消费者。
5.服务消费者,从提供者地址列表中,基于软负载均衡算法,选一台提供者进行调用,如果调用失败,再选另一台调用。
服务消费者和提供者,在内存中累计调用次数和调用时间,定时每分钟发送一次统计数据到监控中心
用Zookeeper做注册中心
使用
注册方
1.在web.xml中配置监听器listener
<!--配置Spring监听器-->
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<!--指定加载路径-->
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath*:spring/applicationContext*.xml</param-value>
</context-param>
2.在Spring配置文件中
<?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:p="http://www.springframework.org/schema/p"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:dubbo="http://code.alibabatech.com/schema/dubbo" xmlns:mvc="http://www.springframework.org/schema/mvc"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc.xsd
http://code.alibabatech.com/schema/dubbo http://code.alibabatech.com/schema/dubbo/dubbo.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd">
<!--发布的名称 不能重复-->
<dubbo:application name="pinyougou-sellergoods"/>
<!--注册中心地址-->
<dubbo:registry address="zookeeper://192.168.xx.xxx:2181"/>
<!--发布的协议和端口-->
<dubbo:protocol name="dubbo" port="20882"/>
<!--标签 每个类都要配置-->
<!--<dubbo:service interface="com.pinyougou.sellergoods.service.TbBrandService" ref="tbBrandService"/>-->
<!--<bean id="tbBrandService" class="com.pinyougou.sellergoods.service.impl.TbBrandServiceImpl"/>-->
<!--注解 @service import com.alibaba.dubbo.config.annotation.Service;-->
<dubbo:annotation package="com.pinyougou.sellergoods.service.impl"></dubbo:annotation>
<!-- 服务系统访问注册中心的超时时间 -->
<dubbo:provider timeout="50000"/>
</beans>
调用方
在SpringMVC配置文件中
<!-- 引用dubbo 服务 发布的名称-->
<dubbo:application name="pinyougou-manager-web" />
<!--访问的路径-->
<dubbo:registry address="zookeeper://192.168.xx.xxx:2181"/>
<!--开启注解的路径 @Reference注入-->
<dubbo:annotation package="com.pinyougou.manager.controller" />