Dubbo-RPC远程控制调用框架

背景

  • 大型互联网项目架构目标-

​ ●**高性能:提供快速的访问体验。
​ ●
高可用:**网站服务- 可以正常访问

  • 集群和分布式

集群和分布式,
●集群:很多“人”一起,干一样的事。一个业务模块,部署在多台服务器上。
●分布式:很多"人”一起,干不样的事。这些不一样的事, 合起来是一件大事。一个大的业务拆分为多个业务模块,部署在多台服务器上。

  • Dubbo概念

●Dubbo是阿里巴巴公司开源的一个高性能、轻量级的Java RPC框架。
●致力于提供高性能和透明化的RPC远程服务调用方案,以及SOA服务治理方案。
●官网: htp://ubbo.apache.orgo

** Dubbo作为一个RPC框架,其最核心的功能就是要实现跨网络的远程调用**

  • 节点角色说明: .
    ●Provider: 暴露服务的服务提供方
    ●Contahier: 服务运行容器
    ●Consumer: 调用远程服务的服务消费方
    ●Registry: 服务注册与发现的注册中心
    ●Monitor:统计服务的调用次数和调用时间的监控中心

  • zookeeper注册中心安装linux

Dubbo快速入门Demo

  • 服务皆为war包,有web.xml文件,在此文件中读配置文件信息,配置文件中配置相应框架信息和dubbo的信息
    注意:这是部署一个服务提供者时的配置,如需配置多个,请转至最后
    在这里插入图片描述
    ** customer和provider两者皆可独立提供服务,故皆打为jar包运行于tomcat服务器上
<packaging>war</packaging>

interface公共接口模块

抽离接口,使其被依赖
服务提供者需要实现该接口模块
服务调用者需要注入使用该模块

  • 让服务提供者Service和服务调用者Controller依赖于此公共模块
public interface UserService {
   
    String say();
}

服务提供者service模块

  • 提供服务,打包为war项目,需要tomcat插件
  • ApplicationContext.xml配置文件内容
<?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://dubbo.apache.org/schema/dubbo" xmlns:context="http://www.springframework.org/schema/context"
	   xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
        http://dubbo.apache.org/schema/dubbo http://dubbo.apache.org/schema/dubbo/dubbo.xsd http://www.springframework.org/schema/context https://www.springframework.org/schema/context/spring-context.xsd">

	Spring时的包扫描,已不需要
	<!--<context:component-scan base-package="com.itheima.service" />-->

	<!--dubbo的配置-->
	<!--1.配置项目的名称,唯一-->
	<dubbo:application name="dubbo-service"/>
	<!--2.配置注册中心的地址-->
	<dubbo:registry address="zookeeper://192.168.23.129:2181" timeout="250000"/>
	<!--3.配置dubbo包扫描-->
	<dubbo:annotation package="com.yh1.impl" />

	<!--<dubbo:service interface="com.yh.ours.UserService" ref="UserServiceImpl"/>-->

</beans>

import com.yh.ours.UserService;
import org.apache.dubbo.config.annotation.Service;

@Service//此注解已弃用-->可以使用xml文件中注册该服务
public class UserServiceImpl implements UserService {
   
    @Override
    public String say() {
   
        return "hello";
    }
}
  • web.xml文件
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xmlns="http://java.sun.com/xml/ns/javaee"
         xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
         version="2.5">


  <!-- 加载 spring配置文件以及添加监听 -->
  <context-param>
    <param-name>contextConfigLocation</param-name>
    <param-value>classpath*:spring/applicationContext*.xml</param-value>
  </context-param>
  <listener>
    <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
  </listener>


</web-app>

消费者web模块

  • srping-mvc.xml文件
<?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://dubbo.apache.org/schema/dubbo"
       xmlns:mvc="http://www.springframework.org/schema/mvc"
       xmlns:context="http://www.springframework.org/schema/context"
       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://dubbo.apache.org/schema/dubbo http://dubbo.apache.org/schema/dubbo/dubbo.xsd http://www.springframework.org/schema/context https://www.springframework.org/schema/context/spring-context.xsd">


Controller层的包还是要由mvc框架来扫描使用
    <mvc:annotation-driven/>
    <context:component-scan base-package="com.yh"/>


    <!--dubbo的配置-->
    <!--1.配置项目的名称,唯一-->
    <dubbo:application name="dubbo-web" >
        <
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值