当前位置:首页 > 服务端 > duboo是什么

duboo是什么

2022年09月17日 09:33:11服务端4
<div id="article_content" class="article_content clearfix csdn-tracking-statistics" data-pid="blog" data-mod="popu_307" data-dsm="post" style="height: 1518px; overflow: hidden;">
                    <link rel="stylesheet" href="https://csdnimg.cn/release/phoenix/template/css/htmledit_views-0a60691e80.css">
            <div class="htmledit_views">
               
<h2><a name="t0"></a><span>1. Dubbo是什么?</span></h2>
<p><span>Dubbo是一个分布式服务框架,致力于提供高性能和透明化的RPC远程服务调用方案,以及SOA服务治理方案。简单的说,</span><span><span>dubbo就是个服务框架,如果没有分布式的需求,其实是不需要用的,只有在分布式的时候,才有dubbo这样的分布式服务框架的需求,并且本质上是个服务调用的东东,<span style="color:#ff0000;"><strong>说白了就是个远程服务调用的分布式框架(告别<span>Web Service模式中的WSdl,以服务者与消费者的方式在dubbo上注册</span>)</strong></span></span></span><br><span>其核心部分包含:</span><br><span>1. 远程通讯: 提供对多种基于长连接的NIO框架抽象封装,包括多种线程模型,序列化,以及“请求-响应”模式的信息交换方式。</span><br><span>2. 集群容错: 提供基于接口方法的透明远程过程调用,包括多协议支持,以及软负载均衡,失败容错,地址路由,动态配置等集群支持。</span><br><span>3. 自动发现: 基于注册中心目录服务,使服务消费方能动态的查找服务提供方,使地址透明,使服务提供方可以平滑增加或减少机器。</span></p>
<h2><a name="t1"></a><a name="t1" target="_blank"></a><span><span>2. Dubbo能做什么?</span></span></h2>
<p><span>1.透明化的远程方法调用,就像调用本地方法一样调用远程方法,只需简单配置,没有任何API侵入。 &nbsp; &nbsp; &nbsp;<br>
2.软负载均衡及容错机制,可在内网替代F5等硬件负载均衡器,降低成本,减少单点。<br>
3. 服务自动注册与发现,不再需要写死服务提供方地址,注册中心基于接口名查询服务提供者的IP地址,并且能够平滑添加或删除服务提供者。<br><br></span><span>Dubbo采用全Spring配置方式,透明化接入应用,对应用没有任何API侵入,只需用Spring加载Dubbo的配置即可,Dubbo基于Spring的Schema扩展进行加载。</span><span><br></span></p>
<p><span style="color:#ff0000;"><strong>之前使用Web Service,我想测试接口可以通过模拟消息的方式通过soapui或LR进行功能测试或性能测试。但现在使用Dubbo,接口之间不能直接交互,我尝试通过模拟消费者地址测试,结果不堪入目,再而使用jmeter通过junit进行测试,但还是需要往dubbo上去注册,如果再不给提供源代码的前提下,这个测试用例不好写啊....</strong></span></p>
<p>&nbsp;</p>
<h2><a name="t2"></a><a name="t2" target="_blank"></a>3. dubbo的架构</h2>
<div><span lang="en-us" xml:lang="en-us">dubbo</span><span>架构图如下所示:</span></div>
<div>&nbsp;</div>
<p><img src="https://img-blog.csdn.net/20131224140734734" alt=""></p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<h4><a name="t3" target="_blank"></a>节点角色说明:</h4>
<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Provider:&nbsp;暴露服务的服务提供方。</p>
<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Consumer:&nbsp;调用远程服务的服务消费方。</p>
<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Registry:&nbsp;服务注册与发现的注册中心。</p>
<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Monitor:&nbsp;统计服务的调用次调和调用时间的监控中心。</p>
<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Container:&nbsp;服务运行容器。</p>
<p><span style="color:#ff0000;"><strong>这点我觉得非常好,角色分明,可以根据每个节点角色的状态来确定该服务是否正常。</strong></span></p>
<h4><a name="t4" target="_blank"></a></h4>
<h4><a name="t5" target="_blank"></a>调用关系说明:</h4>
<p><span>0 服务容器负责启动,加载,运行服务提供者。</span></p>
<h4><a name="t6" target="_blank"></a><span>1. 服务提供者在启动时,向注册中心注册自己提供的服务。</span></h4>
<h4><a name="t7" target="_blank"></a><span>2. 服务消费者在启动时,向注册中心订阅自己所需的服务。</span></h4>
<h4><a name="t8" target="_blank"></a><span>3. 注册中心返回服务提供者地址列表给消费者,如果有变更,注册中心将基于长连接推送变更数据给消费者。</span></h4>
<h4><a name="t9" target="_blank"></a><span>4. 服务消费者,从提供者地址列表中,基于软负载均衡算法,选一台提供者进行调用,如果调用失败,再选另一台调用。</span></h4>
<h4><a name="t10" target="_blank"></a><span>5. 服务消费者和提供者,在内存中累计调用次数和调用时间,定时每分钟发送一次统计数据到监控中心。</span></h4>
<p><span style="color:#ff0000;"><strong>dubbo的容错性显而易见,性能方面还没有还得及测,我们系统某页面需要掉5次接口,本来想建议做个缓存,但业务关系不能采纳,还需要研究下dubbo的性能调优问题...</strong></span></p>
<h2><a name="t3"></a><a name="t11" target="_blank"></a>4. dubbo使用方法。</h2>
<p><span>Dubbo采用全Spring配置方式,透明化接入应用,对应用没有任何API侵入,只需用Spring加载Dubbo的配置即可,Dubbo基于Spring的Schema扩展进行加载。</span><span>如果不想使用Spring配置,而希望通过API的方式进行调用(不推荐)</span></p>
<p><span>下面我们就来看看spring配置方式的写法:</span></p>
<h4><a name="t12" target="_blank"></a>服务提供者:</h4>
<p><span>1.&nbsp;下载zookeeper注册中心,下载地址:<a href="http://www.apache.org/dyn/closer.cgi/zookeeper/" target="_blank"><span>http://www.apache.org/dyn/closer.cgi/zookeeper/</span></a>&nbsp;&nbsp;下载后解压即可,进入D:\apach-zookeeper-3.4.5\bin,</span></p>
<p><span>双击zkServer.cmd启动注册中心服务。</span></p>
<h4><a name="t13" target="_blank"></a><span>2.&nbsp;定义服务接口: (该接口需单独打包,在服务提供方和消费方共享)</span></h4>
<p>&nbsp;</p>
<p>&nbsp;<strong><span style="color:#ff0000;">下面这个例子不错,写的很详细可以做个model.</span></strong></p>
<div class="dp-highlighter bg_html">
<ol class="dp-xml" start="1"><li class="alt"><span><span>package&nbsp;com.unj.dubbotest.provider;&nbsp;&nbsp;</span></span></li><li><span>&nbsp;&nbsp;</span></li><li class="alt"><span>import&nbsp;java.util.List;&nbsp;&nbsp;</span></li><li><span>&nbsp;&nbsp;</span></li><li class="alt"><span>public&nbsp;interface&nbsp;DemoService&nbsp;{&nbsp;&nbsp;</span></li><li><span>&nbsp;&nbsp;</span></li><li class="alt"><span>&nbsp;&nbsp;&nbsp;&nbsp;String&nbsp;sayHello(String&nbsp;name);&nbsp;&nbsp;</span></li><li><span>&nbsp;&nbsp;</span></li><li class="alt"><span>&nbsp;&nbsp;&nbsp;&nbsp;public&nbsp;List&nbsp;getUsers();&nbsp;&nbsp;</span></li><li><span>&nbsp;&nbsp;</span></li><li class="alt"><span>}&nbsp;&nbsp;</span></li></ol></div>
<p><br><span>在服务提供方实现接口:(对服务消费方隐藏实现)</span></p>
<p><span style="line-height:1.5;">&nbsp;</span></p>
<div class="dp-highlighter bg_html">
<ol class="dp-xml" start="1"><li class="alt"><span><span>package&nbsp;com.unj.dubbotest.provider;&nbsp;&nbsp;</span></span></li><li><span>&nbsp;&nbsp;</span></li><li class="alt"><span>import&nbsp;java.util.ArrayList;&nbsp;&nbsp;</span></li><li><span>import&nbsp;java.util.LinkedList;&nbsp;&nbsp;</span></li><li class="alt"><span>import&nbsp;java.util.List;&nbsp;&nbsp;</span></li><li><span>&nbsp;&nbsp;</span></li><li class="alt"><span>&nbsp;&nbsp;</span></li><li><span>public&nbsp;class&nbsp;DemoServiceImpl&nbsp;implements&nbsp;DemoService{&nbsp;&nbsp;</span></li><li class="alt"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span></li><li><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;public&nbsp;String&nbsp;sayHello(String&nbsp;name)&nbsp;{&nbsp;&nbsp;</span></li><li class="alt"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return&nbsp;"Hello&nbsp;"&nbsp;+&nbsp;name;&nbsp;&nbsp;</span></li><li><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}&nbsp;&nbsp;</span></li><li class="alt"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;public&nbsp;List&nbsp;getUsers()&nbsp;{&nbsp;&nbsp;</span></li><li><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;List&nbsp;<span class="attribute">list</span><span>&nbsp;=&nbsp;</span><span class="attribute-value">new</span><span>&nbsp;ArrayList();&nbsp;&nbsp;</span></span></li><li class="alt"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;User&nbsp;<span class="attribute">u1</span><span>&nbsp;=&nbsp;</span><span class="attribute-value">new</span><span>&nbsp;User();&nbsp;&nbsp;</span></span></li><li><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;u1.setName("jack");&nbsp;&nbsp;</span></li><li class="alt"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;u1.setAge(20);&nbsp;&nbsp;</span></li><li><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;u1.setSex("男");&nbsp;&nbsp;</span></li><li class="alt"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span></li><li><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;User&nbsp;<span class="attribute">u2</span><span>&nbsp;=&nbsp;</span><span class="attribute-value">new</span><span>&nbsp;User();&nbsp;&nbsp;</span></span></li><li class="alt"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;u2.setName("tom");&nbsp;&nbsp;</span></li><li><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;u2.setAge(21);&nbsp;&nbsp;</span></li><li class="alt"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;u2.setSex("女");&nbsp;&nbsp;</span></li><li><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span></li><li class="alt"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;User&nbsp;<span class="attribute">u3</span><span>&nbsp;=&nbsp;</span><span class="attribute-value">new</span><span>&nbsp;User();&nbsp;&nbsp;</span></span></li><li><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;u3.setName("rose");&nbsp;&nbsp;</span></li><li class="alt"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;u3.setAge(19);&nbsp;&nbsp;</span></li><li><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;u3.setSex("女");&nbsp;&nbsp;</span></li><li class="alt"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span></li><li><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;list.add(u1);&nbsp;&nbsp;</span></li><li class="alt"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;list.add(u2);&nbsp;&nbsp;</span></li><li><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;list.add(u3);&nbsp;&nbsp;</span></li><li class="alt"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return&nbsp;list;&nbsp;&nbsp;</span></li><li><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}&nbsp;&nbsp;</span></li><li class="alt"><span>}&nbsp;&nbsp;</span></li></ol></div>
<p>&nbsp;</p>
<div class="panelMacro">用Spring配置声明暴露服务:</div>
<div class="dp-highlighter bg_html">
<ol class="dp-xml" start="1"><li class="alt"><span><span class="tag">&lt;?</span><span class="tag-name">xml</span><span>&nbsp;</span><span class="attribute">version</span><span>=</span><span class="attribute-value">"1.0"</span><span>&nbsp;</span><span class="attribute">encoding</span><span>=</span><span class="attribute-value">"UTF-8"</span><span class="tag">?&gt;</span><span>&nbsp;&nbsp;</span></span></li><li><span><span class="tag">&lt;</span><span class="tag-name">beans</span><span>&nbsp;</span><span class="attribute">xmlns</span><span>=</span><span class="attribute-value">"http://www.springframework.org/schema/beans"</span><span>&nbsp;&nbsp;</span></span></li><li class="alt"><span>&nbsp;&nbsp;&nbsp;&nbsp;<span class="attribute">xmlns:xsi</span><span>=</span><span class="attribute-value">"http://www.w3.org/2001/XMLSchema-instance"</span><span>&nbsp;&nbsp;</span></span></li><li><span>&nbsp;&nbsp;&nbsp;&nbsp;<span class="attribute">xmlns:dubbo</span><span>=</span><span class="attribute-value">"http://code.alibabatech.com/schema/dubbo"</span><span>&nbsp;&nbsp;</span></span></li><li class="alt"><span>&nbsp;&nbsp;&nbsp;&nbsp;<span class="attribute">xsi:schemaLocation</span><span>="http://www.springframework.org/schema/beans&nbsp;&nbsp;</span></span></li><li><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;http://www.springframework.org/schema/beans/spring-beans.xsd&nbsp;&nbsp;</span></li><li class="alt"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;http://code.alibabatech.com/schema/dubbo&nbsp;&nbsp;</span></li><li><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;http://code.alibabatech.com/schema/dubbo/dubbo.xsd&nbsp;&nbsp;</span></li><li class="alt"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;"<span class="tag">&gt;</span><span>&nbsp;&nbsp;</span></span></li><li><span>&nbsp;&nbsp;&nbsp;</span></li><li class="alt"><span>&nbsp;&nbsp;&nbsp;&nbsp;<span class="comments">&lt;!--&nbsp;具体的实现bean&nbsp;--&gt;</span><span>&nbsp;&nbsp;</span></span></li><li><span>&nbsp;&nbsp;&nbsp;&nbsp;<span class="tag">&lt;</span><span class="tag-name">bean</span><span>&nbsp;</span><span class="attribute">id</span><span>=</span><span class="attribute-value">"demoService"</span><span>&nbsp;</span><span class="attribute">class</span><span>=</span><span class="attribute-value">"com.unj.dubbotest.provider.DemoServiceImpl"</span><span>&nbsp;</span><span class="tag">/&gt;</span><span>&nbsp;&nbsp;</span></span></li><li class="alt"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span></li><li><span>&nbsp;&nbsp;&nbsp;&nbsp;<span class="comments">&lt;!--&nbsp;提供方应用信息,用于计算依赖关系&nbsp;--&gt;</span><span>&nbsp;&nbsp;</span></span></li><li class="alt"><span>&nbsp;&nbsp;&nbsp;&nbsp;<span class="tag">&lt;</span><span class="tag-name">dubbo:application</span><span>&nbsp;</span><span class="attribute">name</span><span>=</span><span class="attribute-value">"xixi_provider"</span><span>&nbsp;&nbsp;</span><span class="tag">/&gt;</span><span>&nbsp;&nbsp;</span></span></li><li><span>&nbsp;&nbsp;&nbsp;</span></li><li class="alt"><span>&nbsp;&nbsp;&nbsp;&nbsp;&lt;!--&nbsp;使用multicast广播注册中心暴露服务地址&nbsp;&nbsp;&nbsp;</span></li><li><span>&nbsp;&nbsp;&nbsp;&nbsp;<span class="tag">&lt;</span><span class="tag-name">dubbo:registry</span><span>&nbsp;</span><span class="attribute">address</span><span>=</span><span class="attribute-value">"multicast://224.5.6.7:1234"</span><span>&nbsp;</span><span class="tag">/&gt;</span><span>--</span><span class="tag">&gt;</span><span>&nbsp;&nbsp;</span></span></li><li class="alt"><span>&nbsp;&nbsp;&nbsp;&nbsp;</span></li><li><span>&nbsp;&nbsp;&nbsp;&nbsp;<span class="comments">&lt;!--&nbsp;使用zookeeper注册中心暴露服务地址&nbsp;--&gt;</span><span>&nbsp;&nbsp;</span></span></li><li class="alt"><span>&nbsp;&nbsp;&nbsp;&nbsp;<span class="tag">&lt;</span><span class="tag-name">dubbo:registry</span><span>&nbsp;</span><span class="attribute">address</span><span>=</span><span class="attribute-value">"zookeeper://127.0.0.1:2181"</span><span>&nbsp;</span><span class="tag">/&gt;</span><span>&nbsp;&nbsp;&nbsp;</span></span></li><li><span>&nbsp;&nbsp;&nbsp;&nbsp;</span></li><li class="alt"><span>&nbsp;&nbsp;&nbsp;&nbsp;<span class="comments">&lt;!--&nbsp;用dubbo协议在20880端口暴露服务&nbsp;--&gt;</span><span>&nbsp;&nbsp;</span></span></li><li><span>&nbsp;&nbsp;&nbsp;&nbsp;<span class="tag">&lt;</span><span class="tag-name">dubbo:protocol</span><span>&nbsp;</span><span class="attribute">name</span><span>=</span><span class="attribute-value">"dubbo"</span><span>&nbsp;</span><span class="attribute">port</span><span>=</span><span class="attribute-value">"20880"</span><span>&nbsp;</span><span class="tag">/&gt;</span><span>&nbsp;&nbsp;</span></span></li><li class="alt"><span>&nbsp;&nbsp;&nbsp;</span></li><li><span>&nbsp;&nbsp;&nbsp;&nbsp;<span class="comments">&lt;!--&nbsp;声明需要暴露的服务接口&nbsp;--&gt;</span><span>&nbsp;&nbsp;</span></span></li><li class="alt"><span>&nbsp;&nbsp;&nbsp;&nbsp;<span class="tag">&lt;</span><span class="tag-name">dubbo:service</span><span>&nbsp;</span><span class="attribute">interface</span><span>=</span><span class="attribute-value">"com.unj.dubbotest.provider.DemoService"</span><span>&nbsp;</span><span class="attribute">ref</span><span>=</span><span class="attribute-value">"demoService"</span><span>&nbsp;</span><span class="tag">/&gt;</span><span>&nbsp;&nbsp;</span></span></li><li><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span></li><li class="alt"><span><span class="tag">&lt;/</span><span class="tag-name">beans</span><span class="tag">&gt;</span><span>&nbsp;&nbsp;</span></span></li></ol></div>
<div class="panelMacro">加载Spring配置,启动服务:</div>
<div class="panelMacro">
<div class="dp-highlighter bg_html">
<ol class="dp-xml" start="1"><li class="alt"><span><span>package&nbsp;com.unj.dubbotest.provider;&nbsp;&nbsp;</span></span></li><li><span>&nbsp;&nbsp;</span></li><li class="alt"><span>import&nbsp;org.springframework.context.support.ClassPathXmlApplicationContext;&nbsp;&nbsp;</span></li><li><span>&nbsp;&nbsp;</span></li><li class="alt"><span>public&nbsp;class&nbsp;Provider&nbsp;{&nbsp;&nbsp;</span></li><li><span>&nbsp;&nbsp;&nbsp;</span></li><li class="alt"><span>&nbsp;&nbsp;&nbsp;&nbsp;public&nbsp;static&nbsp;void&nbsp;main(String[]&nbsp;args)&nbsp;throws&nbsp;Exception&nbsp;{&nbsp;&nbsp;</span></li><li><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;ClassPathXmlApplicationContext&nbsp;<span class="attribute">context</span><span>&nbsp;=&nbsp;</span><span class="attribute-value">new</span><span>&nbsp;ClassPathXmlApplicationContext(new&nbsp;String[]&nbsp;{"applicationContext.xml"});&nbsp;&nbsp;</span></span></li><li class="alt"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;context.start();&nbsp;&nbsp;</span></li><li><span>&nbsp;&nbsp;&nbsp;</span></li><li class="alt"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;System.in.read();&nbsp;//&nbsp;为保证服务一直开着,利用输入流的阻塞来模拟&nbsp;&nbsp;</span></li><li><span>&nbsp;&nbsp;&nbsp;&nbsp;}&nbsp;&nbsp;</span></li><li class="alt"><span>&nbsp;&nbsp;&nbsp;</span></li><li><span>}&nbsp;&nbsp;</span></li></ol></div>
<br><h4><a name="t14" target="_blank"></a>服务消费者:</h4>
<p><strong><span style="color:#ff0000;">&nbsp;applicationContext-dubbo.xml 中注册自己需要调用的接口,我刚开始测试的时候需要的接口很多,所以把这个文件写的满满的,后来熟悉了把接口按业务类型分开,写了N多个<strong><span>&nbsp;applicationContext-dubbo-***.xml 简练多了 》。&nbsp;</span></strong></span></strong></p>
<p>&nbsp;</p>
</div>
<div class="panelMacro"><span>1.通过Spring配置引用远程服务:</span>
<div class="panelMacro">
<div class="dp-highlighter bg_html">
<ol class="dp-xml" start="1"><li class="alt"><span><span class="tag">&lt;?</span><span class="tag-name">xml</span><span>&nbsp;</span><span class="attribute">version</span><span>=</span><span class="attribute-value">"1.0"</span><span>&nbsp;</span><span class="attribute">encoding</span><span>=</span><span class="attribute-value">"UTF-8"</span><span class="tag">?&gt;</span><span>&nbsp;&nbsp;</span></span></li><li><span><span class="tag">&lt;</span><span class="tag-name">beans</span><span>&nbsp;</span><span class="attribute">xmlns</span><span>=</span><span class="attribute-value">"http://www.springframework.org/schema/beans"</span><span>&nbsp;&nbsp;</span></span></li><li class="alt"><span>&nbsp;&nbsp;&nbsp;&nbsp;<span class="attribute">xmlns:xsi</span><span>=</span><span class="attribute-value">"http://www.w3.org/2001/XMLSchema-instance"</span><span>&nbsp;</span><span class="attribute">xmlns:dubbo</span><span>=</span><span class="attribute-value">"http://code.alibabatech.com/schema/dubbo"</span><span>&nbsp;&nbsp;</span></span></li><li><span>&nbsp;&nbsp;&nbsp;&nbsp;<span class="attribute">xsi:schemaLocation</span><span>="http://www.springframework.org/schema/beans&nbsp;&nbsp;</span></span></li><li class="alt"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;http://www.springframework.org/schema/beans/spring-beans.xsd&nbsp;&nbsp;</span></li><li><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;http://code.alibabatech.com/schema/dubbo&nbsp;&nbsp;</span></li><li class="alt"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;http://code.alibabatech.com/schema/dubbo/dubbo.xsd&nbsp;&nbsp;</span></li><li><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;"<span class="tag">&gt;</span><span>&nbsp;&nbsp;</span></span></li><li class="alt"><span>&nbsp;&nbsp;</span></li><li><span>&nbsp;&nbsp;&nbsp;&nbsp;<span class="comments">&lt;!--&nbsp;消费方应用名,用于计算依赖关系,不是匹配条件,不要与提供方一样&nbsp;--&gt;</span><span>&nbsp;&nbsp;</span></span></li><li class="alt"><span>&nbsp;&nbsp;&nbsp;&nbsp;<span class="tag">&lt;</span><span class="tag-name">dubbo:application</span><span>&nbsp;</span><span class="attribute">name</span><span>=</span><span class="attribute-value">"hehe_consumer"</span><span>&nbsp;</span><span class="tag">/&gt;</span><span>&nbsp;&nbsp;</span></span></li><li><span>&nbsp;&nbsp;</span></li><li class="alt"><span>&nbsp;&nbsp;&nbsp;&nbsp;<span class="comments">&lt;!--&nbsp;使用zookeeper注册中心暴露服务地址&nbsp;--&gt;</span><span>&nbsp;&nbsp;</span></span></li><li><span>&nbsp;&nbsp;&nbsp;&nbsp;<span class="comments">&lt;!--&nbsp;&lt;dubbo:registry&nbsp;address="multicast://224.5.6.7:1234"&nbsp;/&gt;&nbsp;--&gt;</span><span>&nbsp;&nbsp;</span></span></li><li class="alt"><span>&nbsp;&nbsp;&nbsp;&nbsp;<span class="tag">&lt;</span><span class="tag-name">dubbo:registry</span><span>&nbsp;</span><span class="attribute">address</span><span>=</span><span class="attribute-value">"zookeeper://127.0.0.1:2181"</span><span>&nbsp;</span><span class="tag">/&gt;</span><span>&nbsp;&nbsp;</span></span></li><li><span>&nbsp;&nbsp;</span></li><li class="alt"><span>&nbsp;&nbsp;&nbsp;&nbsp;<span class="comments">&lt;!--&nbsp;生成远程服务代理,可以像使用本地bean一样使用demoService&nbsp;--&gt;</span><span>&nbsp;&nbsp;</span></span></li><li><span>&nbsp;&nbsp;&nbsp;&nbsp;<span class="tag">&lt;</span><span class="tag-name">dubbo:reference</span><span>&nbsp;</span><span class="attribute">id</span><span>=</span><span class="attribute-value">"demoService"</span><span>&nbsp;&nbsp;</span></span></li><li class="alt"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="attribute">interface</span><span>=</span><span class="attribute-value">"com.unj.dubbotest.provider.DemoService"</span><span>&nbsp;</span><span class="tag">/&gt;</span><span>&nbsp;&nbsp;</span></span></li><li><span>&nbsp;&nbsp;</span></li><li class="alt"><span><span class="tag">&lt;/</span><span class="tag-name">beans</span><span class="tag">&gt;</span><span>&nbsp;&nbsp;</span></span></li></ol></div>
<br><div class="panelMacro"><span>2.加载Spring配置,并调用远程服务:</span></div>
<div class="panelMacro">
<div class="dp-highlighter bg_html">
<ol class="dp-xml" start="1"><li class="alt"><span><span>package&nbsp;com.alibaba.dubbo.demo.pp;&nbsp;&nbsp;</span></span></li><li><span>&nbsp;&nbsp;</span></li><li class="alt"><span>import&nbsp;java.util.List;&nbsp;&nbsp;</span></li><li><span>&nbsp;&nbsp;</span></li><li class="alt"><span>import&nbsp;org.springframework.context.support.ClassPathXmlApplicationContext;&nbsp;&nbsp;</span></li><li><span>&nbsp;&nbsp;</span></li><li class="alt"><span>import&nbsp;com.unj.dubbotest.provider.DemoService;&nbsp;&nbsp;</span></li><li><span>&nbsp;&nbsp;</span></li><li class="alt"><span>public&nbsp;class&nbsp;Consumer&nbsp;{&nbsp;&nbsp;</span></li><li><span>&nbsp;&nbsp;</span></li><li class="alt"><span>&nbsp;&nbsp;&nbsp;&nbsp;public&nbsp;static&nbsp;void&nbsp;main(String[]&nbsp;args)&nbsp;throws&nbsp;Exception&nbsp;{&nbsp;&nbsp;</span></li><li><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;ClassPathXmlApplicationContext&nbsp;<span class="attribute">context</span><span>&nbsp;=&nbsp;</span><span class="attribute-value">new</span><span>&nbsp;ClassPathXmlApplicationContext(&nbsp;&nbsp;</span></span></li><li class="alt"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;new&nbsp;String[]&nbsp;{&nbsp;"applicationContext.xml"&nbsp;});&nbsp;&nbsp;</span></li><li><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;context.start();&nbsp;&nbsp;</span></li><li class="alt"><span>&nbsp;&nbsp;</span></li><li><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;DemoService&nbsp;<span class="attribute">demoService</span><span>&nbsp;=&nbsp;(DemoService)&nbsp;context.getBean("demoService");&nbsp;//&nbsp;&nbsp;</span></span></li><li class="alt"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;String&nbsp;<span class="attribute">hello</span><span>&nbsp;=&nbsp;</span><span class="attribute-value">demoService</span><span>.sayHello("tom");&nbsp;//&nbsp;ִ&nbsp;&nbsp;</span></span></li><li><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;System.out.println(hello);&nbsp;//&nbsp;&nbsp;&nbsp;</span></li><li class="alt"><span>&nbsp;&nbsp;</span></li><li><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;//&nbsp;&nbsp;&nbsp;</span></li><li class="alt"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;List&nbsp;<span class="attribute">list</span><span>&nbsp;=&nbsp;</span><span class="attribute-value">demoService</span><span>.getUsers();&nbsp;&nbsp;</span></span></li><li><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if&nbsp;(list&nbsp;!=&nbsp;null&nbsp;&amp;&amp;&nbsp;list.size()&nbsp;<span class="tag">&gt;</span><span>&nbsp;0)&nbsp;{&nbsp;&nbsp;</span></span></li><li class="alt"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;for&nbsp;(int&nbsp;<span class="attribute">i</span><span>&nbsp;=&nbsp;</span><span class="attribute-value">0</span><span>;&nbsp;i&nbsp;</span><span class="tag">&lt;</span><span>&nbsp;</span><span class="tag-name">list.size</span><span>();&nbsp;i++)&nbsp;{&nbsp;&nbsp;</span></span></li><li><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;System.out.println(list.get(i));&nbsp;&nbsp;</span></li><li class="alt"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}&nbsp;&nbsp;</span></li><li><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}&nbsp;&nbsp;</span></li><li class="alt"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;//&nbsp;System.out.println(demoService.hehe());&nbsp;&nbsp;</span></li><li><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;System.in.read();&nbsp;&nbsp;</span></li><li class="alt"><span>&nbsp;&nbsp;&nbsp;&nbsp;}&nbsp;&nbsp;</span></li><li><span>&nbsp;&nbsp;</span></li><li class="alt"><span>}&nbsp;&nbsp;</span></li></ol></div>
</div>
</div>
</div>
<p><span>调用结果为:</span></p>
<p>&nbsp;</p>
<p><span><img src="https://img-blog.csdn.net/20131224152934546" alt=""><br></span></p>
<p><span><span>dubbo管理页面:</span></span></p>
<p><strong><span style="color:#ff0000;">这个管理页面还需要部署一个环境的,一开始我还以为是dubbo自带的,找了半天没有找到....</span></strong></p>
<p>&nbsp;</p>
<p><span><span><img src="https://img-blog.csdn.net/20131224152811531" alt=""><br></span></span></p>
<p><span>&nbsp;</span></p>
<p><span>&nbsp;</span></p>
<p><span>&nbsp;</span></p>
<p><span>&nbsp;</span></p>
<p><span>应用页面:</span></p>
<p><img src="https://img-blog.csdn.net/20131224152822062" alt=""></p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>提供者页面:</p>
<p><img src="https://img-blog.csdn.net/20131224153419968" alt=""></p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>消费者页面:</p>
<p><img src="https://img-blog.csdn.net/20131224152829015" alt=""></p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>服务页面:</p>
<p><img src="https://img-blog.csdn.net/20131224152846578" alt=""></p>
<p><span style="color:#ff0000;">测试是否成功,我觉得只要看看状态是否正常,就ok了 ....</span></p>
<p>&nbsp;</p>
<p><span><span>案例代码下载:<a href="http://download.csdn.net/detail/yiyu1/7116319" target="_blank">http://download.csdn.net/detail/yiyu1/7116319</a><br></span></span></p>
<div class="panelMacro">&nbsp;</div>
<div class="panelMacro">&nbsp;</div>
<p><span>&nbsp;</span></p>
<p><span>&nbsp;</span></p>
<p><span>&nbsp;</span></p>
<p><span>&nbsp;</span></p>
<div id="MySignature" style="display:block;">敏捷测试团队,不再仅仅是在coding之后。而是和研发人员贯穿在需求分析、规格说明、自动化单元测试、自动化验收测试、静态代码分析、技术债等环节中。所以敏捷项目必定在将来效率的趋势下成为主流。</div>
            </div>
                </div>

作者:qq_34193163
来源链接:https://blog.csdn.net/qq_34193163/article/details/80465856

版权声明:
1、JavaClub(https://www.javaclub.cn)以学习交流为目的,由作者投稿、网友推荐和小编整理收藏优秀的IT技术及相关内容,包括但不限于文字、图片、音频、视频、软件、程序等,其均来自互联网,本站不享有版权,版权归原作者所有。

2、本站提供的内容仅用于个人学习、研究或欣赏,以及其他非商业性或非盈利性用途,但同时应遵守著作权法及其他相关法律的规定,不得侵犯相关权利人及本网站的合法权利。
3、本网站内容原作者如不愿意在本网站刊登内容,请及时通知本站(javaclubcn@163.com),我们将第一时间核实后及时予以删除。


本文链接:https://www.javaclub.cn/server/42453.html

分享给朋友:

“duboo是什么” 的相关文章

解决方案仅用于执行startup.bat启动时乱码解决

解决方案仅用于执行startup.bat启动时乱码解决

目录 1.首先要知道的是,中文乱码一定是编码方式不一致导致的(废话...) 2.其次我们要找到T...

什么?IP协议是什么你竟然不了解,那还不快快点进来!

什么?IP协议是什么你竟然不了解,那还不快快点进来!

IP协议详解 1.一些基础知识 1.1虚电路是逻辑连接 1.2因特网采用的设计思路 1.3尽最大努力交付的好处...

python实现——处理Excel表格(超详细)

python实现——处理Excel表格(超详细)

目录 xls和xlsx 基本操作 1:用openpyxl模块打开Excel文档,查看所有sheet表 2.1:通过sheet名称获取表格...

pycharm安装教程,超详细

pycharm安装教程,超详细

在安装pycharm之前,确保你的电脑配置好了python,没有下载安装的可以去看我的文章—>>>python安装详细教程 pycharm windows版本下载地址:https://www.jetbrains.com/pycha...

Python:实用的IPython(一种交互式开发环境)

Python:实用的IPython(一种交互式开发环境)

用习惯了CentOS突然又用Windows,写Python想在控制端写怎么办?别急,一招教你在Windows终端写出一手舒服的代码! 欢迎光临,我的主页。更多干货,等你来学: 不许代码码上红 警句:莫道君行早,更有早行人。...

[C#]richtextbox实现拖放

namespace WindowsFormsApplication1 { public partial class Form1 : Form { public Form1() { InitializeCo...

[C#][控件]列表控件listbox(一)

1. 常用属性列表:    SelectionMode    组件中条目的选择类型,即多选(Multiple)、单选(Single)    Rows    ...

吐血整理《计算机网络五层协议之物理层(下)》

吐血整理《计算机网络五层协议之物理层(下)》

吐血整理《计算机网络五层协议之物理层(上)》 吐血整理《计算机网络五层协议之物理层(中)》 绝知此事要躬行! 物理层(下篇) 1.数字传输系统 1.1PCM的基本原理...

centos7中 yum的安装

centos7中 yum的安装

自己误将yum卸载, 在重装时由于依赖问题一直报错: error: Failed dependencies:     /usr/bin/python is ne...

CentOS7搭建本地YUM仓库,并定期同步阿里云源

CentOS7同步阿里云镜像rpm包并自建本地yum仓库 系统环境 # cat /etc/centos-release CentOS Linux release 7.6.1810 (Core) # uname -r 3.10.0-957.e...

发表评论

访客

◎欢迎参与讨论,请在这里发表您的看法和观点。