zoukankan      html  css  js  c++  java
  • Dubbo之消费者

    在写 dubbbo调用时候

       <dubbo:reference  不能有空格!

    项目结构:

     pom:

      

    <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
      <modelVersion>4.0.0</modelVersion>
      <parent>
        <groupId>com.toov5</groupId>
        <artifactId>toov5-parent</artifactId>
        <version>0.0.1-SNAPSHOT</version>
      </parent>
      <artifactId>toov5-order-dubbo-service</artifactId>
      
       <dependencies>
    	  <dependency>
    	    <groupId>com.toov5</groupId>
            <artifactId>toov5-member-api</artifactId>
            <version>0.0.1-SNAPSHOT</version>
    	  </dependency>
    	  
    	  <dependency>
    			<groupId>com.101tec</groupId>
    			<artifactId>zkclient</artifactId>
    			<version>0.10</version>
    		</dependency>
    		<dependency>
    			<groupId>commons-logging</groupId>
    			<artifactId>commons-logging</artifactId>
    			<version>1.2</version>
    		</dependency>
    		<dependency>
    			<groupId>org.jboss.netty</groupId>
    			<artifactId>netty</artifactId>
    			<version>3.2.5.Final</version>
    		</dependency>
    		<dependency>
    			<groupId>org.springframework</groupId>
    			<artifactId>spring-context</artifactId>
    			<version>4.3.9.RELEASE</version>
    		</dependency>
    		<dependency>
    			<groupId>com.alibaba</groupId>
    			<artifactId>dubbo</artifactId>
    			<version>2.5.3</version>
    			<exclusions>
    				<exclusion>
    					<groupId>org.springframework</groupId>
    					<artifactId>spring</artifactId>
    				</exclusion>
    				<exclusion>
    					<groupId>org.jboss.netty</groupId>
    					<artifactId>netty</artifactId>
    				</exclusion>
    			</exclusions>
    		</dependency>	  
      </dependencies>
      
      
    </project>
    

     业务:

    package com.toov5.dubbo.consumer;
    
    import org.springframework.context.support.ClassPathXmlApplicationContext;
    
    import com.toov5.api.member.service.MemberService;
    
    public class OderToMemberTest {
       public static void main(String[] args) {
        
          ClassPathXmlApplicationContext applicationContext = new ClassPathXmlApplicationContext("dubbo-consumer.xml");
          MemberService memberService =  applicationContext.getBean(MemberService.class);
          String resultUser = memberService.getUser(12L);
          System.out.println("调用服务后的返回结果"+resultUser);
    } 
    }

    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.xsd
           http://code.alibabatech.com/schema/dubbo
           http://code.alibabatech.com/schema/dubbo/dubbo.xsd">
    	<!--定义了提供方应用信息,用于计算依赖关系;在 dubbo-admin 或 dubbo-monitor 会显示这个名字,方便辨识 -->
    	<dubbo:application name="demotest-consumer" />
    	<!--使用 zookeeper 注册中心暴露服务,注意要先开启 zookeeper -->
    	<dubbo:registry address="zookeeper://192.168.91.5:2181" />
    	<!-- 用dubbo协议在20880端口暴露服务 -->
    	<dubbo:protocol name="dubbo" port="20880" />
    	<!--使用 dubbo 协议实现定义好的 MemberService 接口 -->
    	<dubbo:reference id="memberService" interface="com.toov5.api.member.service.MemberService"/>
    </beans>
    

      启动:

    只引入了接口 没有实现。 实现都是通过底层转换成rpc  dubbo协议进行调用的

     

  • 相关阅读:
    JUnit测试框架使用
    Android开发环境搭建与SD card
    深入Java泛型(Java泛型擦除机制,使用泛型强转时机,擦除对复写影响,协变返回类型)
    DHTML5(控件动态效果综合应用与表单校验)
    DHTML4(select与checkbox应用)
    DHTML3(表格动态创建,删除行/列,表格行排序,行颜色交替高亮显示)
    DHTML2(window对象,下拉列表)
    DHTML1(节点操作)
    JavaScript_语法,语句,函数,对象
    Html/CSS2_了解CSS
  • 原文地址:https://www.cnblogs.com/toov5/p/9925164.html
Copyright © 2011-2022 走看看