dubbo结合zookeeper的使用

dubbo是分布式管理框架,主要用于管理分布式系统.zookeeper是分布式协调的治理工具。

dubbo是什么?

  • 一款分布式服务框架
  • 高性能和透明化的RPC远程服务调用方案
  • SOA服务治理方案

dubbo架构图

dubbo结合zookeeper的使用

Provider:服务提供方

Consumer:服务消费者

Registry:注册中心

Monitor:统计服务调用次数和调用时间的监控中心

调用流程:

0 . 启动服务

1. 服务提供者启动的时候, 向注册中心提供自己的服务

2.服务消费者启动的时候,向注册中心订阅自己的服务

3.注册中心将服务提供者地址列表返回给服务消费者,如果有变更,注册中心将基于长变更变更数据返回给消费者

4.服务消费者,基于软负载均衡算法,选一台提供者进行调用,如果调用失败,再选择另外一台服务提供者进行调用.

5.服务消费者和服务提供者, 在内容中累计调用次数和调用时间, 定时每分钟发送一次统计数据到监控台中心.

zookeeper注册中心

上述途中所或的Register就是注册中心,dubbo官方推荐的注册中心是zookeeper

服务提供方: 在注册中心发布服务

服务消费方: 在注册中心订阅服务

dubbo+zookeeper+SSM框架的配合使用

1.创建maven工程

dubbo结合zookeeper的使用

dubbo : dubbo父类工程, 主要是用来管理所有的jar版本

dubbo-api : dubbo工程所有的接口

dubbo-consumer : dubbo 消费者

dubbo-provider : dubbo提供者 , 所有公共接口的实现

dubbo-consumer-user : dubbo 消费用户

2. 创建服务方

2.1 服务方接口


  1. package com.provider;
  2. public interface DemoService {
  3. String sayHello(String name);
  4. }

2.2服务方接口实现类


  1. package com.provider;
  2. import org.springframework.stereotype.Service;
  3. @Service(value="demoService")
  4. public class DemoServiceImpl implements DemoService{
  5. public String sayHello(String name) {
  6. return "Hello Dubbo,Hello " + name;
  7. }
  8. }

2.3 applicationContext.xml


  1. xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  2. xmlns:aop="http://www.springframework.org/schema/aop"
  3. xmlns:tx="http://www.springframework.org/schema/tx"
  4. xmlns:jdbc="http://www.springframework.org/schema/jdbc"
  5. xmlns:context="http://www.springframework.org/schema/context"
  6. xsi:schemaLocation="
  7. http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.1.xsd
  8. http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.1.xsd
  9. http://www.springframework.org/schema/tx
  10. http://www.springframework.org/schema/tx/spring-tx-3.1.xsd
  11. http://www.springframework.org/schema/aop
  12. http://www.springframework.org/schema/aop/spring-aop-3.1.xsd"
  13. >

2.4 dubbo-provider.xml


  1. xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  2. xmlns:dubbo="http://code.alibabatech.com/schema/dubbo"
  3. xsi:schemaLocation="http://www.springframework.org/schema/beans
  4. http://www.springframework.org/schema/beans/spring-beans.xsd
  5. http://code.alibabatech.com/schema/dubbo
  6. http://code.alibabatech.com/schema/dubbo/dubbo.xsd">


分享到:


相關文章: