Doubbo教案

1》Dubbo
官网:http://dubbo.apache.org/
参考文档:http://dubbo.apache.org/books/dubbo-user-book/preface/background.html
1.1》什么是Dubbo
Dubbo是 阿里巴巴公司开源的一个高性能优秀的服务框架,使得应用可通过高性能的 RPC 实现服务的输出和输入功能,可以和 [2] Spring框架无缝集成。

1.2》什么是RPC
RPC(Remote Procedure Call)—远程过程调用,它是一种通过网络从远程计算机程序上请求服务,而不需要了解底层网络技术的协议。RPC协议假定某些传输协议的存在,如TCP或UDP,为通信程序之间携带信息数据。在OSI网络通信模型中,RPC跨越了传输层和应用层。RPC使得开发包括网络分布式多程序在内的应用程序更加容易。

1.3》微服务
微服务架构是一种架构模式,它提倡将单一应用程序划分成一组小的服务,服务之间互相协调、互相配合,为用户提供最终价值。

了解垂直结构和分部结构
https://blog.csdn.net/noaman_wgs/article/details/70214612/
1.4》dubbo主要核心部件:

Remoting: 网络通信框架,实现了 sync-over-async 和 request-response 消息机制

RPC: 一个远程过程调用的抽象,支持负载均衡、容灾和集群功能

Registry: 服务目录框架用于服务的注册和服务事件发布和订阅

1.5》dubbo的结构
在这里插入图片描述

1.6》查看dubbo的官方,首页快速入门案例
http://dubbo.apache.org/
在这里插入图片描述

1.7》dubbo使用注意

  1. 模型需要系列化
  2. 添加dubbo和zookeeper依赖
<!-- start..............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>

<dependency>
    <groupId>org.apache.zookeeper</groupId>
    <artifactId>zookeeper</artifactId>
    <version>3.4.6</version>
</dependency>
<dependency>
    <groupId>com.github.sgroschupf</groupId>
    <artifactId>zkclient</artifactId>
    <version>0.1</version>
</dependency>

<!-- end..............dubbo.................-->

2》Dubbo应用-Provider提供商
2.1》创建一个独立的service接口模块
在这里插入图片描述
2.2》创建service接口实现类模块

  1. 模块需要引用公共的dao模块
  2. 引用service接口模块
  3. 实现的service类加个名称
    在这里插入图片描述
    2.3》在resoures中添加spring的dao配置
    在这里插入图片描述
    2.4》在spring添加dubbo服务
    在这里插入图片描述
<?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-4.3.xsd
       http://code.alibabatech.com/schema/dubbo
       http://code.alibabatech.com/schema/dubbo/dubbo.xsd">
       <!-- 提供方应用信息,用于计算依赖关系 -->
    <dubbo:application name="edu-eb-service-provider"  />

    <!-- 使用zookeeper注册中心-->
    <dubbo:registry protocol="zookeeper" address="192.168.1.110:2181"/>

    <!-- 用dubbo协议在20880端口暴露服务 -->
    <dubbo:protocol name="dubbo" port="20880" />

    <!-- 声明需要暴露的服务接口 -->
    <dubbo:service interface="com.yuxiu.edu.eb.service.IUserService" ref="userService" />

</beans>

2.5》发布微服务
使用Main方法,加载spring配置文件,然后发布服务

public class App 
{
    public static void main( String[] args )
    {
        ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("classpath:spring-context.xml");
        context.start();

        synchronized (App.class) {
            while (true) {
                try {
                    App.class.wait();
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
        }
    }
}

3》Dubbo应用-Comsumer消费者
3.1》添加一个Web模块,并引用服务接口模块
在这里插入图片描述
3.2》然后配置好springmvc

3.3》在spring的配置文件中配置dubbo的消费者

<?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-4.3.xsd
       http://code.alibabatech.com/schema/dubbo
       http://code.alibabatech.com/schema/dubbo/dubbo.xsd">

    <!-- 消费方应用名,用于计算依赖关系,不是匹配条件,不要与提供方一样 -->
    <dubbo:application name="edu-eb-web" />

    <!-- 使用zookeeper注册中心暴露服务地址 -->
    <!-- 注册中心地址 -->
    <dubbo:registry protocol="zookeeper" address="192.168.1.110:2181" />

    <!-- 用户服务接口 -->
    <dubbo:reference interface="com.yuxiu.edu.eb.service.IUserService" id="userService" check="false" />
</beans>

3.4》配置个控制器调用service,
其实也就是远程调用
在这里插入图片描述

4》Dubbo后台管理安装

  1. 将dubbo-admin-2.5.3.war放在tomcat7中执行
    链接:https://pan.baidu.com/s/1PKq4nhPCTmjo-_bFy0mouA
    提取码:0ogi
  2. 记得Java_Home要改成1.7,高版本的jdk不兼容
  3. 然后访问http://localhost:8888/dubbo-admin-2.5.3,帐号和密码默认都为root
  4. 要修改帐号和密码可以修改dubbo.properties文件
    在这里插入图片描述
    在这里插入图片描述
    在这里插入图片描述

猜你喜欢

转载自blog.csdn.net/qq_23322973/article/details/88382093