Dubbo框架介绍

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/zjx86320/article/details/51018804

     Dubbo是一个常用的分布式服务框架,它致力于提供高性能和透明化的RPC远程调用服务方案,Dubbo有助于开发企业级的开发效率,以及可以通过简单的配置就可以做到负载均衡。


     一、Dubbo的基础知识


     1.Dubbo是什么

     2.Dubbo涉及的知识

     

     二、Dubbo框架设计介绍


     1.Dubbo的各个角色


     Dubbo在设计的时候,抽象出了四个角色的概念,它包括Consumer、Provider、Registry、Monitor。Consumer就是我们常说的消费者,Provider表示服务的提供者,Registry表示Dubbo服务的注册中心,实际上Dubbo并没有这样的一个注册应用,它只是抽象出了注册中心的这么一个概念,Monitor是监控类型的一个角色。


     首先,Provider将服务注册到注册中心上,然后Consumer获取到这些服务,来调用Provider。或者当Provider提供的服务有变化时,也会相应的通知Consumer。Provider和Consumer在调用时,都会发送相应的统计信息给Monitor.


     2.生产者配置和启动


     ①引入maven依赖


		<dependency>
			<groupId>com.alibaba</groupId>
			<artifactId>dubbo</artifactId>
			<version>2.5.3</version>			
		</dependency>

     ②编写配置文件


     Spring默认目录:classpath*:META-INFO/spring/*.xml

     这个文件下的所有xml都会加载到spring容器中,如果有Dubbo相关的配置,就会启动对应的NIO容器。


     ③xsd文件     


<?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.xsd
        http://code.alibabatech.com/schema/dubbo
        http://code.alibabatech.com/schema/dubbo/dubbo.xsd"> 
    
    <dubbo:application/> 
    <dubbo:provider/>	  
    <dubbo:registry/>
    <dubbo:protocol/>
    <dubbo:service  interface="com.gome.service.ReadService"  ref="readService"/>

</beans>

     ④Dubbo标签


                  


     3.消费之配置和启动


     ①引入maven依赖


                <dependency>
			<groupId>com.alibaba</groupId>
			<artifactId>dubbo</artifactId>
			<version>2.5.3</version>			
		</dependency>

     ②编写配置文件


     Spring默认目录:classpath*:META-INFO/spring/*.xml


     ③加载XML的方式


     1>自定义容器加载xml

ApplicationContext ctx = new ClassPathXmlApplicationContext("/spring/spring-config.xml");

     2>web类型配置

<context-param>
		<param-name>contextConfigLocation</param-name>
		<parem-value>classpath*:/spring/spring-config.xml</parem-value>
	</context-param>
	

     3>Junit启动方式

@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration({"classpath*:spring-*.xml"})
public class HttpRpcTest{}

     ④xsd文件


<?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:jee="http://www.springframework.org/schema/jee"
	xmlns:tx="http://www.springframework.org/schema/tx"
	xmlns:dubbo="http://code.alibabatech.com/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-3.1.xsd
	http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.1.xsd
	http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee-3.1.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-3.1.xsd"
	default-lazy-init="false" >
	
   <dubbo:application></dubbo:application>   
   <dubbo:registry></dubbo:registry> 
   <dubbo:consumer></dubbo:consumer>  
   <dubbo:reference></dubbo:reference>
    
</beans>


     ⑤Dubbo标签


                  

     在这里需要注意,Dubbo中引用的spring的版本是2.5的,要和项目中的保持一致。这里只是对Dubbo框架的相关配置做了简单的介绍,也是站在RPC框架的基础上,Dubbo是RPC的一种实现,理解了PRC的底层原理,能更好的帮助我们Dubbo框架的相关配置。   




猜你喜欢

转载自blog.csdn.net/zjx86320/article/details/51018804